zo ja dan toegang gewijgerd 2. Bij hackersaanvallen op je site (gedetecteerd hier in security.php) wordt ip geblokkeerd als je dat hebt aangegeven op de beheerpagina bij Instellingen. Je kunt opgeven of je wilt dat de persoon geredirect wordt naar de index en zijn code genegeerd wordt of dat zijn ip geblokkeerd wordt en de persoon niet welkom is ! Je kunt dit bestand ook los gebruiken (als je de sql aanpast) in een andere php applicatie maar dan moet je wel de credits intackt laten en onder de GPL publiceren. Zorg wel dat je dan de code onder "Eigen extra security checks" verwijderd want die is specifiek voor het gebruik vna schone url's geschreven. denk neit dat je er bent met dit bestand want je moet ook veilig programmeren verder wat inhoud dat je altijd iedere gebruikersinvoer op welke plek dan ook dus de adresregel en formulieren altijd controleerd op invoer en filterd. Dit gebeurt in dit geval met de plugin HTMLPurifier via invoerveld en invoertekst. Ook speciale aandacht geven aan waardes die rechtstreeks in de database gaan door het gebruik van arrays kun je een hoop omzijlen en zorgen dat je queries veilig worden ingevoerd met printf en mysql_real_escape_string: http://nl3.php.net/function.mysql-real-escape-string */ /*___________________________________________Ip controle______________________________________________________*/ // Je zal je verbazen hoeveel hackersaanvallen er op php sites worden uitgevoerd ! // kijken of ip in geblokkeerde ips staat $geblokkeerdeips = array(); $sql = "SELECT blocked_ip FROM ".$prefix."_sec_blockedip"; $resultblockedips = mysql_query($sql); while ($blockedips = mysql_fetch_array($resultblockedips)) { $eengeblokkeerdip = uitvoerveld($blockedips['blocked_ip']); $geblokkeerdeips[] = $eengeblokkeerdip; } if (in_array($ip, $geblokkeerdeips)) { accessdenied(); die(); } /*___________________________________________________________________________________________________________*/ /* ____________________ RavenNuke 7.6 Sentinal functies/code aangepast voor Dutch CMS _____________________ */ /********************************************************/ /* CLIKE, UNION, & Email elements from HackAlert */ /* HTTPAuth element */ /* By: Raven PHP Scripts */ /* http://www.ravenphpscripts.com */ /* Copyright © 2004 by Raven PHP Scripts */ /********************************************************/ /* Scripting Blocker elements */ /* By: ChatServ */ /* http://www.nukeresources.com */ /* Copyright © 2004 by Nuke Resources */ /********************************************************/ /* Zie credits.txt Een aantal stukjes beveiligingscode code door Raven - GPL Het gaat om een aantal specifieke stukjes code en met name de reggex die daarin gebruikt worden ter beveiliging van hackersanvallen die door mij weer aangepast zijn voor Dutch CMS. Oorspronkelijk komen ze uit RavenNuke 7.6 uit het bestand nukesentinal.php. Ook heb ik per e-mail nog extra toestemming gekregen: "As long as you retain all credits and links in your code and your code is released as GPL you are permitted to use the code." "Much of that code is mine, function st_clean_string($cleanstring) for example, and/or a combination of effort. The code from Chatserv, for example, was not originally his but was added to. In any event, the code is GPL and you are free to use it as long as you retain all credits in your code with references, urls, etc." Gaylen Fraley (aka Raven) Raven Web Hosting http://ravenwebhosting.com Raven PHP Scripts http://ravenphpscripts.com RavenNuke(tm) http://ravennuke.com Donations Accepted at: http://ravenphpscripts.com/donations.html E-Mail contact: ravenwebservices@everestkc.net Raven Web Hosting Terms of Service (TOS): http://ravenphpscripts.com/contentid-20.html Raven Web Acceptable Use Policy (AUP): http://ravenphpscripts.com/contentid-19.html Aangepast in die zin dat de variabelen, functies en notatie aangepast zijn. Om een voorbeeld te geven: De c-like attack zag er zo uit: */ // Origineel: // $blocker_row = $blocker_array[2]; // if($blocker_row['activate'] > 0) { // if (stristr($nsnst_const['query_string'],'/*') OR stristr($nsnst_const['query_string_base64'],'/*') OR stristr($nsnst_const['query_string'],'*/') OR stristr($nsnst_const['query_string_base64'],'*/')) { // block_ip($blocker_row); // } // } // Veranderd in: // if(stristr($query_string,'/*') // OR stristr($query_string_base64,'/*') // OR stristr($query_string,'*/') // OR stristr($query_string_base64,'*/')) { // blockip($rede="C-like Attack"); // die(); // } // Of de invallid request method: //if(strtolower($nsnst_const['request_method'])!="get" AND strtolower($nsnst_const['request_method'])!="head" AND strtolower($nsnst_const['request_method'])!="post" AND strtolower($nsnst_const['request_method'])!="put") { die(_AB_INVALIDMETHOD); } // Veranderd in: // if(strtolower($_SERVER["REQUEST_METHOD"])!="get" // AND strtolower($_SERVER["REQUEST_METHOD"])!="head" // AND strtolower($_SERVER["REQUEST_METHOD"])!="post" // AND strtolower($_SERVER["REQUEST_METHOD"])!="put") { // blockip($rede="Invalid request method"); // die(); // } /* Er zit verschil tussen $_SERVER["QUERY_STRING"] en $_SERVER['REQUEST_URI'] kwam ik achter. $_SERVER['REQUEST_URI'] kan ook bijvoorbeeld een plaatje zijn wat opgevraagd wordt via de pagina. Je zou zeggen gebruik dan altijd $_SERVER["QUERY_STRING"] maar die werkt niet goed bij schone url's: /stukjes/stukje/stukje Ik heb ze daarom allebei gebruikt. De blokken met $query_string1 (een) en $query_string_base641 (1) zijn door mijzelf toegevoegd en soms $query_string_base64 */ // filter $_GET waardes voor script attack // Copyright 2004(c) ChatServ foreach($_GET as $sec_key => $secvalue) { if ((preg_match("/<[^>]script*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]*object*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]*iframe*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]*applet*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]*meta*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]style*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]*form*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]*img*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]*onmouseover*\"?[^>]*>/i", $secvalue)) || (preg_match("/<[^>]body*\"?[^>]*>/i", $secvalue) && !preg_match("/<[^>]tbody*\"?[^>]*>/i", $secvalue)) || (preg_match("/\([^>]*\"?[^)]*\)/i", $secvalue)) || (preg_match("/\"/", $secvalue))) { blockip($rede="Script attack"); die(); } } // Invalid request method check // http://rails.nuvvo.com/lesson/2318-dealing-with-microsoft-office-protocol-discovery-in-rails if (strtolower($_SERVER["REQUEST_METHOD"])=="options" AND (stristr($browser, 'Microsoft Office') OR stristr($browser, 'Microsoft Office Protocol Discovery') OR stristr($browser, 'Microsoft Data Access') OR stristr($browser, 'Microsoft Data Access Internet Publishing Provider Protocol Discovery') OR stristr($browser, 'Microsoft-WebDAV-MiniRedir'))) { header( 'refresh: 0; url='.$abspad); die(); } // Invalid request method check if (strtolower($_SERVER["REQUEST_METHOD"])!="get" AND strtolower($_SERVER["REQUEST_METHOD"])!="head" AND strtolower($_SERVER["REQUEST_METHOD"])!="post" AND strtolower($_SERVER["REQUEST_METHOD"])!="put") { // AND strtolower($_SERVER["REQUEST_METHOD"])!="options") { if ($locatie == '/') { header( 'refresh: 0; url='.$abspad); die(); } else { blockip($rede="Invalid request method"); die(); } } // Check for UNION attack // Copyright 2004(c) Raven PHP Scripts function st_clean_string($cleanstring) { $st_fr1 = array("%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", "%08", "%09", "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17", "%18", "%19", "%20", "%21", "%22", "%23", "%24", "%25", "%26", "%27", "%28", "%29", "%30", "%31", "%32", "%33", "%34", "%35", "%36", "%37", "%38", "%39", "%40", "%41", "%42", "%43", "%44", "%45", "%46", "%47", "%48", "%49", "%50", "%51", "%52", "%53", "%54", "%55", "%56", "%57", "%58", "%59", "%60", "%61", "%62", "%63", "%64", "%65", "%66", "%67", "%68", "%69", "%70", "%71", "%72", "%73", "%74", "%75", "%76", "%77", "%78", "%79"); $st_to1 = array("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y"); $st_fr2 = array("%0A", "%0B", "%0C", "%0D", "%0E", "%0F", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F", "%2A", "%2B", "%2C", "%2D", "%2E", "%2F", "%3A", "%3B", "%3C", "%3D", "%3E", "%3F", "%4A", "%4B", "%4C", "%4D", "%4E", "%4F", "%5A", "%5B", "%5C", "%5D", "%5E", "%5F", "%6A", "%6B", "%6C", "%6D", "%6E", "%6F", "%7A", "%7B", "%7C", "%7D", "%7E", "%7F", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f", "%2a", "%2b", "%2c", "%2d", "%2e", "%2f", "%3a", "%3b", "%3c", "%3d", "%3e", "%3f", "%4a", "%4b", "%4c", "%4d", "%4e", "%4f", "%5a", "%5b", "%5c", "%5d", "%5e", "%5f", "%6a", "%6b", "%6c", "%6d", "%6e", "%6f", "%7a", "%7b", "%7c", "%7d", "%7e", "%7f"); $st_to2 = array("", "", "", "", "", "", "", "", "", "", "", "", "*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "J", "K", "L", "M", "N", "O", "Z", "[", "\\", "]", "^", "_", "j", "k", "l", "m", "n", "o", "z", "{", "|", "}", "~", "", "", "", "", "", "", "", "", "", "", "", "", "", "*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "J", "K", "L", "M", "N", "O", "Z", "[", "\\", "]", "^", "_", "j", "k", "l", "m", "n", "o", "z", "{", "|", "}", "~", ""); $cleanstring = str_replace($st_fr1, $st_to1, $cleanstring); $cleanstring = str_replace($st_fr2, $st_to2, $cleanstring); return $cleanstring; } function get_query_string() { if($_SERVER["QUERY_STRING"]) { return str_replace("%09", "%20", $_SERVER["QUERY_STRING"]); } return ""; } //Raven 12/18/2005 $query_string = st_clean_string(get_query_string()); $query_string_base64 = st_clean_string(base64_decode($query_string)); function get_query_string1() { if($_SERVER["REQUEST_URI"]) { return str_replace("%09", "%20", $_SERVER["REQUEST_URI"]); } return ""; } $query_string1 = st_clean_string(get_query_string1()); $query_string_base641 = st_clean_string(base64_decode($query_string1)); // Deze was alleen met $query_string dus nog $query_string_base64 toegevoegd define('REGEX_UNION','#\w?\s?union\s\w*?\s?(select|all|distinct|insert|update|drop|delete)#is'); if (preg_match(REGEX_UNION, $query_string)) { blockip($rede="Union Attack"); die(); } if (preg_match(REGEX_UNION, $query_string_base64)) { blockip($rede="Union Attack"); die(); } if (preg_match(REGEX_UNION, $query_string1)) { blockip($rede="Union Attack"); die(); } if (preg_match(REGEX_UNION, $query_string_base641)) { blockip($rede="Union Attack"); die(); } if (stristr($query_string,'+or+') OR stristr($query_string,'*/or/*') OR stristr($query_string_base64,'+or+') OR stristr($query_string_base64,'*/or/*')) { blockip($rede="Union Attack"); die(); } if (stristr($query_string1,'+or+') OR stristr($query_string1,'*/or/*') OR stristr($query_string_base641,'+or+') OR stristr($query_string_base641,'*/or/*')) { blockip($rede="Union Attack"); die(); } // Check for C-LIKE attack // Copyright 2004(c) Raven PHP Scripts //It uses the C comment-style coding ie. /* */ if(stristr($query_string,'/*') OR stristr($query_string_base64,'/*') OR stristr($query_string,'*/') OR stristr($query_string_base64,'*/')) { blockip($rede="C-like Attack"); die(); } if(stristr($query_string1,'/*') OR stristr($query_string_base641,'/*') OR stristr($query_string1,'*/') OR stristr($query_string_base641,'*/')) { blockip($rede="C-like Attack"); die(); } // Check for XSS attack // deze was alleen maar met $query_string en niet met $query_string_base64 dus die nog toegevoegd. if ( stristr($query_string, "ftp://") OR stristr($query_string, "http://") OR stristr($query_string, "https://") OR stristr($query_string, "_SERVER=") OR stristr($query_string, "_COOKIE=") OR stristr($query_string, "file://") OR (stristr($query_string,"../") AND !stristr($query_string, "concat")) OR (stristr($query_string, "cmd=") AND !stristr($query_string, "&cmd")) OR (stristr($query_string, "exec") AND !stristr($query_string, "execu")) OR (stristr($query_string,"concat") AND !stristr($query_string, "../"))) { blockip($rede="Remote script"); die(); } if ( stristr($query_string_base64, "ftp://") OR stristr($query_string_base64, "http://") OR stristr($query_string_base64, "https://") OR stristr($query_string_base64, "_SERVER=") OR stristr($query_string_base64, "_COOKIE=") OR stristr($query_string_base64, "file://") OR (stristr($query_string_base64,"../") AND !stristr($query_string_base64, "concat")) OR (stristr($query_string_base64, "cmd=") AND !stristr($query_string_base64, "&cmd")) OR (stristr($query_string_base64, "exec") AND !stristr($query_string_base64, "execu")) OR (stristr($query_string_base64,"concat") AND !stristr($query_string_base64, "../"))) { blockip($rede="Remote script"); die(); } if ( stristr($query_string1, "ftp://") OR stristr($query_string1, "http://") OR stristr($query_string1, "https://") OR stristr($query_string1, "_SERVER=") OR stristr($query_string1, "_COOKIE=") OR stristr($query_string1, "file://") OR (stristr($query_string1,"../") AND !stristr($query_string1, "concat")) OR (stristr($query_string1, "cmd=") AND !stristr($query_string1, "&cmd")) OR (stristr($query_string1, "exec") AND !stristr($query_string1, "execu")) OR (stristr($query_string1,"concat") AND !stristr($query_string1, "../"))) { blockip($rede="Remote script"); die(); } if ( stristr($query_string_base641, "ftp://") OR stristr($query_string_base641, "http://") OR stristr($query_string_base641, "https://") OR stristr($query_string_base641, "_SERVER=") OR stristr($query_string_base641, "_COOKIE=") OR stristr($query_string_base641, "file://") OR (stristr($query_string_base641,"../") AND !stristr($query_string_base641, "concat")) OR (stristr($query_string_base641, "cmd=") AND !stristr($query_string_base641, "&cmd")) OR (stristr($query_string_base641, "exec") AND !stristr($query_string_base641, "execu")) OR (stristr($query_string_base641,"concat") AND !stristr($query_string_base641, "../"))) { blockip($rede="Remote script"); die(); } // Stop Santy Worm // idem $bad_uri_content=array("rush", "highlight=%", "perl", "chr(", "pillar", "visualcoder", "sess_"); while(list($stid,$uri_content)=each($bad_uri_content)) { if(stristr($query_string, $uri_content)) { blockip($rede="Santy Worm"); die(); } } $bad_uri_content=array("rush", "highlight=%", "perl", "chr(", "pillar", "visualcoder", "sess_"); while(list($stid,$uri_content)=each($bad_uri_content)) { if(stristr($query_string_base64, $uri_content)) { blockip($rede="Santy Worm"); die(); } } $bad_uri_content=array("rush", "highlight=%", "perl", "chr(", "pillar", "visualcoder", "sess_"); while(list($stid,$uri_content)=each($bad_uri_content)) { if(stristr($query_string1, $uri_content)) { blockip($rede="Santy Worm"); die(); } } $bad_uri_content=array("rush", "highlight=%", "perl", "chr(", "pillar", "visualcoder", "sess_"); while(list($stid,$uri_content)=each($bad_uri_content)) { if(stristr($query_string_base641, $uri_content)) { blockip($rede="Santy Worm"); die(); } } /* Je kunt ook nog controleren tegen: lege user agents lege ip's foute referer lijst harverster lijst Maar dat is niet persee noodzakelijk */ /*__________________________________________________________________________________________________________*/ /* ________________________________________Eigen extra security checks _____________________________________*/ /* ongeldige url Je kan controleren of deze tekens erin voorkomen - ? = & & % maar kan ook juist toestaan welke tekens WEL mogen: alleen cijfers en letter en een / en een . en een - en _ */ //Alleen de apache query ?C=D;O=A mag er in voorkomen anders redirect naar index hoofdsite //zie Weblog op de website van Dutch CMS over deze update //$regex1 = "/^[?=;&]/"; $regex1 = "/[^a-zA-Z0-9\._-]+/"; $regex2 = "/^[?A-Z]+([=][A-Z]+)*[;][A-Z]+([=][A-Z]+)$/"; if ($naamdirectory != $beheermap) { $secstukjes1 = explode("/", $query_string); $secstukjes2 = explode("/", $query_string_base64); $secstukjes3 = explode("/", $query_string1); //1 // splits de regel op in stukjes gedeeld door de / foreach($secstukjes1 as $seckey1 => $secstukje1) { // Als php tekens in voorkomen zoals ? = if (preg_match($regex1, $secstukje1)) { // Als die niet aan het patroon ?C=D;O=A voldoen if (!preg_match($regex2, $secstukje1)) { // redirect dan naar index header( 'refresh: 0; url='.$abspad); die(); } } } //2 foreach($secstukjes2 as $seckey2 => $secstukje2) { // Als php tekens in voorkomen zoals ? = if (preg_match($regex1, $secstukje2)) { // Als die niet aan het patroon ?C=D;O=A voldoen if (!preg_match($regex2, $secstukje2)) { // redirect dan naar index header( 'refresh: 0; url='.$abspad); die(); } } } //3 foreach($secstukjes3 as $seckey3 => $secstukje3) { // Als php tekens in voorkomen zoals ? = if (preg_match($regex1, $secstukje3)) { // Als die niet aan het patroon ?C=D;O=A voldoen if (!preg_match($regex2, $secstukje3)) { // redirect dan naar index header( 'refresh: 0; url='.$abspad); die(); } } } } /*____________________________________________________________________________________________________________*/ /*______________________________________HTML pagina ip geblokkeerd____________________________________________*/ // En nog een hele eer voor een hacker dat we nog zo'n mooie pagina maken voor hem. function accessdenied($rede='') { echo ' Access Denied ! '.$rede.'

Access Denied ! '.$rede.'



Especially for you we are pulling the plug !

Your ip is registered as an hackers ip ! Try your luck somewhere else !

'; } /*____________________________________________________________________________________________________________*/ /*_________________________________________Ip adres blokkeren________________________________________________*/ function blockip($rede) { global $prefix, $blockip, $abspad, $adminmail, $emailbyblockip, $sitenaam, $ip, $nu, $browser, $locatie; // De hacker code wordt ook in de database gedaan maar wel gecodeerd anders kan hij alsnog invloed hebben $badstring = base64_encode($locatie); // toevoegen bij Invallig request method: $_SERVER["REQUEST_METHOD"] // mail naar admin als je dat hebt opgegeven via beheer > algemene instellingen /* Gebruik bij de mail functie altijd "" en niet '' . Dit voorkomt een hoop ellende ! */ if ($emailbyblockip == 1) { $subject = "Bericht van je website $sitenaam - ip geblokkeerd"; $message = ""; $message .= "Dit is een automatisch bericht van je website: $sitenaam. Het volgende ip is geblokeerd: $ip\n\nRede: $rede\n\n"; $message .= "Einde bericht\n\n"; $headers = "From: $sitenaam <$adminmail>\nReply-To: $adminmail\nMIME-Version: 1.0\nContent-Type: text/plain; format=flowed; charset=\"UTF-8\"; reply-type=original\nX-Priority: 3\nX-Mailer: PHP/" . phpversion(); mail($adminmail, $subject, $message, $headers); } if ($blockip == 0) { $sql = sprintf("INSERT INTO ".$prefix."_sec_blockedip VALUES ('%s', %d, '%s', '%s', '%s')", $ip, $nu, mysql_real_escape_string($browser), mysql_real_escape_string($rede), mysql_real_escape_string($badstring)); mysql_query("SET CHARACTER SET UTF8"); mysql_query($sql); accessdenied($rede); die(); } else { // redirect naar index header( 'refresh: 3; url='.$abspad); accessdenied(); die(); } } /*___________________________________________________________________________________________________________*/ ?>