473,796 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.co m' ;
$subject = "newsletter signup" ;

$formurl = "http://www.example.com/index.html" ;
$errorurl = "http://www.example.com/signuperror.htm l" ;
$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_REFER ER" );

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_quot es_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 1977
-----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.co m' ;
$subject = "newsletter signup" ;

$formurl = "http://www.example.com/index.html" ;
$errorurl = "http://www.example.com/signuperror.htm l" ;
$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_REFER ER" );

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_quot es_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)

iD8DBQFHKieokA9 dCbrNdDMRAkxRAK DKg/lgihg2TDL0jRzd7 A9PXA8ZrQCdHyjo
DR9g97F30LDbwK4 nhCAJ9aU=
=XDYz
-----END PGP SIGNATURE-----
Nov 1 '07 #2
DVH

"Brendan Gillatt" <br************ ***@brendanREMO VETHISgillatt.c o.ukwrote
in message news:fv******** *************@p ipex.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
3352
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 wondering if there's a way to customize it further, such that the hyperlink they are sent is the web address of the page the "send to friend" link was on. I don't want to convert my entire site over to .asp, so having a pop-up .asp page seems to make...
15
3319
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. <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function isPPC() { if (navigator.appVersion.indexOf("PPC") != -1) return true; else return false;
6
11194
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 will include the code I originally used. I understand I should switch from CDONTS to CDO mail but after several sttempts I am finding a very hard time getting the new CDO mail to work properly. Any assistance with this would be greatly...
1
2174
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
8798
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 with this code: MailMessage msgMail = new MailMessage(); msgMail.To = "test@address.com"; msgMail.From = "from@address.com"; msgMail.Subject = "Mail Example Subject";
11
22384
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. Are there any examples of using smtpd ? I'm not an expert,so I need some examples to learn how to use it. Or maybe there is a better way to to this?
2
22999
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 coming from the group mailbox I belong to. I haven't been able to find how to send a mail with a different address in the From but from the command line I can change the Reply-to (better than nothing). If I use the same in a script it doesn't...
5
3488
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() - after sending, a small summary html page is sent to the user with number sent, time taken and a simple navigation choice. Up to about 100 emails it all works fine - this takes the server about 27 secs . Any more than that and although the emails are...
2
1839
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 info and optionally can upload images, the user receives and email receipt of all the data they just submitted, and i'm suppose to receive their information in my email. what still works is that the user will receive their receipt and the images...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9535
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10465
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7558
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.