Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 1, 2026.

How to fix SQL injection

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
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
•••
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
•••
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
•••
in what way is it not working?

the function used does stop tainting the database.
 
0
•••
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
•••
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
•••
How are you testing these SQL injection holes? Just curious.
 
0
•••
0
•••
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
•••
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
•••
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
•••
Thank you for your help

I run my website and hope nothing happend in the future
 
0
•••
Appraise.net

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back