Aerosol Posted December 10, 2014 Report Posted December 10, 2014 -----BEGIN PGP SIGNED MESSAGE-----Hash: SHA1Product: phpTrafficAProduct page: http://soft.zoneo.net/phpTrafficA/Affected versions: Up to and including 2.3 (latest as of writing).Description:An SQL injection exists in Php/Functions/log_function.php, line 933:$sql3 ="INSERT INTO `${table}_host` SET date='$date', host='',hostname='', page='$page', ref='$cleanref', agent='$agent',longIP='$iplong'";The $agent variable comes directly from $_SERVER['HTTP_USER_AGENT'],without any escaping. This makes SQL injection possible. Even ifmultiple statements in one query has been turned off, the contents ofthe database can still be read by manipulating the last parameter of thequery (the IPv4-address stored as an integer). For example, thefollowing spoofed user agent will store the ASCII-value of the secondcharacter of the admin hash as its IP:Firefox', longIP=(SELECT ASCII(SUBSTRING(value,2,1)) FROMphpTrafficA_conf WHERE variable='adminpassword') #This will be displayed in the "Latest visitors > Details" section, andby repeating this procedure multiple times, the entire admin hash (orany other database content) can be retrieved.Partial mitigations:- - Turn off "multiple statements in one query".- - Hide "Latest visitors > Details" section from view. This preventsthe attacker from obtaining the output of the manipulated query.- - Apply this quick fix to line 933:$sql3 ="INSERT INTO `${table}_host` SET date='$date', host='',hostname='', page='$page', ref='$cleanref',agent='".mysql_real_escape_string($agent)."', longIP='$iplong'";The code-fix does not resolve the SQL injection for all serverconfigurations, but should be sufficient for most. A proper fix would bea version of phpTrafficA that uses PDO with prepared statements.Best regards,Daniel Geerts-----BEGIN PGP SIGNATURE-----Version: GnuPG v2.0.14 (GNU/Linux)iQIcBAEBAgAGBQJUhwA8AAoJEHn1bVIKHk5NxhYQAMiEbr06K7UQxXEZv0+3KTr6LTA+65vVdmu0mTPQrTEjNeW46bv5tpnOuZc0q8Nprwbko2V/ANVXnD2NC4nBdYE8J+7XonQq7CnsM//C504D2Vms3ylQhkthycCBc1OXaaEEIF2lmFrLPFsLLNkjaEArA5hDZJE7tSjDoq4/a3Psl1DLC+oblYbAA/JJxcSx5Abdnt47i9HMs9xWxN5Jn9ojOwXoF31YrMxbMoqrENQqnc5lVvfxM+ki/t5sCZV4jk1kRX7Ivf7sEMbhiN0sKqnMUeNwVSgi5308rAYdyg5zpUurvwIlKYtU9kA4N1sIVJCIGzeZXYCIOVAJZNglZ/NBbX9EoLoxeU1R7RS2SWHLEneriiyj0nCyS1X+HSkov9p1gYemxqivgmBKsV3A4LxGCrz7kHpcpYSn15u7vploGOki/G0sqpMVL9UwkK/F5vxRkMWxBjqvCzXudDXBvYVJgnSJGw0QB6roJqHx3yf3x91YE8m69axiFTE8dAUz1IfTsbEgc2oUfnO+crWPyWh7IHx8gIfN/3Uck/6gLPse63rtKB+jI7/i4xJbm0FIbOnodzkJP1GDy9U3UsEbleSWkKV884YFogi1iyfuOhrqCGWatQybpHlM/VyycH3NvzpsDFwVCYrnaQ/jpfKS1rlzdWvSYp6b43Nui30hm+kv=PZkK-----END PGP SIGNATURE-----Source Quote