I first tried around a bit with changing arithmetic operators but unfortuntely, nothing worked. I was convinced that it must be some PHP-specific stuff but I'm not a great php fan so I decided to brute-force that stuff with gave me the opportunity to get into a script language I wanted to learn since a long time anyway - Python. I solved most of the programming challenges before with C (sometimes Java), which can get quite annoying when it comes to string manipulation etc.
So here it is, my first python script which gave me the solution for this challenge:
Code: Select all
#!/usr/bin/env python
import os
# php statement we want to brute-force
statement_pre = '$y = 79; '
statement = '$x = $y * 2245 + ($y * 2 - 7);'
statement_post = ' echo $x;'
for position in range(0, len(statement)):
for token in range(0x20, 0x7f):
out_str = statement_pre
out_str += statement[0:position] + chr(token) + statement[position+1:]
out_str += statement_post
out_str = out_str.replace('$', '\$')
if os.popen('php -r "' + out_str + '"').readline().find('8841') != -1:
print 'Solution found!'
print 'position: ' + str(position) + ', character: ' + chr(token)
exit(1);
The forced indenting is maybe a bit unfamailiar at first and the fact that all strings are immutable shocked me (no somestring[bla] = 'x' allowed), but I think I'm getting used to and after seeing some source code from others it seems that the readability of Python scripts is really good - compared e.g. to the Perl nightmare

Anyway, the solution wasn't as hard as I thought and in fact it would have been easy to find out without scripting, but it was a nice exercise
