int __cdecl main(int a1, char **a2)
{
if ( a1 > 1 && sub_8048414(a2[1], 0) )
{
puts("Access granted");
sub_8048538((int)a2[1]);
}
else
{
puts("Access denied");
}
return 0;
}
要使得程序输出“Access granted”,需要sub_8048414函数返回True。
int __cdecl sub_8048414(_BYTE *a1, int a2)
{
int result; // eax
switch ( a2 )
{
case 0:
if ( *a1 == 105 )
goto LABEL_19;
result = 0;
break;
case 1:
if ( *a1 == 101 )
goto LABEL_19;
result = 0;
break;
case 3:
if ( *a1 == 110 )
goto LABEL_19;
result = 0;
break;
case 4:
if ( *a1 == 100 )
goto LABEL_19;
result = 0;
break;
case 5:
if ( *a1 == 97 )
goto LABEL_19;
result = 0;
break;
case 6:
if ( *a1 == 103 )
goto LABEL_19;
result = 0;
break;
case 7:
if ( *a1 == 115 )
goto LABEL_19;
result = 0;
break;
case 9:
if ( *a1 == 114 )
LABEL_19:
result = sub_8048414(a1 + 1, 7 * (a2 + 1) % 11);
else
result = 0;
break;
default:
result = 1;
break;
}
return result;
}
要使得该函数返回非0值,那么 result=0这行不能被执行,根据出入的参数中a2=0,所以可以求出a1也就是输入:
def getInput():
tab=[105,101,0,110,100,97,103,115,0,114,0]
a2 = 0
res = []
while True:
if tab[a2] == 0:
break
res.append(tab[a2])
a2 = 7*(a2+1)%11
print(res)
return res
int __cdecl sub_8048538(int a1)
{
int v2[33]; // [esp+18h] [ebp-A0h] BYREF
int i; // [esp+9Ch] [ebp-1Ch]
qmemcpy(v2, &unk_8048760, sizeof(v2));
for ( i = 0; i <= 32; ++i )
putchar(v2[i] ^ *(char *)(a1 + i % 8));
return putchar(10);
上面的代码时负责输出flag的。
综上,破解程序:
def getInput():
tab=[105,101,0,110,100,97,103,115,0,114,0]
a2 = 0
res = []
while True:
if tab[a2] == 0:
break
res.append(tab[a2])
a2 = 7*(a2+1)%11
print(res)
return res
def getFlag(a2):
unk =[15, 31, 4, 9, 28, 18,
66, 9, 12, 68, 13, 7, 9, 6,
45, 55, 89, 30, 0, 89, 15, 8,
28, 35, 54, 7, 85, 2, 12, 8, 65, 10, 20]
flag = ''
for i in range(33):
flag+=chr(unk[i]^a2[i%8])
print(flag)
return flag
input = getInput()
getFlag(input)