Accueil
Fermer

Publicité

Nos liens web
Les liens utiles
Publicité
Joomla! Script Sentinelle - La procédure PDF Imprimer Envoyer
Écrit par Thor   
Index de l'article
Joomla! Script Sentinelle
La procédure
Toutes les pages
  • Créer le fichier block.php (chmod 444) et copier ce contenu :

<?php

//Script actualisé en version 1.03

// recupèration de l''ip
function get_ip(){
if(isset(
$_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];}
elseif(isset(
$_SERVER['HTTP_CLIENT_IP'])){
$ip = $_SERVER['HTTP_CLIENT_IP''];}
else {
$ip = $_SERVER['REMOTE_ADDR'];}
return
$ip;
}


// la condition en méthode $_GET
$url = $_SERVER["REQUEST_URI"];

if (
(preg_match("#<[^>]*\w*\"?[^>]*>#is",$url)) ||
(
preg_match("#\Wcmd=?\b#is,$url)) ||
(
preg_match("#execu?\\b#is",$url)) ||
(
preg_match("#[\d\W](union|insert|from|where|concat|into|cast)[\d\W]#is",$url)) ||
(
preg_match("#http:\/\/.*#is",$url)) ||
(
preg_match("#https:\/\/.*#is",$url)) ||
(
preg_match("#\.\/#i",$url)))

// l'instruction qui sera executée
{
$mail_perso = " Cette adresse email est protégée contre les robots des spammeurs, vous devez activer Javascript pour la voir. "; // votre mail
$mailheaders .= "From: ".$mail_perso . "\r\n";
// $mailheaders .= "Bcc: ".$mail_perso. "\r\n"; // pour copie cachée
$banip = get_ip();
$msg = "Une tentative de hacking commise sur ".$_SERVER['HTTP_HOST'].
" par ".$banip." en appelant ".$_SERVER['REQUEST_URI']."\n\n";
$msg .= "HTTP_SERVER_VARS:\n\n";
$msg .= "HTTP_HOST_NAME => ".gethostbyaddr($banip)."\n\n";
while (list (
$key, $val) = each ($_SERVER)) $msg .= "$key => $val\n";
$msg = addslashes($msg);
eval(
"\$msg = \"$msg\";");
$msg = stripslashes($msg);

$fichier = "ban.txt";
$variable=0;
$ipArray = preg_replace("#\r\n?|\n#","",file($fichier));

foreach (
$ipArray as $ipTest) {
if (
$banip==$ipTest){$variable++;}
}
// enregistrement des IP sur fichier
if ($variable == 0) {
$fp = fopen($fichier, "a");
fputs ($fp, "$banip\n");
fclose($fp);
}

// envoi du mail vers l''admin
@mail($mail_perso,'HACKING TENTATIVE'.$banip,$msg,$mailheaders);
$iphack = "http://www.who.is/whois-ip/ip-address/".$banip."";
die(
'<html><head><title>Stop Hacking</title><SCRIPT language="Javascript">
alert("Sentinelle Protection Message:\n\nUnauthorized request your IP have been banned!
\nRequête interdite, votre IP a été bannie!! ");</SCRIPT><style type="text/css">
<!--.Style1 {color: #FFFFFF}--></style></head><body style=margin:0px;>
<div align="center" style="background-color:#000000;"><br /><br /><font size="+6"><b>
<span class="Style1">Stop hacking!</span></b></font><br /><br />
<img src="http://votre-site.com/votre-image.gif" border="0"><br /><br /><br /><br />
<iframe width=100% height=300 frameborder=0 src="'
.$iphack.'"></iframe></div></body></html>');
}

// protection des formulaires
foreach ($_POST as $check_form) {
if (
(preg_match("#<[^>]*script*\"?[^>]*>#is", $check_form)) ||
(
preg_match("#<[^>]*object*\"?[^>]*>#is", $check_form)) ||
(
preg_match("#<[^>]*iframe*\"?[^>]*>#is", $check_form)) ||
(
preg_match("#<[^>]*applet*\"?[^>]*>#is", $check_form)) ||
(
preg_match("#<[^>]*body*\"?[^>]*>#is", $check_form)
&&
!preg_match("#<[^>]*tbody*\"?[^>]*>#is", $check_form)) ||
(
preg_match("#<[^>]*onmouseover*\"?[^>]*#is", $check_form)) ||
(
preg_match("#<[^>]*img*\"?[^>]*#is", $check_form)) ||
(
preg_match("#<[^>]*meta*\"?[^>]*>#is", $check_form)) ||
(
preg_match("#<[^>]*style*\"?[^>]*>#is", $check_form)))

{
$banip = get_ip();
$fichier = "ban.txt";
$variable=0;
$ipArray = preg_replace("#\r\n?|\n#","",file($fichier));

foreach (
$ipArray as $ipTest) {
if (
$banip==$ipTest){$variable++;}
}
if (
$variable == 0) {
$fp = fopen($fichier, "a");
fputs ($fp, "$banip\n");
fclose($fp);
}
$iphack = "http://www.who.is/whois-ip/ip-address/".$banip."";
die(
'<html><head><title>Stop Hacking</title><SCRIPT language="Javascript">
alert("Sentinelle Protection Message:\n\nUnauthorized request your IP have been banned!
\nRequête interdite, votre IP a été bannie!! ");</SCRIPT><style type="text/css">
<!--.Style1 {color: #FFFFFF}--></style></head><body style=margin:0px;>
<div align="center" style="background-color:#000000;"><br /><br /><font size="+6"><b>
<span class="Style1">Stop hacking!</span></b></font><br /><br />
<img src="http://votre-site.com/votre-image.gif" border="0"><br /><br /><br /><br />
<iframe width=100% height=300 frameborder=0 src="'
.$iphack.'"></iframe></div></body></html>');

}
}
unset(
$check_form);
?>

  • Editez votre fichier index.php; ajoutez la ligne ci-dessous et enregistrez .

    require_once ( dirname(__FILE__).'block.php' );
    require_once ( dirname(__FILE__).'ban.php' );

 

  • Créer et Placer à l'endroit détreminé sur votre site votre votre-image.gif.(par défaut racine du site)
  • Créer et placer à la racine de votre site le fichier ban.txt (chmod 644) (une IP par ligne , ou vierge si vous n''avez pas de bannis).
  • Créer votre fichier ban.php

Ajouter ce code et enregistrez :

<?php

$ip = $_SERVER[''REMOTE_ADDR''];
$ipArray = preg_replace("#\r\n?|\n#","",file(''/chemin/absolu/du/fichier/ban.txt''));

foreach ($ipArray as $ipTest) {
if (
substr_count($ip, $ipTest) != "0") {
header(''location: /banned.htm''); // page de ban renvoyée
die();

}

}

?>

Note: Pour inserer ce script dans un forum cherchez la fonction session_start(); et placez le code ci-dessus (sans les balises php) en dessous donc il ne sera pas nécéssaire de créer le fichier ban.php ni en faire référence dans votre index.php.
Un exemple du script adapté pour notre forum smf (voir sujet).

  • Pour finir créer votre page de redirection (Ban ou Avertissement) banned.htm à la racine de votre site exemple en htm .

voir aussi Plugin Sentinelle pour Joomla!



 
Powerd by Web-Infoservice
rentabilisez votre site aujourd'hui !
XHTML Validation
CSS Validation
Flux Rss