第二十二题[WUSTCTF2020]level1
查壳
64位ELF文件,用64位IDA打开。
在函数界面可以看到一个“flag”,跟进该函数。
int __cdecl main(int argc, const char **argv, const char **envp)
{int i; // [rsp+4h] [rbp-2Ch]FILE *stream; // [rsp+8h] [rbp-28h]char ptr[24]; // [rsp+10h] [rbp-20h] BYREFunsigned __int64 v7; // [rsp+28h] [rbp-8h]v7 = __readfsqword(0x28u);stream = fopen("flag", "r");fread(ptr, 1uLL, 0x14uLL, stream);fclose(stream);for ( i = 1; i <= 19; ++i ){if ( (i & 1) != 0 )printf("%ld\n", (unsigned int)(ptr[i] << i));elseprintf("%ld\n", (unsigned int)(i * ptr[i]));}return 0;
}
打开了一个叫“flag”的文件,将值存入ptr,循环19次,如果i和1与运算结果不为0,输出ptr[i]左移i位的值,否则输出ptr[i]与i的乘积,我们发现这个题有两个文件,另一个txt文件应该就是输出的值,只需要将其中的值进行逆运算就可以得到flag。
写一个脚本
ptr = [198, 232, 816, 200, 1536, 300, 6144, 984, 51200, 570, 92160,1200, 565248, 756, 1474560, 800, 6291456, 1782, 65536000]for i in range(19):if (i+1) & 1:print(chr(ptr[i] >> (i+1)), end="")else:print(chr(ptr[i] // (i+1)), end="")
解得flag为flag{d9-dE6-20c}
第二十三题[GUET-CTF2019]re1
查壳
64位,upx壳,先脱壳,再用64位IDA打开,检索字符串,找到一个'Correct!'字符串,跟进,反汇编查看伪代码。
__int64 __fastcall sub_400E28(__int64 a1, int a2, int a3, int a4, int a5, int a6)
{int v6; // edxint v7; // ecxint v8; // r8dint v9; // r9d__int64 result; // rax__int64 v11[5]; // [rsp+0h] [rbp-30h] BYREFunsigned __int64 v12; // [rsp+28h] [rbp-8h]v12 = __readfsqword(0x28u);memset(&v11[1], 0, 24);sub_40F950((unsigned int)"input your flag:", a2, a3, a4, a5, a6);scanf((unsigned int)"%s", (unsigned int)v11, v6, v7, v8, v9, 0);if ( (unsigned int)sub_4009AE(v11) )printf("Correct!");elseprintf("Wrong!");result = 0LL;if ( __readfsqword(0x28u) != v12 )sub_443550();return result;
}
初始化v11,输入flag,如果 (unsigned int)sub_4009AE(v11),输出‘Correct!’,关键在于函数 (unsigned int)sub_4009AE(v11),跟进。
_BOOL8 __fastcall sub_4009AE(char *a1)
{if ( 1629056 * *a1 != 166163712 )return 0LL;if ( 6771600 * a1[1] != 731332800 )return 0LL;if ( 3682944 * a1[2] != 357245568 )return 0LL;if ( 10431000 * a1[3] != 1074393000 )return 0LL;if ( 3977328 * a1[4] != 489211344 )return 0LL;if ( 5138336 * a1[5] != 518971936 )return 0LL;if ( 7532250 * a1[7] != 406741500 )return 0LL;if ( 5551632 * a1[8] != 294236496 )return 0LL;if ( 3409728 * a1[9] != 177305856 )return 0LL;if ( 13013670 * a1[10] != 650683500 )return 0LL;if ( 6088797 * a1[11] != 298351053 )return 0LL;if ( 7884663 * a1[12] != 386348487 )return 0LL;if ( 8944053 * a1[13] != 438258597 )return 0LL;if ( 5198490 * a1[14] != 249527520 )return 0LL;if ( 4544518 * a1[15] != 445362764 )return 0LL;if ( 3645600 * a1[17] != 174988800 )return 0LL;if ( 10115280 * a1[16] != 981182160 )return 0LL;if ( 9667504 * a1[18] != 493042704 )return 0LL;if ( 5364450 * a1[19] != 257493600 )return 0LL;if ( 13464540 * a1[20] != 767478780 )return 0LL;if ( 5488432 * a1[21] != 312840624 )return 0LL;if ( 14479500 * a1[22] != 1404511500 )return 0LL;if ( 6451830 * a1[23] != 316139670 )return 0LL;if ( 6252576 * a1[24] != 619005024 )return 0LL;if ( 7763364 * a1[25] != 372641472 )return 0LL;if ( 7327320 * a1[26] != 373693320 )return 0LL;if ( 8741520 * a1[27] != 498266640 )return 0LL;if ( 8871876 * a1[28] != 452465676 )return 0LL;if ( 4086720 * a1[29] != 208422720 )return 0LL;if ( 9374400 * a1[30] == 515592000 )return 5759124 * a1[31] == 719890500;return 0LL;
}
发现代码很长,是多个if嵌套,可以确定a的值就是flag,只需要将含有a的算式逆运算即可。
a1 = [0]*32
a1[0] = chr(166163712//1629056)
a1[1] = chr(731332800 // 6771600)
a1[2] = chr(357245568 // 3682944)
a1[3] = chr(1074393000 // 10431000)
a1[4] = chr(489211344 // 3977328)
a1[5] = chr(518971936 // 5138336)
a1[7] = chr(406741500 // 7532250)
a1[8] = chr(294236496 // 5551632)
a1[9] = chr(177305856 // 3409728)
a1[10] = chr(650683500 // 13013670)
a1[11] = chr(298351053 // 6088797)
a1[12] = chr(386348487 // 7884663)
a1[13] = chr(438258597 // 8944053)
a1[14] = chr(249527520 // 5198490)
a1[15] = chr(445362764 // 4544518)
a1[16] = chr(981182160 // 10115280)
a1[17] = chr(174988800 // 3645600)
a1[18] = chr(493042704 // 9667504)
a1[19] = chr(257493600 // 5364450)
a1[20] = chr(767478780 // 13464540)
a1[21] = chr(312840624 // 5488432)
a1[22] = chr(1404511500 // 14479500)
a1[23] = chr(316139670 // 6451830)
a1[24] = chr(619005024 // 6252576)
a1[25] = chr(372641472 // 7763364)
a1[26] = chr(373693320 // 7327320)
a1[27] = chr(498266640 // 8741520)
a1[28] = chr(452465676 // 8871876)
a1[29] = chr(208422720 // 4086720)
a1[30] = chr(515592000 // 9374400)
a1[31] = chr(719890500 // 5759124)
for i in range(32):if(i == 6):continue
print(a1[i], end='')
解出flag{e65421110ba03099a1c039337}flag{e65421110ba03099a1c039337}
但是原函数并没有判断a6,所以没有与a6相关的算式,我们解出的flag实际上缺了第七位
使用穷举法枚举a6可能的值,能猜出a6的值为1,正确的flag为flag{e165421110ba03099a1c039337}flag{e65421110ba03099a1c039337}