choppers

DEFCON Quals 2015: mathwhiz

2015-05-17 00:00:02

Description

Baby's First: 1 point
mathwhiz

mathwhiz_c951d46fed68687ad93a84e702800b7a.quals.shallweplayaga.me:21249

Analysis

When you connect to the server, you get prompted with a simple math problem to solve.

$ nc mathwhiz_c951d46fed68687ad93a84e702800b7a.quals.shallweplayaga.me 21249
2 + 1 =
You took too long!  You lost after 1 rounds.
$

It looks like we have to write a simple expression evaluator, or just use python's eval function.

Solution

#!/usr/bin/python

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("mathwhiz_c951d46fed68687ad93a84e702800b7a.quals.shallweplayaga.me", 21249))

while 1:
    line = s.recv(1024)
    print line[:-1]
    expression = line[:-2]
    expression = expression.replace("[", "(")
    expression = expression.replace("]", ")")
    expression = expression.replace("{", "(")
    expression = expression.replace("}", ")")
    expression = expression.replace("ONE", "1")
    expression = expression.replace("TWO", "2")
    expression = expression.replace("THREE", "3")
    expression = expression.replace("1^1", "1")
    expression = expression.replace("1^2", "1")
    expression = expression.replace("1^3", "1")
    expression = expression.replace("2^1", "2")
    expression = expression.replace("2^2", "4")
    expression = expression.replace("2^3", "8")
    expression = expression.replace("3^1", "3")
    expression = expression.replace("3^2", "9")
    expression = expression.replace("3^3", "27")
    print eval(expression)
    s.send(str(eval(expression)) + '\n')

s.close()
$ ./mathwhiz.py
2 + 1 =
3
1 + 1 =
2
2 + 1 =
3
3 - 2 =
1
1 + 1 =
2
...
1 + 3 - 2 =
2
1 - 1 + 2 + 1 =
3
3 - 1 - 1 + 1 =
2
1 + 1 + 1 =
3
You won!!!
The flag is: Farva says you are a FickenChucker and you'd better watch Super Troopers 2
.
Traceback (most recent call last):
  File "./mathwhiz.py", line 28, in <module>
    print eval(expression)
  File "<string>", line 1
    You won!!!
          ^
SyntaxError: invalid syntax
$