WrongPlanet.net was compromised through a phpnuke security hole that Mashi, thankfully, patched. The attacker got in through a mysql injection that he was able to execute because of a bug in the input validation for the URL. The line that read
Code:
if (preg_match("/\?admin/", "$checkurl")
checks to see if the person is not an admin. If the person isn't an admin, the script won't let the person access the database. If the person is an admin, the user can access the database. The url validation was buggy, however, and didn't truly prevent nonadmins from executing an sql injection, because while someone couldn't write:
Code:
http://wrongplanet.net/admin.php?admin=alex
Someone could write
Code:
http://wrongplanet.net/admin.php?thisTextIs=notimportant&admin=alex
without the mentioned regex actually catching the input as being invalid. By changing the conditional to this:
Code:
if (preg_match("/\?admin/", "$checkurl") || preg_match("/\&admin/", "$checkurl"))
we are able to make the regex register a url as invalid when something precedes the "admin=" portion of the url. Thats the only thing that needed to be changed to have prevented the attacker from gaining access.