Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3076 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  Warning: mail() [function.mail]: Permission denied: headers injection

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Warning: mail() [function.mail]: Permission denied: headers injection

n°1953869
mufutah
Posté le 30-12-2009 à 10:12:32  profilanswer
 

Bjr,
Mon hebergeur à mis une sécurité et du coup, mon formulaire d'envoi de mail me renvoi cette erreur:
Warning: mail() [function.mail]: Permission denied: headers injection (empty line) in
 
Voila ce que mon hebergeur dit:
 
 

Citation :


 
Quelques sites ont été victimes d'une attaque distribuée visant à envoyer un mailing en masse de spam via des sites client.
 
En effet, des spammeurs ont répertorié toutes les pages ayant un formulaire de contact envoyant un email. Plusieurs sites hébergé chez nous et dans le monde ont donc été exploité de la même façon.
 
Ils se sont servis d'une faille existante dans beaucoup de formulaires de contact qui ne vérifient pas la présence de retour de ligne dans certains champs, en particulier celui de l'e-mail de l'expéditeur à compléter dans les formulaires.
 
Vous pouvez éviter que cela se produise, soit en désactivant le script PHP de contact e-mail de votre site, soit en vous assurant qu'il n'y a pas de retour de ligne dans chacun des champs du formulaire de contact de votre site.
 
Voici comment éviter simplement que ceci soit exploitable en remplaçant les retours de ligne dans chacun des champs devant normalement contenir un email (ce champ est souvent nommé $email, $sender ou $from):
 
$EMAIL = str_replace("\n", "", str_replace("\r", "", $EMAIL));
 
Le spammer exploite les scripts ressemblant à ceci
 
$MESSAGE = $_POST[msg];
$RECIPIENT = "webmaster@votredomaine.com";
$SUBJECT = "Formulaire de contact";
$EMAIL = $_POST[email];
 
// Sans cette ligne votre script est exploitable !!!!
$EMAIL = str_replace("\n", "", str_replace("\r", "", $EMAIL));
 
mail($RECIPIENT, $SUBJECT, $MESSAGE, "From: $EMAIL" );
 
 
Merci de bien vouloir vérifier ceci dans vos scripts PHP.  


 
mon script
 

Code :
  1. <? $module = $_POST['module'];
  2. $nom = $_POST['nom'];
  3. $prenom = $_POST['prenom'];
  4.  
  5. $dest="webmaster@domaine.com";
  6.  
  7. $reponse=StripSlashes("Votre demande d'inscription a été prise en compte. Nous vous recontacterons très prochainement" );
  8.  
  9. class Mail
  10. {
  11.  
  12.        var $sendto= array();
  13.        var $from, $msubject;
  14.        var $acc= array();
  15.        var $abcc= array();
  16.        var $aattach= array();
  17.        var $priorities= array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
  18.  
  19.  
  20. function Mail()
  21. {
  22.        $this->autoCheck(
  23.          true );
  24. }
  25.  
  26. function autoCheck( $bool )
  27. {
  28.        if( $bool )
  29.                $this->checkAddress = true;
  30.        else
  31.                $this->checkAddress = false;
  32. }
  33.  
  34.  
  35. function Subject( $subject )
  36. {
  37.        $this->msubject = strtr( $subject, "\r\n" , "  " );
  38. }
  39.  
  40. function From( $from )
  41. {
  42.  
  43.        if( ! is_string($from) ) {
  44.                echo "Class Mail: error, From is not a string";
  45.                exit;
  46.        }
  47.        $this->from= $from;
  48. }
  49. function To( $to )
  50. {
  51.  
  52.        if( is_array( $to ) )
  53.                $this->sendto= $to;
  54.        else
  55.                $this->sendto[] = $to;
  56.  
  57.        if( $this->checkAddress == true )
  58.                $this->CheckAdresses( $this->sendto );
  59.  
  60. }
  61. function Cc( $cc )
  62. {
  63.        if( is_array($cc) )
  64.                $this->acc= $cc;
  65.        else
  66.                $this->acc[]= $cc;
  67.  
  68.        if( $this->checkAddress == true )
  69.                $this->CheckAdresses( $this->acc );
  70.  
  71. }
  72. function Bcc( $bcc )
  73. {
  74.        if( is_array($bcc) ) {
  75.                $this->abcc = $bcc;
  76.        } else {
  77.                $this->abcc[]= $bcc;
  78.        }
  79.  
  80.        if( $this->checkAddress == true )
  81.                $this->CheckAdresses( $this->abcc );
  82. }
  83. function Body( $body )
  84. {
  85.        $this->body= $body;
  86. }
  87. function Send()
  88. {
  89.        $this->_build_headers();
  90.        if( sizeof( $this->aattach > 0 ) ) {
  91.                $this->_build_attachement();
  92.                $body = $this->fullBody . $this->attachment;
  93.        }
  94.        for( $i=0; $i< sizeof($this->sendto); $i++ ) {
  95.                $res = mail($this->sendto[$i], $this->msubject,$body, $this->headers);
  96.        }
  97.  
  98. }
  99.  
  100. function Organization( $org )
  101. {
  102.        if( trim( $org != "" )  )
  103.                $this->organization= $org;
  104. }
  105. function Priority( $priority )
  106. {
  107.  
  108.        if( ! intval( $priority ) )
  109.                return false;
  110.  
  111.        if( ! isset( $this->priorities[$priority-1]) )
  112.                return false;
  113.  
  114.        $this->priority= $this->priorities[$priority-1];
  115.  
  116.        return true;
  117.  
  118. }
  119. function Attach( $filename, $filetype='application/x-unknown-content-type', $disposition = "inline" )
  120. {
  121.        $this->aattach[] = $filename;
  122.        $this->actype[] = $filetype;
  123.        $this->adispo[] = $disposition;
  124. }
  125. function Get()
  126. {
  127.        $this->_build_headers();
  128.        if( sizeof( $this->aattach > 0 ) ) {
  129.                $this->_build_attachement();
  130.                $this->body= $this->body . $this->attachment;
  131.        }
  132.        $mail = $this->headers;
  133.        $mail .= "\n$this->body";
  134.        return $mail;
  135. }
  136. function ValidEmail($address)
  137. {
  138.        if( ereg( ".*<(.+)>", $address, $regs ) ) {
  139.                $address = $regs[1];
  140.        }
  141.         if(ereg( "^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)\$",$address) )
  142.                 return true;
  143.         else
  144.                 return false;
  145. }
  146.  
  147. function CheckAdresses( $aad )
  148. {
  149.        for($i=0;$i< sizeof( $aad); $i++ ) {
  150.                if( ! $this->ValidEmail( $aad[$i]) ) {
  151.                        echo "Class Mail, method Mail : invalid address $aad[$i]";
  152.                        exit;
  153.                }
  154.        }
  155. }
  156. function _build_headers()
  157. {
  158.  
  159.  
  160.        $this->headers= "From: $this->from\n";
  161.  
  162.        $this->to= implode( ", ", $this->sendto );
  163.  
  164.        if( count($this->acc) > 0 ) {
  165.                $this->cc= implode( ", ", $this->acc );
  166.                $this->headers .= "CC: $this->cc\n";
  167.        }
  168.  
  169.        if( count($this->abcc) > 0 ) {
  170.                $this->bcc= implode( ", ", $this->abcc );
  171.                $this->headers .= "BCC: $this->bcc\n";
  172.        }
  173.  
  174.        if( $this->organization != ""  )
  175.                $this->headers .= "Organization: $this->organization\n";
  176.  
  177.        if( $this->priority != "" )
  178.                $this->headers .= "X-Priority: $this->priority\n";
  179.  
  180. }
  181. function _build_attachement()
  182. {
  183.        $this->boundary= "------------" . md5( uniqid("myboundary" ) );
  184.  
  185.        $this->headers .= "MIME-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"$this->boundary\"\n\n";
  186.        $this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\nContent-Type: text/plain; charset=us-ascii\nContent-Transfer-Encoding: 7bit\n\n" . $this->body ."\n";
  187.        $sep= chr(13) . chr(10);
  188.  
  189.        $ata= array();
  190.        $k=0;
  191.        for( $i=0; $i < sizeof( $this->aattach); $i++ ) {
  192.  
  193.                $filename = $this->aattach[$i];
  194.                $basename = basename($filename);
  195.                $ctype = $this->actype[$i];    
  196.                $disposition = $this->adispo[$i];
  197.  
  198.                if( ! file_exists( $filename) ) {
  199.                        echo "Class Mail, method attach : file $filename can't be found"; exit;
  200.                }
  201.                $subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n  filename=\"$basename\"\n";
  202.                $ata[$k++] = $subhdr;
  203.                $linesz= filesize( $filename)+1;
  204.                $fp= fopen( $filename, 'r' );
  205.                $data= base64_encode(fread( $fp, $linesz));
  206.                fclose($fp);
  207.                $ata[$k++] = chunk_split( $data );
  208.        }
  209.        $this->attachment= implode($sep, $ata);
  210. }
  211.  
  212.  
  213. }
  214. $msg  =null;
  215.     $msg .="-----  FORMULAIRE D INSCRIPTION -------\n";
  216.     $msg .="\nNom : ".$nom."\n";
  217.     $msg .="\nPrenom : ".$prenom."\n";
  218.     $msg .="----- FIN FORMULAIRE D INSCRIPTION -------\n";
  219. $subject=StripSlashes($subject);
  220. $msg=StripSlashes($msg);
  221. $msg="Message depuis votre site web:
  222. $msg";
  223. $m= new Mail;
  224.        $m->From( "$email" );
  225.        $m->To( "$dest" );    
  226.        $m->Subject( "$subject" );
  227.        $m->Body( $msg);  
  228. if ($email1!="" ) {
  229.        $m->Cc( "$email1" );
  230.     }
  231.        $m->Priority($priority) ;  
  232. if ("$NomFichier_name"!="" ) {
  233.     copy("$NomFichier","../upload/$NomFichier_name" );
  234.     $m->Attach( "../upload/$NomFichier_name", "application/octet-stream" );
  235.     }
  236.        $m->Send();
  237. if ("$NomFichier_name"!="" ) {
  238. Unlink("../upload/$NomFichier_name" );   }    
  239. echo "$reponse";
  240. ?>


 
Merci de m'aider
 
 
 [cpp][/cpp]

mood
Publicité
Posté le 30-12-2009 à 10:12:32  profilanswer
 

n°1953877
mufutah
Posté le 30-12-2009 à 10:30:43  profilanswer
 

l'erreur se trouve à la ligne 95
 
$res = mail($this->sendto[$i], $this->msubject,$body, $this->headers);
 
Merci de m'aider

n°1953885
pataluc
Posté le 30-12-2009 à 10:45:43  profilanswer
 

t'as lu le mail de ton hébergeur? il te dit ce qu'il faut faire. tu rajoute la ligne suivante juste avant la ligne 95:

Code :
  1. $mail = str_replace("\n", "", str_replace("\r", "", $this->sendto[$i]));

et tu remplaces $this->sendto[$i] par $mail dans la ligne 95.

n°1953908
mufutah
Posté le 30-12-2009 à 11:53:29  profilanswer
 

Code :
  1. for( $i=0; $i< sizeof($this->sendto); $i++ ) {
  2. $mail = str_replace("\n", "", str_replace("\r", "", $this->sendto[$i]));
  3. $res = mail($mail, $this->msubject,$body, $this->headers);


Cela ne résout pas mon problème
Toujours le même message d'erreur.

n°1953914
tomsoft
Posté le 30-12-2009 à 12:05:21  profilanswer
 

.

Message cité 1 fois
Message édité par tomsoft le 30-12-2009 à 12:40:26
n°1953930
pataluc
Posté le 30-12-2009 à 12:23:44  profilanswer
 


mouais enfin on lui a demandé de créer un nouveau topic... :jap:

Message cité 1 fois
Message édité par pataluc le 30-12-2009 à 12:24:22
n°1953934
mufutah
Posté le 30-12-2009 à 12:28:12  profilanswer
 

:jap: Merci pour votre indulgence

n°1953941
tomsoft
Posté le 30-12-2009 à 12:38:30  profilanswer
 

pataluc a écrit :


mouais enfin on lui a demandé de créer un nouveau topic... :jap:


 
autant pour moi :jap: j'ai juste lu le reste, et tiré des conclusions trop rapides :jap:


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  Warning: mail() [function.mail]: Permission denied: headers injection

 

Sujets relatifs
Wanewsletter, mail envoyé mais jamais recu Warning: mysql_num_rows() expects parameter 1 to be resource
Protection contre injection HTMLExcel: création mail automatique
Message d'alerte lors de l'envoi d'un mailPEAR Mail et PHP 5.3.0
Cannot modify header information - headers already sent by[wxWidgets] La macro WXDLL_ENTRY_FUNCTION
mail() qui bloque à cause de sendmailbatch sftp pour recuperer fichier et envoi mail
Plus de sujets relatifs à : Warning: mail() [function.mail]: Permission denied: headers injection


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR