1

私はインターネット上で開発したphpプログラムを持っています。これまでのところ、共有ホスティング パッケージを使用してきました。vps (apache2 suse 9.1 plesk) に移動するまで、すべてが機能していました。特定の php 関数がアクティブ化されていないことがわかりました。私はインターネットを利用することで、それらのほとんどを解決しました。

私の主な問題は、fpdf で PDF を電子メールで送信することです。すなわち

<?php
// download fpdf class (http://fpdf.org)
require("fpdf.php");

// fpdf object
$pdf = new FPDF();

// generate a simple PDF (for more info, see http://fpdf.org/en/tutorial/)
$pdf->AddPage();
$pdf->SetFont("Arial","B",14);
$pdf->Cell(40,10, "this is a pdf example");

// email stuff (change data below)
$to = "steven@siteaddress.co.uk"; 
$from = "me@domain.com"; 
$subject = "send email with pdf attachment"; 
$message = "<p>Please see the attachment.</p>";

// a random hash will be necessary to send mixed content
$separator = md5(time());

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
$filename = "example.pdf";

// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));


// main header (multipart mandatory)
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol; 
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;

// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;

// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";

// send message
//mail($to, $subject, "", $headers);
if (@mail($to, $subject, "",$headers)) {  
 echo('<p>Mail sent successfully.</p>');  
} else {  
 echo('<p>Mail could not be sent.</p>');  
}  

?>

上記のファイルは共有ホスティングで機能しますが、vps から送信すると、ファイルからこのエラー メッセージが表示されます。

Mar 23 19:16:56 h1871885 suhosin[64630]: ALERT - mail() - double newline in headers, possible injection, mail dropped (attacker '86.137.40.199', file '/srv/www/vhosts/sitename.co.uk/httpdocs/main/email.php', line 111)

多くの試行錯誤の後、エラーはこの行からです

 if (@mail($to, $subject, "",$headers))

「」を削除すると、vps でメールが送信されますが、添付ファイルはありません。これは私の共有アカウントでも発生します。添付ファイルは、chars のホール ロードを含むメッセージで終了します。だから私は間違いなくそこにそれらが必要です。この問題を克服する方法を知っている人はいますか。

どうもありがとう

suhosin.ini を 0 に設定した後

Mar 23 20:52:48 h1871885 suhosin[60778]: ALERT - mail() - double newline in headers, possible injection, mail dropped (attacker '86.137.40.199', file '/srv/www/vhosts/sitename.co.uk/httpdocs/main/email1.php', line 56)
4

1 に答える 1

1

あなたはあなた.$eol.$eol$headers. しかし、RFC2822を十分に調べて、メッセージの書式設定で空白行が必要な場所を正確に把握していると思います。そのため、リモートで悪用可能なインジェクションの脆弱性がないと確信していると仮定して、 suhosin の保護をオフにすることができます。mail()

于 2011-03-23T20:26:36.970 に答える