Description

People either love or hate math. Do you love it? Prove it! You just need to solve a bunch of equations without a mistake.

Service: 188.166.133.53:11027

Solution

Connecting to the service with nc 188.166.133.53 11027 gave me a simple equation. I answered a few manually, but quickly realized that I had to write a script for this.

From my manual testing I saw that the format was always of the format x [+-*/] [number] = [number]

So I quickly hammered together a script, and crossed my fingers.

Yes, I know the code is ugly as hell. But it works.

#!/usr/bin/env python

from pwn import *

def parse_equation(indata):
    equation,equals = indata.split(' = ')
    new_equation = equation.lstrip('x ')

    oper = new_equation[0]
    if oper == '-':
        new_equation = equals + ' + ' + new_equation[2:]
    elif oper == '+':
        new_equation = equals + ' - ' + equation[4:]
    elif oper == '*':
        new_equation = equals + ' / ' + equation[4:]
    elif oper == '/':
        new_equation = equation[4:] + ' / ' + equals


    log.info('Parsed equation: ' + new_equation)
    return eval(new_equation)

host = '188.166.133.53'
port = 11027

r = remote(host, port)              # Connect to host
r.recv(1024)                        # Receive welcome line
while True:
    data = r.recv(1024)
    log.info(data)
    junk,equation = data.split(':')     # Extract equation from receive data
    answer = str(parse_equation(equation.strip()))    # Parse equation
    log.info('Answer: ' + answer)
    r.send(answer)
    log.info(r.recv(1024))

r.close()                           # Close connection

Flag: IW{M4TH_1S_34SY}

Rekt Sec

InternetWatche 2016 CTF - The Secret Store (Web 70)

InternetWatche 2016 CTF - The Secret Store (Web 70) Continue reading