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
|
from pwn import * import os import sys from pwn import * import argparse from pwnlib.util import misc
context.os = 'linux' context.terminal = ['tmux', 'splitw', '-h']
pwn_arch ='arm' link_dir = "/usr/arm-linux-gnueabi/" pwnfile = './ret2libc_arm' port= "8888" LOCAL = 1
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() leak = lambda name, addr: log.success('{} = {:#x}'.format(name, addr)) uu32 = lambda data: u32(data.ljust(4, '\0')) uu64 = lambda data: u64(data.ljust(8, '\0')) li = lambda x: log.info('\x1b[01;38;5;214m' + x + '\x1b[0m')
if len(sys.argv) == 1: print ("Welcome to c0ke's simplified pwntools template!!!") print ("Usage : \n") print (" python mode.py HOST:PORT\n ") print (" python mode.py [1/0] [GDB]\n ") exit() elif len(sys.argv)==2: context.log_level = 'debug' chioce = sys.argv[1] if chioce =='1': GDB = 1 else: GDB = 0
else: LOCAL = 0 context.log_level = 'debug' server_ip = sys.argv[1].split(':')[0] server_port = int(sys.argv[1].split(':')[1])
elf = ELF(pwnfile) rop = ROP(pwnfile) context.binary = pwnfile
libcfile = link_dir + "lib/libc.so.6"
libc = ELF(libcfile)
def pwn_init(): if GDB == 1: attach_payload =""" gdb-multiarch \ -ex "file {0}"\ -ex "set architecture {2}" \ -ex "target remote 127.0.0.1:{1} "\ """.format(pwnfile , port , pwn_arch) pwnlib.util.misc.run_in_new_terminal(attach_payload)
def cat_flag(): flag_header = b'flag{' sleep(1) sl('cat flag') ru(flag_header) flag = flag_header + ru('}') + b'}' exit(0)
def exploit():
def finish(): ia() c()
if __name__ == '__main__': if LOCAL: if GDB: io = process(["qemu-" + pwn_arch , "-L" , link_dir ,"-g",port, pwnfile]) else: io = process(["qemu-" + pwn_arch , "-L" , link_dir, pwnfile])
else: io = remote(server_ip, server_port) pwn_init() exploit() finish()
|