diff --git a/config/ecran_securite.php b/config/ecran_securite.php index 33b5e5bbc3be8e9378ac72d096888ac7cd3976ff..764f64c8eec72d3312744da7f20b7688abaa61a0 100644 --- a/config/ecran_securite.php +++ b/config/ecran_securite.php @@ -5,46 +5,19 @@ * ------------------ */ -define('_ECRAN_SECURITE', '0.7'); // 5 aout 2009 +define('_ECRAN_SECURITE', '0.8'); // 8 aout 2009 /* * Documentation : http://www.spip.net/fr_article4200.html * - * Ce petit script est inclus automatiquement par SPIP s'il est present - * dans le repertoire config/ ; il peut aussi etre inclus pour tous les - * codes php, avec la commande auto_prepend_file dans php.ini - * Il essaie de mettre un ecran devant certains des trous de - * securite connus d'anciennes versions de SPIP (et qui ont ete bouches dans - * les versions officielles). - * - * Ce fichier ne se substitue pas a une veritable mise a niveau de votre - * version de SPIP, mais il peut permettre de bloquer certaines attaques en - * attendant une migration propre. - * - * Installation : - * - * trois possibilites : - * - * -- deposer le fichier ecran_securite.php dans le repertoire config/ ; - * - * -- dans php.ini : - * auto_prepend_file '/chemin/vers/ecran_securite.php' - * (exemple: /usr/share/php/ecran_securite/ecran_securite.php) - * - * -- dans httpd.conf : - * php_admin_value auto_prepend_file '/chemin/vers/ecran_securite.php' - * - * Le fichier ecran_securite.php sera charge a chaque "hit" sur le serveur. - * - * - * L'ecran de securite reagit aux reglages suivants : - * - * -- define('_ECRAN_SECURITE_LOAD', X); - * protection anti-bots quand la charge serveur excede X - * valeur par defaut : 4 ; desactiver : 0 - * */ +/* + * test utilisateur + */ +if (isset($_GET['test_ecran_securite'])) + $ecran_securite_raison = 'test '._ECRAN_SECURITE; + /* - interdit de passer une variable id_article (ou id_xxx) qui ne * soit pas numerique (ce qui bloque l'exploitation de divers trous @@ -88,11 +61,10 @@ if (preg_match(',^(.*/)?spip_acces_doc\.,', $REQUEST_URI)) { */ if (isset($_REQUEST['partie_cal']) AND $_REQUEST['partie_cal'] !== htmlentities($_REQUEST['partie_cal'])) - die("No thanks"); + $ecran_securite_raison = "partie_cal"; if (isset($_REQUEST['echelle']) AND $_REQUEST['echelle'] !== htmlentities($_REQUEST['echelle'])) - die("No thanks"); - + $ecran_securite_raison = "echelle"; /* - bloque les requetes contenant %00 (manipulation d'include) * @@ -101,19 +73,21 @@ if (strpos( @get_magic_quotes_gpc() ? stripslashes(serialize($_REQUEST)) : serialize($_REQUEST), chr(0) -) !== false) die(); +) !== false) + $ecran_securite_raison = "%00"; /* - bloque les requetes fond=formulaire_ * */ if (isset($_REQUEST['fond']) AND preg_match(',^formulaire_,i', $_REQUEST['fond'])) - die(); + $ecran_securite_raison = "fond=formulaire_"; /* - bloque les requetes du type ?GLOBALS[type_urls]=toto (bug vieux php) * */ -if (isset($_REQUEST['GLOBALS'])) die(); +if (isset($_REQUEST['GLOBALS'])) + $ecran_securite_raison = "GLOBALS[GLOBALS]"; /* - bloque les requetes des bots sur: * les agenda @@ -121,20 +95,18 @@ if (isset($_REQUEST['GLOBALS'])) die(); */ if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'bot') AND ( - (isset($_REQUEST['echelle']) AND isset($_REQUEST['partie_cal']) AND isset($_REQUEST['type'])) - OR (strpos($_SERVER['REQUEST_URI'],'debut_') AND preg_match(',[?&]debut_.*&debut_,', $_SERVER['REQUEST_URI'])) + (isset($_REQUEST['echelle']) AND isset($_REQUEST['partie_cal']) AND isset($_REQUEST['type'])) + OR (strpos($_SERVER['REQUEST_URI'],'debut_') AND preg_match(',[?&]debut_.*&debut_,', $_SERVER['REQUEST_URI'])) ) -) { - header('HTTP/1.1 403 Forbidden'); - die ("Accès robot agenda/double pagination refusé."); -} +) + $ecran_securite_raison = "robot agenda/double pagination"; /* * Bloque une vieille page de tests de CFG (<1.11) */ -if (isset($_REQUEST['page']) AND $_REQUEST['page']=='test_cfg') { - die(); -} +if (isset($_REQUEST['page']) AND $_REQUEST['page']=='test_cfg') + $ecran_securite_raison = "test_cfg"; + /* Parade antivirale contre un cheval de troie */ if(!function_exists('tmp_lkojfghx')){ @@ -146,23 +118,43 @@ function tmp_lkojfghx2($a=0,$b=0,$c=0,$d=0){ call_user_func($GLOBALS['tmp_xhgfjokl'],$a,$b,$c,$d); } } -if (isset($_POST['tmp_lkojfghx3'])){ die();} +if (isset($_POST['tmp_lkojfghx3'])) + $ecran_securite_raison = "gumblar"; /* * Outils XML mal securises < 2.0.9 */ if (isset($_REQUEST['transformer_xml'])) - die('transformer_xml interdit'); + $ecran_securite_raison = "transformer_xml"; /* * Sauvegarde mal securisee < 2.0.9 */ if (isset($_REQUEST['nom_sauvegarde']) AND strstr($_REQUEST['nom_sauvegarde'], '/')) - die('nom_sauvegarde manipulee'); + $ecran_securite_raison = 'nom_sauvegarde manipulee'; if (isset($_REQUEST['znom_sauvegarde']) AND strstr($_REQUEST['znom_sauvegarde'], '/')) - die('znom_sauvegarde manipulee'); + $ecran_securite_raison = 'znom_sauvegarde manipulee'; + + + +/* + * S'il y a une raison de mourir, mourons + */ +if (isset($ecran_securite_raison)) { + header("HTTP/1.0 403 Forbidden"); + header("Expires: 0"); + header("Cache-Control: no-cache, must-revalidate"); + header("Pragma: no-cache"); + header("Content-Type: text/html"); + die("<html><title>Error 403: Forbidden</title><body><h1>Error 503</h1><p>You are not authorized to view this page ($ecran_securite_raison)</p></body></html>"); +} +/* + * Fin securite + */ + + /* * Bloque les bots quand le load deborde @@ -172,17 +164,17 @@ if (!defined('_ECRAN_SECURITE_LOAD')) define('_ECRAN_SECURITE_LOAD', 4); if ( - defined('_ECRAN_SECURITE_LOAD') - AND _ECRAN_SECURITE_LOAD>0 - AND $_SERVER['REQUEST_METHOD'] === 'GET' - AND strpos($_SERVER['HTTP_USER_AGENT'], 'bot')!==FALSE - AND ( - (function_exists('sys_getloadavg') AND $load = array_shift(sys_getloadavg())) - OR (@is_readable('/proc/loadavg') AND $load = floatval(file_get_contents('/proc/loadavg'))) - ) - AND $load > _ECRAN_SECURITE_LOAD // eviter l'evaluation suivante si de toute facon le load est inferieur a la limite - AND rand(0, $load*$load) > _ECRAN_SECURITE_LOAD*_ECRAN_SECURITE_LOAD - ) { + defined('_ECRAN_SECURITE_LOAD') + AND _ECRAN_SECURITE_LOAD>0 + AND $_SERVER['REQUEST_METHOD'] === 'GET' + AND strpos($_SERVER['HTTP_USER_AGENT'], 'bot')!==FALSE + AND ( + (function_exists('sys_getloadavg') AND $load = array_shift(sys_getloadavg())) + OR (@is_readable('/proc/loadavg') AND $load = floatval(file_get_contents('/proc/loadavg'))) + ) + AND $load > _ECRAN_SECURITE_LOAD // eviter l'evaluation suivante si de toute facon le load est inferieur a la limite + AND rand(0, $load*$load) > _ECRAN_SECURITE_LOAD*_ECRAN_SECURITE_LOAD +) { header("HTTP/1.0 503 Service Unavailable"); header("Retry-After: 300"); header("Expires: 0"); @@ -193,3 +185,4 @@ if ( } +?>