Title : [writeups] Internetwache CTF 2016 - A numbers game #code50
Released : 2016-02-22 02:04:19 -0500
Viewed : 634

https://ctf.internetwache.org/tasks/code/50

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

An easy challenges. Sample input/output:

$ nc 188.166.133.53 11027
Hi, I heard that you're good in math. Prove it!
Level 1.: x - 17 = -15
2
Yay, that's right!
Level 2.: x + 35 = 43

Solved using PHP

#!/usr/bin/php -q
<?php
	$host = "188.166.133.53";
	$port=11027;
	$fp = fsockopen($host, $port, $errno, $errstr, 30);
	if (!$fp) {
		echo $errstr." (".$errno.")\n";
	} else {
		while (!feof($fp)) {
			$line=fgets($fp,128);
			if(!strpos($line,'Prove')){
				$e=explode(' ',$line);
				$h=trymath($e[6],$e[4],$e[3]);
				fwrite($fp,$h);
			}
		}
	}
	function trymath($c,$b,$z){
		switch($z){
			case '+':
				$r=$c-$b; break;
			case '-':
				$r=$c+$b; break;
			case '*':
				$r=$c/$b; break;
			case '/':
				$r=$c*$b; break;
		}
		return $r;
	}

Flag: IW{M4TH_1S_34SY}