Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary brackets in pwn arm template #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions files/templates/pwn_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,68 @@

from pwn import *

context.terminal = ['tmux', 'splitw', '-v']
context.terminal = ["tmux", "splitw", "-v"]
context.arch = "amd64"

binary = '[binary]'
binary = "[binary]"
elf = context.binary = ELF(binary)

ssh_en = False
if args.R:
host = args.HOST or ''
host = args.HOST or ""
port = args.PORT or 0

if ssh_en:
user = ''
password = ''
user = ""
password = ""
r = ssh(user=user, host=host, port=port, password=password)


def start():
if args.R:
if not ssh_en: return remote(host, port)
else: return r.process(binary, cwd='')
if not ssh_en:
return remote(host, port)
else:
return r.process(binary, cwd="")

else:
gs = '''
gs = """
init-pwndbg
c
'''
if args.GDB: return gdb.debug(elf.path, gs)
else: return process(elf.path)
"""
if args.GDB:
return gdb.debug(elf.path, gs)
else:
return process(elf.path)


def one_gadget(filename, base_addr=0):
return [(int(i)+base_addr) for i in subprocess.check_output(['one_gadget', '--raw', filename]).decode().split(' ')]
return [
(int(i) + base_addr)
for i in subprocess.check_output(["one_gadget", "--raw", filename])
.decode()
.split(" ")
]


def log_addr(name, addr):
log.info('{}: 0x{:x}'.format(name, addr))
log.info("{}: 0x{:x}".format(name, addr))


io = start()

sl = lambda x : io.sendline(x.encode() if type(x) == str else x)
sla = lambda x, y : io.sendlineafter(x.encode() if type(x) == str else x, y.encode() if type(y) == str else y)
se = lambda x : io.send(x.encode() if type(x) == str else x)
sa = lambda x, y : io.sendafter(x.encode() if type(x) == str else x, y.encode() if type(y) == str else y)
ru = lambda x : io.recvuntil(x.encode() if type(x) == str else x)
rl = lambda : io.recvline()
cl = lambda : io.clean()
uu32 = lambda x : u32(x.ljust(4, b'\x00'))
uu64 = lambda x : u64(x.ljust(8, b'\x00'))
sl = lambda x: io.sendline(x.encode() if type(x) == str else x)
sla = lambda x, y: io.sendlineafter(
x.encode() if type(x) == str else x, y.encode() if type(y) == str else y
)
se = lambda x: io.send(x.encode() if type(x) == str else x)
sa = lambda x, y: io.sendafter(
x.encode() if type(x) == str else x, y.encode() if type(y) == str else y
)
ru = lambda x: io.recvuntil(x.encode() if type(x) == str else x)
rl = lambda: io.recvline()
cl = lambda: io.clean()
uu32 = lambda x: u32(x.ljust(4, b"\x00"))
uu64 = lambda x: u64(x.ljust(8, b"\x00"))

io.interactive()
62 changes: 39 additions & 23 deletions files/templates/pwn_template32.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,69 @@

from pwn import *

context.terminal = ['tmux', 'splitw', '-v']
context.terminal = ["tmux", "splitw", "-v"]
context.arch = "i386"

binary = '[binary]'
binary = "[binary]"
elf = context.binary = ELF(binary)

ssh_en = False
if args.R:
host = args.HOST or ''
host = args.HOST or ""
port = args.PORT or 0

if ssh_en:
user = ''
password = ''
user = ""
password = ""
r = ssh(user=user, host=host, port=port, password=password)


def start():
if args.R:
if not ssh_en: return remote(host, port)
else: return r.process(binary, cwd='')
if not ssh_en:
return remote(host, port)
else:
return r.process(binary, cwd="")

else:
gs = '''
gs = """
init-pwndbg
c
'''
if args.GDB: return gdb.debug(elf.path, gs)
else: return process(elf.path)
"""
if args.GDB:
return gdb.debug(elf.path, gs)
else:
return process(elf.path)


def one_gadget(filename, base_addr=0):
return [(int(i)+base_addr) for i in subprocess.check_output(['one_gadget', '--raw', filename]).decode().split(' ')]
return [
(int(i) + base_addr)
for i in subprocess.check_output(["one_gadget", "--raw", filename])
.decode()
.split(" ")
]


def log_addr(name, addr):
log.info('{}: 0x{:x}'.format(name, addr))
log.info("{}: 0x{:x}".format(name, addr))


io = start()

sl = lambda x : io.sendline(x.encode() if type(x) == str else x)
sla = lambda x, y : io.sendlineafter(x.encode() if type(x) == str else x, y.encode() if type(y) == str else y)
se = lambda x : io.send(x.encode() if type(x) == str else x)
sa = lambda x, y : io.sendafter(x.encode() if type(x) == str else x, y.encode() if type(y) == str else y)
ru = lambda x : io.recvuntil(x.encode() if type(x) == str else x)
rl = lambda : io.recvline()
cl = lambda : io.clean()
i = lambda : io.interactive()
uu32 = lambda x : u32(x.ljust(4, b'\x00'))
uu64 = lambda x : u64(x.ljust(8, b'\x00'))
sl = lambda x: io.sendline(x.encode() if type(x) == str else x)
sla = lambda x, y: io.sendlineafter(
x.encode() if type(x) == str else x, y.encode() if type(y) == str else y
)
se = lambda x: io.send(x.encode() if type(x) == str else x)
sa = lambda x, y: io.sendafter(
x.encode() if type(x) == str else x, y.encode() if type(y) == str else y
)
ru = lambda x: io.recvuntil(x.encode() if type(x) == str else x)
rl = lambda: io.recvline()
cl = lambda: io.clean()
i = lambda: io.interactive()
uu32 = lambda x: u32(x.ljust(4, b"\x00"))
uu64 = lambda x: u64(x.ljust(8, b"\x00"))

io.interactive()
62 changes: 39 additions & 23 deletions files/templates/pwn_templateARM.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,73 @@

from pwn import *

os.environ['QEMU_LD_PREFIX'] = '/usr/arm-linux-gnueabi'
os.environ["QEMU_LD_PREFIX"] = "/usr/arm-linux-gnueabi"

context.terminal = ['tmux', 'splitw', '-v']
context.terminal = ["tmux", "splitw", "-v"]
context.arch = "arm"

binary = '[binary]'
binary = "[binary]"
elf = context.binary = ELF(binary)
rop = ROP(elf)

ssh_en = False
if args.R:
host = args.HOST or ''
host = args.HOST or ""
port = args.PORT or 0

if ssh_en:
user = ''
password = ''
user = ""
password = ""
r = ssh(user=user, host=host, port=port, password=password)


def start():
if args.R:
if not ssh_en: return remote(host, port)
else: return r.process(binary, cwd='')
if not ssh_en:
return remote(host, port)
else:
return r.process(binary, cwd="")

else:
gs = '''
gs = """
br _start
c
init-pwndbg
c
'''
if args.GDB: return gdb.debug(elf.path, gs)
else: return process([f'qemu-arm {elf.path}'.split()])
"""
if args.GDB:
return gdb.debug(elf.path, gs)
else:
return process(f"qemu-arm {elf.path}".split())


def one_gadget(filename, base_addr=0):
return [(int(i)+base_addr) for i in subprocess.check_output(['one_gadget', '--raw', filename]).decode().split(' ')]
return [
(int(i) + base_addr)
for i in subprocess.check_output(["one_gadget", "--raw", filename])
.decode()
.split(" ")
]


def log_addr(name, addr):
log.info('{}: 0x{:x}'.format(name, addr))
log.info("{}: 0x{:x}".format(name, addr))


io = start()

sl = lambda x : io.sendline(x.encode() if type(x) == str else x)
sla = lambda x, y : io.sendlineafter(x.encode() if type(x) == str else x, y.encode() if type(y) == str else y)
se = lambda x : io.send(x.encode() if type(x) == str else x)
sa = lambda x, y : io.sendafter(x.encode() if type(x) == str else x, y.encode() if type(y) == str else y)
ru = lambda x : io.recvuntil(x.encode() if type(x) == str else x)
rl = lambda : io.recvline()
cl = lambda : io.clean()
uu32 = lambda x : u32(x.ljust(4, b'\x00'))
uu64 = lambda x : u64(x.ljust(8, b'\x00'))
sl = lambda x: io.sendline(x.encode() if type(x) == str else x)
sla = lambda x, y: io.sendlineafter(
x.encode() if type(x) == str else x, y.encode() if type(y) == str else y
)
se = lambda x: io.send(x.encode() if type(x) == str else x)
sa = lambda x, y: io.sendafter(
x.encode() if type(x) == str else x, y.encode() if type(y) == str else y
)
ru = lambda x: io.recvuntil(x.encode() if type(x) == str else x)
rl = lambda: io.recvline()
cl = lambda: io.clean()
uu32 = lambda x: u32(x.ljust(4, b"\x00"))
uu64 = lambda x: u64(x.ljust(8, b"\x00"))

io.interactive()
14 changes: 8 additions & 6 deletions files/templates/pwn_templateKernel/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@
import base64
import os


def run(cmd):
sock.sendlineafter("$ ", cmd)
sock.recvline()


with open("./initramfs/xpl", "rb") as f:
payload = bytes2str(base64.b64encode(f.read()))

host = ''
host = ""
port = 0
sock = Socket(host, port)

run('cd /tmp')
run("cd /tmp")

logger.info("Uploading...")
for i in range(0, len(payload), 512):
print(f"Uploading... {i:x} / {len(payload):x}")
run('echo "{}" >> b64exp'.format(payload[i:i+512]))
run('base64 -d b64exp > xpl')
run('rm b64exp')
run('chmod +x xpl')
run('echo "{}" >> b64exp'.format(payload[i : i + 512]))
run("base64 -d b64exp > xpl")
run("rm b64exp")
run("chmod +x xpl")

sock.interactive()