int __cdecl check_password(char *a1)
{
void *v1; // esp
int v2; // eax
int v3; // eax
int v4; // eax
int v5; // eax
int v6; // eax
int v7; // eax
int v8; // eax
int v9; // eax
int v10; // eax
int v12; // [esp+0h] [ebp-48h] BYREF
char *s; // [esp+Ch] [ebp-3Ch]
int v14; // [esp+10h] [ebp-38h]
int v15; // [esp+14h] [ebp-34h]
int i; // [esp+18h] [ebp-30h]
int v17; // [esp+1Ch] [ebp-2Ch]
size_t n; // [esp+20h] [ebp-28h]
size_t v19; // [esp+24h] [ebp-24h]
char *s1; // [esp+28h] [ebp-20h]
int v21; // [esp+2Ch] [ebp-1Ch]
int v22; // [esp+30h] [ebp-18h]
int v23; // [esp+34h] [ebp-14h]
unsigned int v24; // [esp+38h] [ebp-10h]
unsigned int v25; // [esp+3Ch] [ebp-Ch]
s = a1;
v25 = __readgsdword(0x14u);
v17 = strlen(a1);
n = 4 * ((v17 + 2) / 3);
v19 = n;
v1 = alloca(16 * ((n + 16) / 0x10));
s1 = (char *)&v12;
v14 = 0;
v15 = 0;
while ( v14 < v17 )
{
v2 = v14++;
v21 = (unsigned __int8)s[v2];
if ( v14 >= v17 )
{
v4 = 0;
}
else
{
v3 = v14++;
v4 = (unsigned __int8)s[v3];
}
v22 = v4;
if ( v14 >= v17 )
{
v6 = 0;
}
else
{
v5 = v14++;
v6 = (unsigned __int8)s[v5];
}
v23 = v6;
v24 = (v22 << 8) + (v21 << 16) + v6;
v7 = v15++;
s1[v7] = alphabet[(v24 >> 18) & 0x3F];
v8 = v15++;
s1[v8] = alphabet[(v24 >> 12) & 0x3F];
v9 = v15++;
s1[v9] = alphabet[(v24 >> 6) & 0x3F];
v10 = v15++;
s1[v10] = alphabet[v24 & 0x3F];
}
for ( i = 0; mod[v17 % 3] > i; ++i )
s1[n - 1 - i] = 61;
return strncmp(s1, "SGFja0NURnt3M2xjMG0zXzcwX3IzdjNyNTFuNl93MHJsZEBfQCFfIX0=", n);
}
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
setvbuf(_bss_start, 0, 2, 0);
if ( argc > 1 )
{
if ( (unsigned __int8)check_password(argv[1]) )
{
puts("Incorrect Password!");
result = -1;
}
else
{
puts("Congrats, now where's my flag?");
result = 0;
}
}
else
{
puts("Please provide a password!");
result = -1;
}
return result;
}
IDA Pro로 디컴파일하면 위 코드와 같습니다. 마지막에 s와 SGFja0NURnt3M2xjMG0zXzcwX3IzdjNyNTFuNl93MHJsZEBfQCFfIX0= 문자열이 같으면 조건을 충족하게 되는데 base64로 디코딩하면 플래그를 획득할 수 있습니다.
'Reversing > CTF' 카테고리의 다른 글
[HackCTF] Keygen (0) | 2021.10.09 |
---|---|
[HackCTF] Strncmp (0) | 2021.09.12 |
[HackCTF] Handray (0) | 2021.09.11 |
[HackCTF] Reversing Me (0) | 2021.09.10 |
[DIMI CTF] gorev (0) | 2021.08.06 |
댓글