[GXYCTF2019]luck_guy
This question is a 64-bit elf file, it is not difficult to analyze, but I did not learn the switch function, which caused some time to
put in the 64-bit ida analysis pseudo-code is simple and clear, enter the lucky number and store it in v4 to execute the patch_me function.
If you enter If the lucky number is even, enter the get_flag function. The
pseudo code is as follows:
unsigned __int64 get_flag()
{
unsigned int v0; // eax
char v1; // al
signed int i; // [rsp+4h] [rbp-3Ch]
signed int j; // [rsp+8h] [rbp-38h]
__int64 s; // [rsp+10h] [rbp-30h]
char v6; // [rsp+18h] [rbp-28h]
unsigned __int64 v7; // [rsp+38h] [rbp-8h]
v7 = __readfsqword(0x28u);
v0 = time(0LL);
srand(v0);
for ( i = 0; i <= 4; ++i )
{
switch ( rand() % 200 )
{
case 1:
puts("OK, it's flag:");
memset(&s, 0, 0x28uLL);
strcat((char *)&s, f1);
strcat((char *)&s, &f2);
printf("%s", &s);
break;
case 2:
printf("Solar not like you");
break;
case 3:
printf("Solar want a girlfriend");
break;
case 4:
v6 = 0;
s = 9180147350284624745LL; //转换成16进制为0x69,0x63,0x75,0x67,0x60,0x6f,0x66,0x7f
strcat(&f2, (const char *)&s);
break;
case 5:
for ( j = 0; j <= 7; ++j )
{
if ( j % 2 == 1 )
v1 = *(&f2 + j) - 2;
else
v1 = *(&f2 + j) - 1;
*(&f2 + j) = v1;
}
break;
default:
puts("emmm,you can't find flag 23333");
break;
}
}
return __readfsqword(0x28u) ^ v7;
}
After consulting, I know that the switch function needs to be sorted. The approximate order after analysis is case4, case5, case1.
The value in f1 is: GXY{do_not_
Write a python3 script to run out of the flag: GXY{do_not_hate_me}
flag='GXY{do_not_'
f2=[0x69,0x63,0x75,0x67,0x60,0x6f,0x66,0x7f,0]
v1=[]
for i in range(8):
if i%2==1:
v1.append(f2[i]+i-2)
else:
v1.append(f2[i]+i-1)
f2[i]=v1[i]-i
flag+=chr(f2[i])
print(flag)