NameSilo

How to fix SQL injection

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

awal

Established Member
Impact
41
Hello

I have PHP script but I found 18 SQL injection in one file only

How I fix this problems?

Thank you
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
use the function mysql_real_escape_string() around EVERY variable you pass into mysql_query(), especially if it's a user-input (like $_POST or $_GET)
 
1
Close
nasaboy007 said:
use the function mysql_real_escape_string() around EVERY variable you pass into mysql_query(), especially if it's a user-input (like $_POST or $_GET)

Please I need example:

I try with this one

PHP:
$rs_query=mysql_query("Select * from sbwmd_categories where id=" . $category );

I change it to:
PHP:
$rs_query=mysql_query("Select * from sbwmd_categories where id=" . mysql_real_escape_string($category) );

but still not wroking

Thank you
 
0
Close
in what way is it not working?

the function used does stop tainting the database.
 
0
Close
Peter said:
in what way is it not working?

the function used does stop tainting the database.

Still the same problem and I get more SQL injection after I cahnge for example:

PHP:
$rs_query=mysql_query("Select * from sbwmd_categories where id=" . mysql_real_escape_string($cid) )
;
PHP:
$rs_query=mysql_query("Select * from sbwmd_categories where id=" . mysql_real_escape_string($rs["pid"]) );
PHP:
$rst1_query=mysql_query("Select * from sbwmd_categories where pid IN (" . mysql_real_escape_string($clist) . ") and id not in ( ". mysql_real_escape_string($clist) . ")") ;


I think I dont know how to do it.
 
0
Close
Is "ID" always an integer?
If so, please filter it this way, maybe not the most secure, but i believe this one is secure.
PHP:
$id = $_GET['category'];// for example

// Remove non numeric
$id = preg_replace('/([^0-9]+)/', '', $id);

// Intval'ed it
$id = intval($id);

// Use it for query, etc
 
0
Close
How are you testing these SQL injection holes? Just curious.
 
0
Close
0
Close
It's possible that the software is getting a false positive and not recognizing that sanitation function. I would hand-test each sql injection it finds to see if they're actually still vulnerable.
 
0
Close
It's possible that the software is getting a false positive and not recognizing that sanitation function.

I was wondering that myself - especially if you're using the free version.

I found an article on their site about using addslashes/stripslashes to prevent SQL injection attacks. That is an older way of doing it (don't use it - mysql_real_escape_string is more robust) and it's probably an old article, but the free version of their software may not be up-to-date and could be looking for something like that.
 
Last edited:
0
Close
awal said:
Acunetix Web Vulnerability Scanner 5
http://www.acunetix.com/
I agree with false positive alarm.
However, if you still believe there is a hole in your script, make sure you filter every variable which is related to the SQL query.

For example, if a variable is supposed to be a numeric, remove all non numeric characters.
If a variable is supposed to be alpha numeric, remove all non alphanumeric characters.

Do this with regular expression. :imho:

Good luck :tu:
 
0
Close
Thank you for your help

I run my website and hope nothing happend in the future
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back