Code:
$speedHackAdminBypass = 0; //Set to 1, will say that admins don't have to do, use html freely again! :)
if (($speedHackAdminBypass == 1 && !is_admin($admin)) || ($speedHackAdminBypass == 0 && (! is_admin($admin) || is_admin($admin)))) {
if (isset($_REQUEST)) {
foreach ($_REQUEST as $key => $secvalue) {
$secvalue = urldecode($secvalue);
$secvalue = stripslashes($secvalue);
//Following code examines contents in between <> tags, if tag is not commonly used
//replace all instances of < > ( ) # and script with html equivalent characters
//tags not meeting common criteria will be present on the page as they are no longer
//properly formatted tags.
//Do initial check on tags to see how they are, if they are formatted wrong,
//attempt to help out. Affects tags which <> are empty, > > have no beginning tag,
// < < missing an end tag, < have no end tag
$sloppytags = array("'([\r\n])[\s]+'", "'^(>|\">)'", "'(<\s*>)'m", "'((?:\<)(\s*?\/?\s*?[^>]*\/?\/?\s*?)(?:\<))'mi", "'((?:\>)(\s*?\/?\s*?[^<]*\/?\/?\s*?)(?:\>))'mi", "'((?:\<)(\s*?\/?[^><]+\/?\s*))$'mi", "'(<\s*>)'s");
$bettertags = array("", "", "", "\\2<", ">\\2", "<\\2>", "");
$secvalue = preg_replace($sloppytags, $bettertags, $secvalue);
//Grabs all remaining HTML Tags (Empty tags should have been deleted above)
preg_match_all("/(<\s*?\/?\s*?[^>]*[^<]*\/?\/?\s*?>)/im", $secvalue, $urlblah);
$blah = array();
$countblah = 0;
foreach($urlblah[0] as $url) {
$the_reg = '/(<\s*\/?\s*(b|br|em|li|ul|i|pre|tt|citestrong|blockquote|dl|dt|dd|ol|center|a|(hr|font|p)(\s*(align|size|color)(\=(\"|\'|\s*)[a-z0-9\%px\;]*)\7|\s*?noshade)?)\s*?\/?\s*>)/si';
if(! preg_match($the_reg, $url)) {
$do = 1;
if (eregi("src=", $url)) {
$do = 0;
$img_reg = '/(src=(\"|\'|\s*)[^\"\'\?\&]*(\.gif|\.jpg|\.png)\2)/i';
if (! preg_match($img_reg, $url)) {
$do = 1;
}
}
if (eregi("href=", $url)) {
$do = 0;
$loc_reg = '/(href=[^>]*(location|\([^>]*[^)]*\)|\#|\.js|\.vbs|\.css|alert|document\.?|cookie)[^>]*)/i';
if (preg_match($loc_reg, $url)) {
$do = 1;
} else {
$do = 0;
}
}
} else {
$do = 0;
}
if ($do == 1) {
$dead = array("'#'", "'<'", "'>'", "'\('", "'\)'", "'\/'", "'script'i", "'alert'i", "'document'i", "'location'i", "'cookie'i");
$live = array("#", "<", ">", "(", ")", "/", "script", "alert", "document", "location", "cookie");
$blah[$countblah] = preg_replace($dead, $live, $url);
} elseif($do == 0) {
$blah[$countblah] = $url;
}
$blah[$countblah] = $blah[$countblah];
$do = 0;
$countblah++;
}
$secvalue = str_replace($urlblah[0], $blah, $secvalue);
//Lets do a final sweep on everything not within the <> tags. xss attacks
//using document,location,alert,cookie,and parenthesis, having fun now?
$morebad = array("'alert'i", "'document'i", "'location'i", "'cookie'i", "'\('", "'\)'");
$moregooder = array("alert", "document", "location", "cookie", "(", ")");
$secvalue = preg_replace($morebad, $moregooder, $secvalue);
$_REQUEST[$key] = "$secvalue";
if (isset($GLOBALS[$key])) {
$GLOBALS[$key] = $secvalue;
}
if(isset($_GET[$key]) || isset($HTTP_GET_VARS[$key])) {
$_GET[$key] = $secvalue;
$HTTP_GET_VARS[$key] = $secvalue;
} elseif(isset($_POST[$key]) || isset($HTTP_POST_VARS[$key])) {
$HTTP_POST_VARS[$key] = $secvalue;
$_POST[$key] = $secvalue;
}
}
}
}
|