473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Spamproofing a send mail script

DVH
Hi,

I've a script that sends mail from my site.

I've included a regexp which should return 403 forbidden if you try to
hijack it and send to another address.

How can I test to make sure it works? E.g. can I try to spoof it to send
mail to my other e-mail address?

Thanks for your help.

The script is:

<?php
$mailto = 'd**@example.com' ;
$subject = "newsletter signup" ;

$formurl = "http://www.example.com/index.html" ;
$errorurl = "http://www.example.com/signuperror.html" ;
$thankyouurl = "http://www.example.com/signed.html" ;

$uself = 0;

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}

if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

if (!eregi('^[-A-Za-z0-9_]+@(example.com)$', $mailto)) {
header('HTTP/1.0 403 Forbidden');
die('Access denied.');
}
$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" .
$headersep . "X-Mailer:

chfeedback.php 2.08" );
header( "Location: $thankyouurl" );
exit ;

?>
Nov 1 '07 #1
2 1960
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

DVH wrote:
Hi,

I've a script that sends mail from my site.

I've included a regexp which should return 403 forbidden if you try to
hijack it and send to another address.

How can I test to make sure it works? E.g. can I try to spoof it to send
mail to my other e-mail address?

Thanks for your help.

The script is:

<?php
$mailto = 'd**@example.com' ;
$subject = "newsletter signup" ;

$formurl = "http://www.example.com/index.html" ;
$errorurl = "http://www.example.com/signuperror.html" ;
$thankyouurl = "http://www.example.com/signed.html" ;

$uself = 0;

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}

if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

if (!eregi('^[-A-Za-z0-9_]+@(example.com)$', $mailto)) {
header('HTTP/1.0 403 Forbidden');
die('Access denied.');
}
$messageproper =

"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;

mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" .
$headersep . "X-Mailer:

chfeedback.php 2.08" );
header( "Location: $thankyouurl" );
exit ;

?>

You _must_ check for newlines in form to e-mail scripts. If not, a
malicious user can add their own headers.

- --
Brendan Gillatt
brendan {at} brendangillatt {dot} co {dot} uk
http://www.brendangillatt.co.uk
PGP Key: http://pgp.mit.edu:11371/pks/lookup?...rch=0xBACD7433
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFHKieokA9dCbrNdDMRAkxRAKDKg/lgihg2TDL0jRzd7A9PXA8ZrQCdHyjo
DR9g97F30LDbwK4nhCAJ9aU=
=XDYz
-----END PGP SIGNATURE-----
Nov 1 '07 #2
DVH

"Brendan Gillatt" <br***************@brendanREMOVETHISgillatt.co.ukw rote
in message news:fv*********************@pipex.net...
>>

You _must_ check for newlines in form to e-mail scripts. If not, a
malicious user can add their own headers.
Thanks Brendan.
Nov 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Erik T. Nomad | last post by:
I've created a link that will enable the reader of any page on my website to click it, enter an e-mail address, and have it arrive in that inbox with a hyperlink to the site. However, I'm...
15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
6
by: DigitalRick | last post by:
I have been running CDONTS in my ASPpages to send emails to me sent from my guestbook. It had been working fine untill I upgraded to Server 2003 (I am also running Exchange 2003) all locally. I...
1
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
5
by: Andreas | last post by:
I am working with three computers, my developing computer, a Web Server and a Mail Server (Exchange). I am trying to send a email from the Web Server via the Mail Server to a valid email address...
11
by: fdu.xiaojf | last post by:
Hi, I just want to send a very simple email from within python. I think the standard module of smtpd in python can do this, but I haven't found documents about how to use it after googleing....
2
krik
by: krik | last post by:
Hello, I would like to send a mail via a script with customized From field or at least with Reply-To. This email is sent by a monitoring server via a cron job and the users should see this mail as...
5
by: This | last post by:
I have a pretty basic emailing script that sends a relatively small number (150) of html emails. The emails are compiled, personalised from a mysql db subscribers list, and sent using mail() -...
2
chunk1978
by: chunk1978 | last post by:
i wrote a custom PHP script last year and everything worked perfectly... recently my webserver upgraded to PHP 5 and now my script doesn't work properly. what the script does is: users fill out...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.