Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-03-2006, 06:45 AM
Ani Ani is offline
WebProWorld New Member
 

Join Date: Aug 2003
Posts: 6
Ani RepRank 0
Default Php form gets submitted with invalid email-id

Hello,

I have a php form on http://www.wideinfotech.com/onlinecall.php3

Whenever someone fills up the form I get a mail with the fields that have been filled.

I started getting mails with junk characters like
onthefield@wideinfotech.com - filled up in all the fields. Then I kept a javascript code which doesnt allow to submit the form if there is 'wideinfotech.com' in the string, still I used to receive the mails with 'sometext@wideinfotech.com' filled up in all the fields. Right now I have disabled the form because of the same.

Kindly guide as to how can I control this.

regds
Ani
Reply With Quote
  #2 (permalink)  
Old 04-04-2006, 02:36 AM
WebProWorld Pro
 

Join Date: May 2004
Location: Austin, TX
Posts: 199
steve0 RepRank 0
Default

A really simple solution could be
in the very top of onlinecall.php3 add..

<? if (stristr($_POST[email],"wideinfotech")) die(); ?>
__________________
Hardcore Programming Solutions and Coffee Drinker
Reply With Quote
  #3 (permalink)  
Old 04-07-2006, 05:00 PM
southplatte's Avatar
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Colorado
Posts: 381
southplatte RepRank 1
Default

It sounds like a bot filling out the form. Do some validation on the data and you can kill all that is coming in like that.
Reply With Quote
  #4 (permalink)  
Old 04-07-2006, 07:24 PM
minorgod's Avatar
WebProWorld Member
 

Join Date: Jan 2005
Posts: 78
minorgod RepRank 0
Default

You should forget about JavaScript validation for this and do your validation in PHP instead. Whoever is submitting your form is submitting it via another script that bypasses your JavaScript validation. Usually, a simple referrer check is all you need to kill these bogus messages and you should be using a referrer check on any scripts on your server that are capable of sending mail. This will ensure that the form can only be submitted from your domain. You could do like I do and set a session variable with the current page info the first time you load the page and then do a check for that info when the form is submitted. If the page hasn't been loaded prior to the form being submitted, this info will not be available to your script and it will die. To do this you could put the following at the top of your script:



Code:
session_start();
$allowed_referrers[]=$_SERVER['PHP_SELF'];
Then wherever you call the mail() function, put this before the function call...
Code:
if(!in_array($_SESSION['referrer'],$allowed_referrers)){
		die("You have attempted to submit a message from somewhere outside our domain. Please don't do that.");
	}
//and at the bottom of your script, put this code:

Code:
$_SESSION['referrer']=$_SERVER['PHP_SELF'];
So that the last thing that will happen when the page is loaded is the session will save the name of your current script. It will then be avialable for your referrer check on the next page load.

I use an array to hold the referrer info so that I can set up mulitiple valid referrers by adding other pages to the array. If you don't like that you can always just store the value as a simple string and then use the regular string comparison operators and/or functions.

Also, this method it not TOTALLY foolproof, since session ids can be easily viewed by your user and then resubmitted with an automated request, which would circumvent this protection, but it might slow them down a bit. I'm not positive the code I posted is totally correct, but it should be pretty close to what you need. If not, a quick search for "php email referrer check" will pull up many other posts on the subject.
Reply With Quote
  #5 (permalink)  
Old 04-07-2006, 07:53 PM
WebProWorld Member
 

Join Date: Dec 2003
Location: US
Posts: 35
langard RepRank 0
Default

Here's and error loop to prevent it:

Code:
<?

$error = '';

// get all the email form data

$ems = '';

// stop email server hacks
$ems .= $message;
$ems .= $subject;
$ems .= $address;

if ( stristr( $ems, 'content-type:' ) ¦¦ stristr( $ems, 'multipart/mixed' ) ¦¦ stristr( $ems, 'boundary="' ) ¦¦ stristr( $ems, 'cc:' ) ¦¦ stristr( $ems, 'multi-part message in mime format' ) ¦¦ stristr( $ems, 'to:' ) ¦¦ eregi( "(%[a-f0-9])", $ems ) ¦¦ stristr( $ems, '0x' ))
// the last two are in case they try using hex or other non standard characters
{
$error .= "

Don't bother</p>";
}

if ( $error )
{
echo $error;
}
else
{
...... finish email sending 

?>
__________________
Champagne to real friends and real pain to sham friends.
Reply With Quote
  #6 (permalink)  
Old 04-07-2006, 08:02 PM
DrTandem1's Avatar
WebProWorld 1,000+ Club
 

Join Date: Oct 2003
Location: Encinitas, CA
Posts: 1,908
DrTandem1 RepRank 2
Default

Other things to keep in mind include naming the script file something that doesn't identify it as a mail script. For example, sendmail.php is a dead give away.

The script itself should strip tags and bar line feeds. What is probably happening to your site is it is being hijacked to launch spam. Typically, they use your domain name as the "from" address. So, yes, you want the script to die, if that is entered anywhere.

Besides annoying you, you don't want your site flagged as a source of spam.
__________________
DrTandem's San Diego Web Page Design, drtandem.com
Reply With Quote
  #7 (permalink)  
Old 04-08-2006, 05:09 AM
sands's Avatar
WebProWorld Veteran
 

Join Date: Sep 2005
Location: Kerala, India
Posts: 397
sands RepRank 1
Default

Firstly validate the form using PHP only. JavaScript is useless. Add this code for all the fields:
$name = $_POST['name'];
$email = $_POST['email'];
and
if (!isset($_POST['email'])) {
header( "Location: http://www.wideinfotech.com/onlinecall.php3" );
}
to make sure your script was called from your feedback form. If not the script redirects the visitor back to your feedback form.

For the Email field this code would also prove useful to prevent multiple mails.
if (eregi("\n",$_POST['email'])) {
return; }

I am no expert in PHP and would be grateful if anyone can pick out any mistakes.

langard's additional code suggestion is very good except that it would not work if the form has the provision for attachments.
__________________
My Nook | My Biz | My Photos
Reply With Quote
  #8 (permalink)  
Old 04-08-2006, 07:40 AM
WebProWorld New Member
 

Join Date: Nov 2004
Posts: 13
orko3001 RepRank 0
Default

I had the same problem but I just banned the ip address from the site useing IP Deny Manager (http://www.webmasterstop.com/109.html) in the Servers Cpanel (http://www.webmasterstop.com/64.html)

Haven't had any problem since
Reply With Quote
  #9 (permalink)  
Old 04-08-2006, 07:46 AM
WebProWorld New Member
 

Join Date: Nov 2004
Posts: 13
orko3001 RepRank 0
Default

I had the same problem but I just banned the ip address from the site useing IP Deny Manager (http://www.webmasterstop.com/109.html) in the Servers Cpanel (http://www.webmasterstop.com/64.html)

Haven't had any problem since
Reply With Quote
  #10 (permalink)  
Old 04-10-2006, 04:51 AM
WebProWorld Pro
 

Join Date: Feb 2004
Posts: 104
nelsonez RepRank 0
Default Spammers are probing your PHP code

DrTandem1 said: "What is probably happening to your site is it is being hijacked to launch spam. Typically, they use your domain name as the 'from' address. So, yes, you want the script to die, if that is entered anywhere."

I believe that is what is happening. We have seen this in attacks on perl scripts where a hacker was able to launch a series of commands into one of the fields on a web form that happened to be part of the email header (either a subject field or email field). The problem with the script was the client thought the on-page javascript would do all the field validation but as other posters have stated that can be easily circumvented by a hacker. The key is to make sure the PHP or Perl script has a maximum character limit set for each field in your form.

For example the text field where a user enters there email address on your form should have some reasonable maximum limit of characters, say for example 40 characters. And make sure this limit is checked by the PHP script. A on-page javascript or HTML maxlength value will not stop a hacker.

Also make sure there are validations in the script to do referrer checks and to check for meta characters.
__________________
Eric Nelson, Ph.D. <<SlickRockWeb>> Affordable SEO, Belize resort for sale or just take a Belize vacation.
Reply With Quote
  #11 (permalink)  
Old 04-10-2006, 04:56 AM
WebProWorld Pro
 

Join Date: Feb 2004
Posts: 104
nelsonez RepRank 0
Default Re: Spammers are probing your PHP code

One other thing. Don't get confident that just because you have a referrer check in place that you are safe.

Good hackers can easily fake referrers. I have never quite figured out how they do it some times but I have seen it in many a server log.

The character limit does severely limit what they can do and if you properly parse the data you can prevent them from trying to run non-intended PHP code.
__________________
Eric Nelson, Ph.D. <<SlickRockWeb>> Affordable SEO, Belize resort for sale or just take a Belize vacation.
Reply With Quote
  #12 (permalink)  
Old 04-11-2006, 04:29 AM
WebProWorld Member
 

Join Date: Dec 2003
Location: US
Posts: 35
langard RepRank 0
Default

Don't depend upon referers at all. The PHP manual warns not to in the $_SERVER[HTTP_REFERER] section, also. Referers are provided sometimes, sometimes not by the servers routing the HTTP requests. Most corporate servers, for instance, are behind firewalls and won't give you a referer.

Better ways to check. For instance, we disallow entire countries by IP address block for some of our sites.
__________________
Champagne to real friends and real pain to sham friends.
Reply With Quote
  #13 (permalink)  
Old 04-17-2006, 02:16 AM
Ani Ani is offline
WebProWorld New Member
 

Join Date: Aug 2003
Posts: 6
Ani RepRank 0
Default Tried with POST variables

Hello,

Thanks a lot all of you guys for your replies.
I tried out following _

if($REQUEST_METHOD=="POST")
{
$name = $_POST['name'];
$email = $_POST['email'];
if(!isset($name))
{
die ("Sorry could not send email, Please try after some time.");
}
}

But even after that I am still gettin the spam mails.

Hence I have now again disabled the form.
Kindly advise what else I can do.

regds
Anita
Reply With Quote
  #14 (permalink)  
Old 04-17-2006, 09:38 PM
sands's Avatar
WebProWorld Veteran
 

Join Date: Sep 2005
Location: Kerala, India
Posts: 397
sands RepRank 1
Default Re: Tried with POST variables

Quote:
Originally Posted by Ani
Hello,

Thanks a lot all of you guys for your replies.
I tried out following _

if(!isset($name))
{
die ("Sorry could not send email, Please try after some time.");
}

But even after that I am still gettin the spam mails.
It should be:
if (!isset($_POST['email'])) {

And also try limiting the characters allowed in the E-mail field using PHP as suggested by nelsonez.

This is the code:
if (strlen($email) > 40) {

Try it and see! All the best, cheerio!
__________________
My Nook | My Biz | My Photos
Reply With Quote
  #15 (permalink)  
Old 05-04-2006, 09:49 AM
darren13's Avatar
WebProWorld Pro
 

Join Date: Jul 2003
Location: UK
Posts: 214
darren13 RepRank 0
Default

Hi Sands,
Thanks for advice to check this thread, but I still haven't much of an idea on how to proceed. I use formmail.cgi (I think!) - would I be able to use that code in the formmail file?

Thanks in advance,

Darren.
Reply With Quote
  #16 (permalink)  
Old 05-04-2006, 10:41 AM
sands's Avatar
WebProWorld Veteran
 

Join Date: Sep 2005
Location: Kerala, India
Posts: 397
sands RepRank 1
Default

Quote:
Originally Posted by darren13
Thanks for advice to check this thread, but I still haven't much of an idea on how to proceed. I use formmail.cgi (I think!) - would I be able to use that code in the formmail file?
Hello Darren,
Sorry, I have no idea about CGI. Anyway none of the above measures are foolproof. There is a link that might prove useful for those using PHP.
http://www.alt-php-faq.org/local/115/
__________________
My Nook | My Biz | My Photos
Reply With Quote
  #17 (permalink)  
Old 05-09-2006, 10:45 AM
darren13's Avatar
WebProWorld Pro
 

Join Date: Jul 2003
Location: UK
Posts: 214
darren13 RepRank 0
Default

Okay,

Well thanks for trying anyway Sands, appreciated,

Darren.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0