LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2016, 12:49 PM   #1
pittendrigh
Member
 
Registered: Jun 2014
Posts: 32

Rep: Reputation: Disabled
Email form -- secure or not?


I have a CentOS virtual dedicated server with a half a dozen websites. Only one of which has had an email form so visitors can send me email. I thought I did what was needed to keep bots form exploiting the form. Among other things this (php) email form would exit if any newlines or carriage returns were found in the POST widget for the From address.


But I recently started to get email like the following, which is a strange mixture of valid ascii and gibberish:

mailTo: plkQrWAQiNJ
anXfY0 <a href="http://kehxmcnnvkra.com/">kehxmcnnvkra</a>,
cqggnpeutoir,
[link=http://ltrggpuqdlks.com/]ltrggpuqdlks[/link],
http://upjonkwnbyqs.com/


I replaced the form with codes that simply display a jpeg image of my email address and the gibberish email stopped. So the above seems to be the result of hacker attempts to exploit my form. Did they succeed? Why does the above email header like text include gibberish and well formated ascii?

What follows was my meagre attempt at a secure email form:

<?php ......

function exitOnSuspicious() {
$flag=0;

if (strlen($_POST['message']) > 1024)
exit;

if ($_SESSION['spam'] != 'didUseForm')
exit;

if (strlen($_POST['toName']) > 32 || strstr($_POST['toName'], '\n') || strstr($_POST['toName'], '\r'))
exit;

if (strlen($_POST['fromname']) > 32 || strstr($_POST['fromname'], '\n') || strstr($_POST['fromname'], '\r'))
exit;

// the following--an @ in the toName--is not what could from the mkToSelect function,
// which suggests a hackign attempt.
//
if (@preg_match_all('@', $_POST['toName']) > 1)
exit;

if (strstr($_POST['message'], 'href=') || strstr($_POST['message'], 'url=') || strstr($_POST['message'], 'link='))
$flag=1;

if($flag == 1)
{
header("location: http://nsa.gov");
}

exit;
}
 
Old 01-20-2016, 09:01 AM   #2
teapottwo
Member
 
Registered: Sep 2013
Posts: 52

Rep: Reputation: Disabled
If its a feedback form, why are you letting them fill in the To field. You don't even need to show them your email address in this situation.

Here's some built in filters for PHP: http://php.net/manual/en/filter.examples.validation.php

Yes some stuff will still get through and other won't, but its a lot better than the rules you have!
This is easier to find than the rfc, https://en.wikipedia.org/wiki/Email_address#Syntax
 
Old 01-20-2016, 09:22 AM   #3
pittendrigh
Member
 
Registered: Jun 2014
Posts: 32

Original Poster
Rep: Reputation: Disabled
I allowed them to choose the To: field from a dropdown because......at one time this was on an academic site where the mail might have gone in several directions. And if the incoming name wasn't in a hard-coded list the code did exit.


But that does make it weaker. You are right. Thanks. Makes sense. Good links.

Glad I posted this.

Last edited by pittendrigh; 01-20-2016 at 09:52 AM.
 
Old 01-20-2016, 10:23 AM   #4
teapottwo
Member
 
Registered: Sep 2013
Posts: 52

Rep: Reputation: Disabled
The list is ok if you check for a match within the list from PHP before sending.


The list in the form itself can be bypassed.
 
Old 01-20-2016, 02:41 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,642
Blog Entries: 4

Rep: Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933Reputation: 3933
"Bots" are a scourge, but a simple "captcha" usually stops them cold.
 
Old 01-20-2016, 03:20 PM   #6
teapottwo
Member
 
Registered: Sep 2013
Posts: 52

Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
"Bots" are a scourge, but a simple "captcha" usually stops them cold.
Not long ago I tried to register at another more specific linux forum, their CSS was messed up so I couldn't see their special CAPTCHA correctly, however I could see that it was simply a choice from 4 images, it didn't take long before the first option was correct.

Moral: limit attempts within time period for IP.
 
Old 01-20-2016, 11:58 PM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
Yeah, I use recaptcha.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Turnbull: Don't assume government email is more secure than private email LXer Syndicated Linux News 0 10-10-2015 02:01 PM
Command based email client to send email through secure smtp havolinec Linux - Newbie 2 07-27-2010 07:40 AM
how can I secure my nis server ?can I use openSSL to secure it form sniffing ? abhi_raj Linux - Networking 1 07-10-2006 06:19 AM
Secure email (SSL vs. secure authentication) jrdioko Linux - Newbie 2 11-28-2004 01:39 PM
Form info to the db and then to my email Kuri Programming 0 04-25-2004 11:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration