*ctf box题解

题目给了源码

/*
 * main.c
 * Copyright (C) 2019 hzshang <hzshang15@gmail.com>
 *
 * Distributed under terms of the MIT license.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const unsigned char* box1 = "\x17\x22\x2b\xcc\x0a\x02\x59\x1c\x10\x13\xe4\xaa\xfc\x3b\xfb\xbd\x3f\x76\x05\xc9\xc2\x25\x2d\xa6\x6e\x08\x75\xad\xf9\x5f\x5a\x46\x9c\xfd\xd1\x7f\x58\xbb\x0b\x4b\xdb\x31\x15\x7a\xd7\x90\x4f\x29\xe0\x69\x33\x36\x62\x54\x07\x38\x5d\x68\xda\xeb\x83\x24\x2e\xc6\x93\x5c\xc3\x9e\xd9\xd0\x74\x91\x06\xf3\xb4\x43\xc7\xb7\x0c\xa9\x63\x3a\xe6\xe8\xa0\x27\x6c\xab\x9b\xf6\x18\xba\x2c\x8b\x82\x1b\x00\xac\x52\x3e\x57\x35\x7b\x49\xb8\xf8\x97\x0d\xbc\x6b\xcb\xd6\xb1\x80\x30\x09\x21\x64\x99\x5b\x37\x40\xbe\xb0\x1e\xf4\x8f\xf5\x79\xa2\x95\x32\x66\x23\x6f\x7e\xe1\xbf\x96\xc4\x7c\xd3\x85\x67\xd8\xa7\x8e\xce\xef\x56\x92\xc8\xe5\xca\x4e\xee\x48\xa3\x44\x01\x42\x4a\x7d\x4d\x60\x1a\xa4\x71\xea\x53\x88\x8a\xa1\x98\xc1\x39\xe7\xe3\xcf\x89\x70\xdc\x11\xb5\x47\x87\x61\xec\x73\xc5\xed\x1d\xa8\x55\xe9\x9f\x03\xd2\x86\xf0\xd5\x28\x65\xf1\x94\x2a\x72\x45\xfa\x20\xdd\x78\x9d\xe2\xae\x19\xc0\xd4\xb2\xb3\xdf\x51\x3d\xb6\xf7\xfe\xde\x14\x84\x12\x6a\x50\x8c\xf2\x4c\xa5\x34\x16\x04\x8d\x26\x0f\x0e\x77\x41\x81\xcd\x1f\x3c\x9a\xff\x2f\x6d\xaf\x5e\xb9";
const unsigned char* box2 = "\x8c\xa1\x9d\xab\x31\xdc\x89\xb5\x6e\x4e\xbe\x54\x75\xdf\xc9\x6b\x70\xe8\x27\x6d\x04\x64\xcb\x67\x46\x1a\xff\x25\x2d\x32\x1d\xe1\x94\x0e\x45\xb3\x69\xb4\xc2\xf8\xc3\x59\x34\x5c\xdd\xa3\x9e\x93\x00\x30\xac\x81\x11\xc1\x57\xb2\x97\x76\xe7\x2e\x02\x55\x96\xcc\x05\x09\xb7\x4b\x56\x4c\xd3\x8a\xf3\x51\xc6\xce\x26\x0b\x7c\x9c\xfa\xfc\x7e\xd6\x8b\xae\x48\xe0\xaa\xa5\x4a\x03\x86\x1c\x44\xf5\xd0\x7f\x15\xd2\xd4\xde\x18\x9f\x68\xee\x37\xaf\x8d\x65\xd7\x95\x66\x61\x2c\x39\xbd\x10\x29\x91\xf9\x28\xbb\x4f\x77\x35\xa4\xfe\x6f\xa7\x5b\xa6\xa2\x43\x72\xed\x24\xfd\xe9\x1b\x2a\x47\x08\x2f\xd8\x2b\xf0\x23\x3b\xd1\x22\xec\xeb\x1e\x33\xa0\xf2\x36\xad\x0f\x7a\x8e\x7b\xa9\xe3\xb8\x14\x19\xb6\x79\x82\x9a\x0a\x53\xda\x0c\xef\x80\x3c\x5f\x3f\xe4\xf6\x17\xc8\x06\x74\x4d\x98\x58\xc4\xea\xba\x5a\x84\x49\x62\x5d\x73\x3d\x60\x07\x90\xdb\x3e\xa8\x6c\x41\xc0\x88\x87\x38\xbf\x78\x1f\xf4\x12\x50\x0d\x01\xe6\xcd\x3a\xd9\x63\xb9\xe2\xbc\x20\x6a\xf1\x9b\x7d\x8f\xb0\xcf\x85\xc7\x52\xc5\x99\x13\x42\x5e\xe5\x40\x21\xf7\x71\xd5\xca\xb1\x92\x16\x83\xfb";
const unsigned char* answer = "64960e4fef03c198961fafc1250e1f25960e4f250371db0ec100960aaf8016e5";
int check(char *key){
    int length = strlen(key);
    if(length != strlen(answer)/2)
        return 0;
    unsigned char *sbox = malloc(length+1);
    const unsigned char *boxs[] = {box1,box2};
    strcpy(sbox,key);
    for(int j=0;j<sizeof(boxs)/sizeof(char*);j++){
        for(int i=0;i<length;i++){
            sbox[i] = boxs[j][sbox[i]];
        }
    }
    char *hex = malloc(2*length+1);
    for(int i =0;i<length;i++){
        sprintf(&hex[2*i],"%02x",sbox[i]&0xff);
    }
    hex[2*length] = '\x00';
    printf("%s\n",hex);
    if(!strcmp(answer,hex))
        return 1;
    else
        return 0;
}
int main(int argc, char *argv[]){
    char buf[0x30];
    printf("input your flag:");
    scanf("%47s",buf);
    if(check(buf)){
        printf("Correct!\n");
    }else{
        printf("Try again!\n");
    }
    return 0;
}

分析了一下,就是用box1,box2将输入替换了两次,求flag就是拿answer反过来求flag

import binascii
box1="\x17\x22\x2b\xcc\x0a\x02\x59\x1c\x10\x13\xe4\xaa\xfc\x3b\xfb\xbd\x3f\x76\x05\xc9\xc2\x25\x2d\xa6\x6e\x08\x75\xad\xf9\x5f\x5a\x46\x9c\xfd\xd1\x7f\x58\xbb\x0b\x4b\xdb\x31\x15\x7a\xd7\x90\x4f\x29\xe0\x69\x33\x36\x62\x54\x07\x38\x5d\x68\xda\xeb\x83\x24\x2e\xc6\x93\x5c\xc3\x9e\xd9\xd0\x74\x91\x06\xf3\xb4\x43\xc7\xb7\x0c\xa9\x63\x3a\xe6\xe8\xa0\x27\x6c\xab\x9b\xf6\x18\xba\x2c\x8b\x82\x1b\x00\xac\x52\x3e\x57\x35\x7b\x49\xb8\xf8\x97\x0d\xbc\x6b\xcb\xd6\xb1\x80\x30\x09\x21\x64\x99\x5b\x37\x40\xbe\xb0\x1e\xf4\x8f\xf5\x79\xa2\x95\x32\x66\x23\x6f\x7e\xe1\xbf\x96\xc4\x7c\xd3\x85\x67\xd8\xa7\x8e\xce\xef\x56\x92\xc8\xe5\xca\x4e\xee\x48\xa3\x44\x01\x42\x4a\x7d\x4d\x60\x1a\xa4\x71\xea\x53\x88\x8a\xa1\x98\xc1\x39\xe7\xe3\xcf\x89\x70\xdc\x11\xb5\x47\x87\x61\xec\x73\xc5\xed\x1d\xa8\x55\xe9\x9f\x03\xd2\x86\xf0\xd5\x28\x65\xf1\x94\x2a\x72\x45\xfa\x20\xdd\x78\x9d\xe2\xae\x19\xc0\xd4\xb2\xb3\xdf\x51\x3d\xb6\xf7\xfe\xde\x14\x84\x12\x6a\x50\x8c\xf2\x4c\xa5\x34\x16\x04\x8d\x26\x0f\x0e\x77\x41\x81\xcd\x1f\x3c\x9a\xff\x2f\x6d\xaf\x5e\xb9"
box2="\x8c\xa1\x9d\xab\x31\xdc\x89\xb5\x6e\x4e\xbe\x54\x75\xdf\xc9\x6b\x70\xe8\x27\x6d\x04\x64\xcb\x67\x46\x1a\xff\x25\x2d\x32\x1d\xe1\x94\x0e\x45\xb3\x69\xb4\xc2\xf8\xc3\x59\x34\x5c\xdd\xa3\x9e\x93\x00\x30\xac\x81\x11\xc1\x57\xb2\x97\x76\xe7\x2e\x02\x55\x96\xcc\x05\x09\xb7\x4b\x56\x4c\xd3\x8a\xf3\x51\xc6\xce\x26\x0b\x7c\x9c\xfa\xfc\x7e\xd6\x8b\xae\x48\xe0\xaa\xa5\x4a\x03\x86\x1c\x44\xf5\xd0\x7f\x15\xd2\xd4\xde\x18\x9f\x68\xee\x37\xaf\x8d\x65\xd7\x95\x66\x61\x2c\x39\xbd\x10\x29\x91\xf9\x28\xbb\x4f\x77\x35\xa4\xfe\x6f\xa7\x5b\xa6\xa2\x43\x72\xed\x24\xfd\xe9\x1b\x2a\x47\x08\x2f\xd8\x2b\xf0\x23\x3b\xd1\x22\xec\xeb\x1e\x33\xa0\xf2\x36\xad\x0f\x7a\x8e\x7b\xa9\xe3\xb8\x14\x19\xb6\x79\x82\x9a\x0a\x53\xda\x0c\xef\x80\x3c\x5f\x3f\xe4\xf6\x17\xc8\x06\x74\x4d\x98\x58\xc4\xea\xba\x5a\x84\x49\x62\x5d\x73\x3d\x60\x07\x90\xdb\x3e\xa8\x6c\x41\xc0\x88\x87\x38\xbf\x78\x1f\xf4\x12\x50\x0d\x01\xe6\xcd\x3a\xd9\x63\xb9\xe2\xbc\x20\x6a\xf1\x9b\x7d\x8f\xb0\xcf\x85\xc7\x52\xc5\x99\x13\x42\x5e\xe5\x40\x21\xf7\x71\xd5\xca\xb1\x92\x16\x83\xfb"
asnwer="64960e4fef03c198961fafc1250e1f25960e4f250371db0ec100960aaf8016e5"
asnwer=binascii.a2b_hex(asnwer)
res=''
print type(box1)
for i in asnwer:
    res+=chr(box1.index(chr(box2.index(i))))
print res
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值