Solving the SC1:Math Bot Capture the Flag Challenge with Python

Home / Capture the flag / Solving the SC1:Math Bot Capture the Flag Challenge with Python

Summary

The MSP Tech Club puts on an annual CTF, available here. After stumbling upon the channel on IRC (#alexctf on Freenode) I felt compelled to compete in order to test the lessons that I’ve been learning throughout my OSCP course, the summary of which is below.

The MSP:Math Bot CTF Challenge Explained

The challenge presents two mirrored servers to connect to using netcat. Connecting to either presents a prompt not unlike the following:

Answering each question manually re-presents a new mathematical problem which suggests that the answer to the challenge is to write a bot which can answer the questions to proceed to the next step.

CTF Challenge Solution and flag

After writing a script to connect to the server and handle the equation I realised that a number of results were returned with a variety of operators. Further tweaking to the script allowed it to continually answer mathematical questions presented to it allowed it to answer 500 questions and reveal the flag:

Resulting Python Script

The final script is preserved below: