1

このスクリプトの目的は、404/500 などのサーバー エラーが発生した場合に、ログを Web マスターにメールで送信することです。

このスクリプトは、fwrite を使用してログをカウントし、10 個のログを保存して、10 個のログに達したらメールで送信します。一部の値と表示をエコー経由で使用しますが、XSS やその他のハッキング可能な問題がないことをどのように確認できますか。スクリプトが高度、効率的、またはきれいに書かれていない可能性があることはわかっていますが、うまくいきます。安全性だけが心配です。

.htaccess ファイル

ErrorDocument 400 /errors/error.php?err=400
ErrorDocument 401 /errors/error.php?err=401
ErrorDocument 403 /errors/error.php?err=403
ErrorDocument 404 /errors/error.php?err=404
ErrorDocument 500 /errors/error.php?err=500
ErrorDocument 410 /errors/error.php?err=410

php ファイル /errors/error.php

<?php

$fp = fopen("counterlog.txt", "r"); 
$count = fread($fp, 1024); 
fclose($fp); 


$errorNum = (int)$_GET['err'];
$err_str = array(404=>'Type of error: Not Found (404)', 400=>'Type of error: Bad Request (400)', 401=>'Type of error: Unauthorized (401)', 403=>'Type of error: Forbidden (403)', 410=>'Type of error: Gone (410)', 500=>'Type of error: Internal Server Error (500)');

$ip = getenv ("REMOTE_ADDR"); 
$requri = getenv ("REQUEST_URI"); 
$servname = getenv ("SERVER_NAME"); 
$combine = $ip . " tried to load " . $servname . $requri; 

$httpref = getenv ("HTTP_REFERER");

if (empty($httpref)) { 
 $httpref = "Unknown Location";
}

$httpagent = getenv ("HTTP_USER_AGENT");

$today = date("F j, Y, H:i:s"); 

$note = "This information has been sent to the webmaster." ;

$message = "On $today \n <br> $combine <br> \n User Agent = $httpagent \n <br>User got there from: $httpref <br><br> $err_str[$errorNum] <br><br> $note\n ";
$message2 = "#$count \n $today \n $combine \n User Agent = $httpagent \n User got there     from: $httpref \n $err_str[$errorNum] \n\n ";

$fh = fopen("errorlogje.txt", "a") or die("can't open file");
$stringData = $message2;
fwrite($fh, $stringData);
fclose($fh);

if ($count == 10) {
$count = 0;
$fh = fopen("errorlogje.txt", "r");
$bericht = fread($fh, 4096);
$to = "mail@mail.nl"; // webmaster email
$subject = "errorpage guardian has a message"; // email bericht
$from = "From: mailguardian@mail.nl\r\n";  // email afzender (makelijk voor het sorteren)
mail($to, $subject, $bericht, $from);

$fh = fopen("errorlogje.txt", "w");
fclose($fh);
}
else {
$count = $count + 1;
}

$fp = fopen("counterlog.txt", "w"); 
fwrite($fp, $count); 
fclose($fp); 

echo " $message ";

?>
4

1 に答える 1

1

完全に安全です、はい。使用している唯一の$_GET値は整数にキャストされるため、考えられる問題が排除されます。

于 2012-04-05T08:45:56.687 に答える