题目复现
题目:[拼接]
- 题目来源:polarctf-reverse-[拼接]
- 解题:
根据文件名zip
联想到压缩包,改后缀解压
exeinfo工具查看文件基本信息,windows 32bit,未加壳文件
使用ida 32bit打开,ctrl+f
找到main函数,f5查看源码,调用了main_0函数
打开main_0函数
代码审计
c++
int __cdecl main_0(int argc, const char **argv, const char **envp)
{
char v4; // [esp+0h] [ebp-160h]
char v5; // [esp+0h] [ebp-160h]
char Str1[60]; // [esp+D0h] [ebp-90h] BYREF
char Destination[60]; // [esp+10Ch] [ebp-54h] BYREF
char *v8; // [esp+148h] [ebp-18h]
char *Source; // [esp+154h] [ebp-Ch]
__CheckForDebuggerJustMyCode(&unk_41B009);
Source = "flag{";
v8 = "03ff6cf238c5cd8e7b4ee1e9567ad5a4}";
j_memset(Destination, 0, 0x32u);
j_memset(Str1, 0, 0x32u);
j_strcpy(Destination, "flag{");
j_strcat(Destination, v8);
sub_411050("please input flag\r\n", v4);
sub_4110AA("%s", (char)Str1);
if ( !j_strcmp(Str1, Destination) )
sub_411050("congratulation\r\n", v5);
else
sub_411050("error\r\n", v5);
return 0;
}
定义两个字符串Source
和v8
,代码逻辑是将这两个字符串拼接到Destination
变量中,然后如果输入的值与这个拼接后的字符串相等,则成功,即flag为flag{03ff6cf238c5cd8e7b4ee1e9567ad5a4}
题目:[加加减减]
- 题目来源:polarctf-reverse-[加加减减]
- 解题:
解压得到一个可执行文件,使用exeinfo查看文件基本信息,为windows 32bit,未加壳文件
使用ida 32bit打开,ctrl+f搜索main函数,f5查看源码,看到调用了main_0函数,点开main_0函数
代码审计
int __cdecl main_0(int argc, const char **argv, const char **envp)
{
char v4; // [esp+0h] [ebp-154h]
char v5; // [esp+0h] [ebp-154h]
size_t i; // [esp+D0h] [ebp-84h]
char Str[60]; // [esp+DCh] [ebp-78h] BYREF
char Str2[39]; // [esp+118h] [ebp-3Ch] BYREF
int v9; // [esp+13Fh] [ebp-15h]
int v10; // [esp+143h] [ebp-11h]
__int16 v11; // [esp+147h] [ebp-Dh]
char v12; // [esp+149h] [ebp-Bh]
__CheckForDebuggerJustMyCode(&unk_41C009);
strcpy(Str2, "ek`fz5123086/ce7ac7/`4a81`6/87b`b28a5|");
v9 = 0;
v10 = 0;
v11 = 0;
v12 = 0;
j_memset(Str, 0, 0x32u);
sub_41104B("input\r\n", v4);
sub_4110AA("%s", (char)Str);
for ( i = 0; i < j_strlen(Str); ++i )
--Str[i];
if ( !j_strcmp(Str, Str2) )
sub_41104B("success\r\n", v5);
else
sub_41104B("sorry\r\n", v5);
return 0;
}
数组元素ascii减1
exp
python
Str = "ek`fz5123086/ce7ac7/`4a81`6/87b`b28a5|"
result = ''.join(chr(ord(c)+1) for c in Str)
print(result)