... then we will see standard php error messages, revealing full path to script:
Warning: fsockopen() expects parameter 2 to be long, string given in D:\apache_wwwroot\nuke72\admin\m odules\blocker_query.php on line 305 Port foobar does not appear to be open.
Reason is, that script does not check validity of the portNum, which must be integer in range of 1..6 5535.
B. Cross-site scripting aka XSS (in integrated Network Query Tool)
B1 - XSS through unsanitaized user submitted variable "target"
As we can see, $last_page has value of the urldecoded QUERY_STRING. So if we will add to query string something like %27, then after urldecode() we have "'" (single quote) and this can b e beginning of the brand new sql injection case. Let's look further:
################################### #Page Tracker Function by Kipuka # ################################### if ($tracker_del_on == 1) { $max_tracker_check = $db->sql_query("SELECT count(*) as count FROM ".$pr efix."_blocked_pagetracker WHERE id_tracker = '$access_id'"); $numrows = $db->sql_numrows($max_tracker_check);
if ($numrows > 0) { list($count) = $db->sql_fetchrow($max_tracker_check); } //die("$last_page"); if ($count < $tracker_max_b) { $db->sql_query("INSERT DELAYED INTO ".$prefix."_blocked_pagetracker (last_page ,page_date ,id_tracker) VALUES ('$last_page', '$date', '$access_id')");
} else { $tracker_limitB = $count - $tracker_max_b; $result = $db->sql_query("SELECT id FROM ".$prefix."_blocked_pagetr acker WHERE id_tracker = '$access_id' ORDER BY page_date LIMIT ".$tracker_limitB.",1"); $numrows = $db->sql_numrows($result); if ($numrows > 0) { $row = $db->sql_fetchrow($result); $page_id = $row['id']; $db->sql_query("DELETE FROM ".$prefix."_blocked_pagetracker WHE RE id_tracker = '$access_id' AND id <= '$page_id'"); } $xxx = mysql_error(); die("$xxx"); $db->sql_query("INSERT INTO ".$prefix."_blocked_pagetracker (last_pag e ,page_date ,id_tracker) VALUES ('$last_page', '$date', '$access_id')"); } }
So, sql injection possibility exists, but not in "SELECT FROM" clause, but in "INSERT INTO" construction. So forget the UNION and JOIN tricks. And MySql version 4.1 is not yet in wide use, so we can't use subselects ... Therefore this is noncritical sql injection case, but anyway, potential attacker can use this securit y hole to accomplish some tasks by using of the built-in mysql functions like:
Because attacker does'nt have the visual feedback from script, "blindfolded" methods must b e used, for example "benchmark" method. This can be implemented in perl (php, python, etc...) script, using htt p requests similar to this:
I have written proof of concept code in perl for this exploit and it works perfectly.
D. Easy bypass of the anti-sql-injection filters
Protector System implements various filters against XSS and sql injection. Examples:
...
//IF the user sending any $_SERVER["HTTP_REFERER"] then continue if (strlen($_SERVER["HTTP_REFERER"]) > 0) { //If the user is POSTing from another server do a scan if(eregi("(^|[^a-zA-Z0-9])union(\ )+(all\ |distinct\ )?(\ )*select\ |\.\.\/", $sTemp) && !ereg("(http://$_SERVER[HTTP_HOST])", $_SERVER["HTTP_REFERER"])) { $original_ip = long2ip(-(4294967296-$ipcheck)); $the_error = "User $the_blocked_user with IP $original_ip tried to send information thru a POS T method\r\n"
...
if(eregi("(^|[^a-zA-Z0-9])union(\ )+(all\ |distinct\ )?(\ )*select\ |\.\.\/", $sTemp)) { //Just send a mail incase =) if ($pro_mail && $pro_mail != '' && $mail_blocker == '1') { mail($pro_mail, $blocker _subject, $the_unset_error, $headers); } unset($_POST[$FormFieldName]); echo "<p><h1>Your Attempt to use SQL exploit was blocked</h1>" ; echo "<i>Powered whit Protector System</i>"; die(); } }
...
if($sec_cookieB == '1')
foreach ($_COOKIE as $cookie_name => $value_cookie) { $result = $db ->sql_query("SELECT cookie FROM ".$prefix."_blocked_agent WHERE c ookie = '$cookie_name'"); if($db->sql_numrows($result)>0 && !empty($_COOKIE)) { if (eregi("union\ |&#?[a-zA-Z0-9]+;|:\/\/|\.\.\/|[$<>{}\(\)\"'`]", $value_c ookie)) { $value_cookie = htmlspecialchars($value_cookie, ENT_QUOTES); setcookie($cookie_name,"", time() - 3600); unset($_COOKIE[$cookie_name]); }
...
########################################################################### #Block unvanted GET code! #Security scan of REQUEST_METHOD GET
This whitepaper, written by Ofer Maor and Amichai Shulman, describes various methods to bypass sql injection detection and the final conclusion is:
"At this point, we believe the conclusion of this paper is clear to the reader. Signature protection against SQL Injection is simply not enough. Although this paper demonstrates only some of the variety of evasion techniques for avoiding SQL Injection signatures, some or even all of these techniques are likely to operate on most of today's signature protection mechanisms."
I`m hundred percent agree with this. So let's try to fool sql injection filters in Protector System in practice. First, we make request like this: