模板
from pwn import *
# patchelf --set-interpreter ./ld-linux-x86-64.so.2 ./ts_model
# patchelf --replace-needed libc.so.6 ./libc.so.6 ./ts_model
context.log_level = "debug"
context(arch="amd64", os="linux")
context.terminal = ['tmux','splitw','-h']
def p(s,m):
if m == 0:
io = process(s)
else:
if ":" in s:
x = s.split(":")
addr = x[0]
port = int(x[1])
io = remote(addr,port)
elif " " in s:
x = s.split(" ")
addr = x[0]
port = int(x[1])
io = remote(addr,port)
else:
error(f"{s} may be some error")
return io
def gg():
gdb.attach(io)
raw_input()
def one_gadget(lib,libc_base):
log.progress('Leak One_Gadgets...')
one_ggs = str(subprocess.check_output(['one_gadget','--raw',lib]),encoding = "utf-8").split(' ')
ogg = list(map(int,one_ggs))
for i in range(len(ogg)):
ogg[i] += libc_base
print(list(map(lambda x: hex(x), ogg)))
return ogg
s = lambda x : io.send(x)
sa = lambda x,y: io.sendafter(x, y)
sla = lambda x,y: io.sendlineafter(x, y)
sl = lambda x : io.sendline(x)
rv = lambda x : io.recv(x)
ru = lambda x : io.recvuntil(x)
rvl = lambda : io.recvline()
lg = lambda x,y: log.info(f"\x1b[01;38;5;214m {x} => {hex(y)} \x1b[0m")
ia = lambda : io.interactive()
uu32 = lambda x : u32(x.ljust(4,b'\x00'))
uu64 = lambda x : u64(x.ljust(8,b'\x00'))
l32 = lambda : u32(io.recvuntil(b"\xf7")[-4:].ljust(4,b"\x00"))
l64 = lambda : u64(io.recvuntil(b"\x7f")[-6:].ljust(8,b"\x00"))
io = p("./bins/bin2/babystack",0)