Stop Drop and Roll

Flag

HTB{1_wiLl_sT0p_dR0p_4nD_r0Ll_mY_w4Y_oUt!}

Solution

from pwn import *

R = None

pack = {
    b'GORGE': b'STOP',
    b'PHREAK': b'DROP',
    b'FIRE': b'ROLL'
}

def transform(st):
    st = st[:-1]
    st = st.split(b', ')
    res = []
    for s in st:
        print('key: ', s)
        res.append(pack[s])
    return b'-'.join(res)

def toAscii(data):
    return data.decode().strip()

def choose_prompt(choice, prompt=b"> "):
    R.sendlineafter(prompt, choice)

def recv_prompt(prompt):
    R.recvuntil(prompt)
    return R.recvline()

def pwn():
    choose_prompt(b'y', b'(y/n) ')
    R.recvline()
    line = R.recvline()
    print(line)
    res = transform(line)
    print(res)
    R.sendline(res)

    for i in range(1000):
        line = recv_prompt(b'What do you do? ')
        print(line)
        res = transform(line)
        print(res)
        R.sendline(res)

    while True:
        print(R.recvline())

if __name__ == '__main__':
    if args.REMOTE:
        ip, port = args.REMOTE.split(':')
        R = remote(ip, int(port))
    else:
        R = process(["python", "main.py"])

    pwn()

Author: calx

Created: 2024-05-30 Thu 05:24

Emacs 29.3 (Org mode 9.6.15)