note 59640 added to ref.mail
| From: | appelattnr78dottnet at osu1 dot php dot net | Date: | Mon, 12 Dec 2005 10:38:23 +0000 |
| Subject: | note 59640 added to ref.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-99985@lists.php.net to get a copy of this message | ||
Another modest attempt at tackling those pesky mailheader injections. Works quite well for me as it
is, but i would appreciate any suggestions to improve it:
<?php
/* name: input_check_mailinj()
* sample usage: foreach($_POST as $value) input_check_mailinj($value);
*/
function input_check_mailinj($value)
{
# mail adress(ess) for reports...
$report_to = "abuse@yourdomain.com";
# array holding strings to check...
$suspicious_str = array
(
"content-type:"
,"charset="
,"mime-version:"
,"multipart/mixed"
,"bcc:"
);
// remove added slashes from $value...
$value = stripslashes($value);
foreach($suspicious_str as $suspect)
{
# checks if $value contains $suspect...
if(eregi($suspect, strtolower($value)))
{
$ip = (empty($_SERVER['REMOTE_ADDR'])) ? 'empty' :
$_SERVER['REMOTE_ADDR']; // replace this with your own get_ip function...
$rf = (empty($_SERVER['HTTP_REFERER'])) ? 'empty' :
$_SERVER['HTTP_REFERER'];
$ua = (empty($_SERVER['HTTP_USER_AGENT'])) ? 'empty' :
$_SERVER['HTTP_USER_AGENT'];
$ru = (empty($_SERVER['REQUEST_URI'])) ? 'empty' :
$_SERVER['REQUEST_URI'];
$rm = (empty($_SERVER['REQUEST_METHOD'])) ? 'empty' :
$_SERVER['REQUEST_METHOD'];
# if so, file a report...
if(isset($report_to) && !empty($report_to))
{
@mail
(
$report_to
,"[ABUSE] mailinjection @ " . $_SERVER['HTTP_HOST'] . "
by " . $ip
,"Stopped possible mail-injection @ " .
$_SERVER['HTTP_HOST'] . " by " . $ip . " (" . date('d/m/Y
H:i:s') . ")\r\n\r\n" .
"*** IP/HOST\r\n" . $ip . "\r\n\r\n" .
"*** USER AGENT\r\n" . $ua . "\r\n\r\n" .
"*** REFERER\r\n" . $rf . "\r\n\r\n" .
"*** REQUEST URI\r\n" . $ru . "\r\n\r\n" .
"*** REQUEST METHOD\r\n" . $rm . "\r\n\r\n" .
"*** SUSPECT\r\n--\r\n" . $value . "\r\n--"
);
}
# ... and kill the script.
die
(
'Script processing cancelled: string
(
<em>'.$value.'</em>) contains text portions that are ' .
'potentially harmful to this server. <em>Your input has not been
sent!</em> Please use your ' .
'browser\'s back-button to return to the previous page and
try refrasing your input.</p>'
);
}
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.mail.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59640
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59640&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59640&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59640&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59640&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59640&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59640&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59640&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59640&report=yes
Search -- http://master.php.net/manage/user-notes.php