NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP/MySQL Injection

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-03-2005, 05:37 PM THREAD STARTER               #1 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



PHP/MySQL Injection


Hello,

Please share which method you use, and why you think its better than another to prevent possible form attacks in php/mysql?

Personally, I'd use some filter to ban SQL commands found within the input. Or just check every string/number that comes out from GET/POST and contains any unexpected data.

share yours now,

--Thanks for sharing.
Porte is offline  
Old 07-03-2005, 06:46 PM   #2 (permalink)
Senior Member
 
majinbuu1023's Avatar
Join Date: Jan 2005
Location: New Zealand
Posts: 3,747
majinbuu1023 is a splendid one to beholdmajinbuu1023 is a splendid one to beholdmajinbuu1023 is a splendid one to beholdmajinbuu1023 is a splendid one to beholdmajinbuu1023 is a splendid one to beholdmajinbuu1023 is a splendid one to beholdmajinbuu1023 is a splendid one to beholdmajinbuu1023 is a splendid one to behold
 



put this on your site
Code:
if attack our php/mySQL we will sue you
Cheers
majinbuu1023 is offline  
Old 07-03-2005, 08:04 PM THREAD STARTER               #3 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Crackers do not care what you put on your site lol that would turn them on.
Porte is offline  
Old 07-03-2005, 11:01 PM   #4 (permalink)
Account Suspended
Join Date: Jul 2005
Posts: 172
Virtua is an unknown quantity at this point
 



just run anti-flodder in your server, and anit-ddos ... + try to get the highest security in files of php and mysql database !! Dont make it like phpBB the easiest hacked forum

Thanks
Virtua
Virtua is offline  
Old 07-04-2005, 02:33 AM   #5 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Make sure you always addslashes doing htmlentities and things like that.
liam_d is offline  
Old 07-04-2005, 03:25 AM   #6 (permalink)
NamePros Regular
Join Date: Mar 2004
Posts: 633
theparrot is a jewel in the roughtheparrot is a jewel in the roughtheparrot is a jewel in the rough
 



Originally Posted by liam_d
Make sure you always addslashes doing htmlentities and things like that.

????: NamePros.com http://www.namepros.com/programming/103873-php-mysql-injection.html
Don't use addslashes, that is actually a bad function, no idea why they have it.

Use mysql_real_escape_string and things like that instead.

Also be sure to have register globals off, and check/converty them as needed from _GET and _POST variables etc.
__________________
Need a break? Check out TheDamnBlog.com
Free $6.95 directi accounts at Directi Name Bin
Instant free $8.95 eNom accounts at Dncube.com
theparrot is offline  
Old 07-04-2005, 03:27 AM   #7 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




why is it a bad function, it stops errors when inserting and helps against sqli.

but then you are right use mysql_real_escape_string
liam_d is offline  
Old 07-04-2005, 03:37 AM   #8 (permalink)
NamePros Regular
Join Date: Mar 2004
Posts: 633
theparrot is a jewel in the roughtheparrot is a jewel in the roughtheparrot is a jewel in the rough
 



Originally Posted by liam_d
why is it a bad function, it stops errors when inserting and helps against sqli.
????: NamePros.com http://www.namepros.com/showthread.php?t=103873

but then you are right use mysql_real_escape_string
because it is never the right solution, you are escaping the string for use with programs and/or standards that have different rules, addslashes will fail in special cases with almost all of them, yet it is used a lot since it is there and seems the easy one to remember for all. It would be best if it was gone, people would use urlencode, mysql_escape, dbx_escape, phsql_escape etc as they should.
__________________
Need a break? Check out TheDamnBlog.com
Free $6.95 directi accounts at Directi Name Bin
Instant free $8.95 eNom accounts at Dncube.com
theparrot is offline  
Old 07-04-2005, 06:10 AM THREAD STARTER               #9 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Guys remember, if the magic_quotes_gpc is turned On in the php.ini file of the server, it will automatically run addslashes() , so if we used addslashes while this function is on, It will escape the string twice...err It always good If you insist about using it to do:

if (!get_magic_quotes_gpc()) {
????: NamePros.com http://www.namepros.com/showthread.php?t=103873
addslahes($var);
}

Just you need to check if magic quotes are on or off on the server. Basically, if its on , it will run addslashes...and I think its a good option.

I agree with you about mysql_real_escape_string though, it seems to be the better so far. But any more functions we could use before this even? just to increase security..

I have came up with something, and I need your opinions on it, its that i'll run checks on every input which i expect a string from and validate it against a banned array of words and characters , and if any found, it will just exit the program and return error.
Do you think it'll be effective/increasing security?

I understand that it will prevent some input like ' " , but assuming that your system doesn't require any single / double quotes.

Just sharing..
Thanks for the ideas so far
__________________
WP Theme Developer
Your One-stop for Premium Magazine/CMS WordPress Themes
Deluxe Themes
Porte is offline  
Old 07-04-2005, 05:09 PM THREAD STARTER               #10 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



Originally Posted by Virtua
just run anti-flodder in your server, and anit-ddos ... + try to get the highest security in files of php and mysql database !! Dont make it like phpBB the easiest hacked forum

Thanks
Virtua
I am only taking a shared host on the server ~ when you code then, you have to consider that settings in the php.ini file are either on or off.

And that's different to DDOS attacks to a server. I'm speaking about cracking into SQL and changing SQL querying then gaining permissions to delete/read/modify stuff from your database.

I do not think that phpBB is that easy for crackers ~ but every system is not 100% secure, we do increase security ~ but we do not prevent cracking.
????: NamePros.com http://www.namepros.com/showthread.php?t=103873

Thanks for your input
__________________
WP Theme Developer
Your One-stop for Premium Magazine/CMS WordPress Themes
Deluxe Themes
Porte is offline  
Old 07-11-2005, 03:53 AM   #11 (permalink)
NamePros Member
Join Date: Oct 2003
Posts: 126
i386 is an unknown quantity at this point
 



If you want to set php.ini settings to something you want, just use ini_set().
i386 is offline  
Old 07-11-2005, 05:10 AM   #12 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
not everything can be set using ini_set() and some things can be changed but are pointless changing, for example you can change register_globals in versions lower than 4.2.3 but there is no point as it has already implemented BEFORE the script executes.
Peter is offline  
Old 07-11-2005, 05:11 AM   #13 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




I have been reading up http://uk.php.net/manual/en/function...ape-string.php.

Do you do it like this?

PHP Code:
mysql_query("insert into `blah` set `blah1` = " mysql_real_escape_string($_POST['blah']) . ""); 
Last edited by liam_d; 07-11-2005 at 05:15 AM.
liam_d is offline  
Old 07-11-2005, 05:15 AM   #14 (permalink)
Senior Member
 
pratiknaik's Avatar
Join Date: Feb 2005
Location: Lost somewhere in a stack of queues..
Posts: 1,200
pratiknaik is just really nicepratiknaik is just really nicepratiknaik is just really nicepratiknaik is just really nicepratiknaik is just really nicepratiknaik is just really nicepratiknaik is just really nicepratiknaik is just really nice
 



Installing mod_security would provide the solution at higher level and you won't need to bother about SQL Injection/XSS attacks in your code.

http://modsecurity.org/

Thanks,
Pratik
__________________
Ruby on Rails Developer - http://m.onkey.org
pratiknaik is offline  
Old 07-11-2005, 05:35 AM   #15 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Originally Posted by liam_d
I have been reading up http://uk.php.net/manual/en/function...ape-string.php.

Do you do it like this?

PHP Code:
mysql_query("insert into `blah` set `blah1` = " mysql_real_escape_string($_POST['blah']) . ""); 
yes that is correct you sould still use ` around the variable like:-
????: NamePros.com http://www.namepros.com/showthread.php?t=103873


PHP Code:
mysql_query("insert into `blah` set `blah1` = `" mysql_real_escape_string($_POST['blah']) . "`"); 
with your example if you do not have anything after the mysql_real_escape_string($_POST['blah']) there is no need to have . "" its just making extra work for yourself.
Peter is offline  
Old 07-11-2005, 01:08 PM THREAD STARTER               #16 (permalink)
Senior Member
 
Porte's Avatar
Join Date: May 2005
Location: I'm right here
Posts: 3,526
Porte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud ofPorte has much to be proud of
 



I agree about the ini configuration thing, not everything you can change. Some things are disabled / enabled on host and you need to write your script considering both cases. Anyway, I think I'm still sticking to the first place form validation like banning these characters from any input at first glance such ' " ; - ( ) and tags, any special characters that can lead to breaking a sql query..and I do not know how much this can help me, but logically if PHP won't process the form until its cleaned from these characters then why use extra security measure, just sharing and I would like some notes on this.
__________________
WP Theme Developer
Your One-stop for Premium Magazine/CMS WordPress Themes
Deluxe Themes
Porte is offline  
Old 07-12-2005, 03:49 PM   #17 (permalink)
Account Closed
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

at top of your mysql enabled pages:

PHP Code:
$SQLInjectionRegex '/[\'")]* *[oO][rR] *.*(.)(.) *= *\\2(?:--)?\\1?/';
$sqlinjectattempt preg_grep($SQLInjectionRegex$_REQUEST);
????: NamePros.com http://www.namepros.com/showthread.php?t=103873
if(
$sqlinjectattempt==true)
{
    die(
"SQL injection attempt!");

Last edited by axilant; 07-12-2005 at 03:54 PM.
axilant is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Build your own php/mysql web database xacto Content For Sale 0 07-03-2005 08:47 AM
Help needed with personal project. PHP/MySql programming and layouts! QBert Website Development 3 11-09-2004 11:52 AM
$1,000-project in PHP/mySQL Artashes Web Development Wanted 1 09-29-2004 03:08 AM
Experienced php/mysql coder [FOR HIRE] Low prices! matrixnet For Sale / Advertising Board 0 04-12-2004 01:09 PM
[hiring] php/mysql website monitoring script armstrong Scripts For Sale 4 11-08-2003 11:10 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:07 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger