Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Lionsanime Directory   ClickBooth Network   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 02-29-2008, 10:11 PM   #1 (permalink)
Contributing Member
 
Join Date: 12-14-05
Posts: 109
iTrader: 0 / 0%
Latest Blog:
None

gnznroses is on the right pathgnznroses is on the right path
Question SQL injection

I want to ensure that my scripts are safe against SQL injection, and i've read techniques, but i'm confused because even without using any security measures, i can't get injection to work in testing.

for example, on one form i ask for a username and do a search for it:

PHP Code:
$query "SELECT id FROM users WHERE name='" strtolower($userinfo['name']) . "'";
$result mysql_query($query);
if (!
$result){
//echo debug info
}; 
so i enter this as a username:
Quote:
a'; delete from delme where a='22
the query doesn't execute and triggers the debug info, which is as follows:
Quote:
Could not run name check
Magic quotes is disabled

query is:
SELECT id FROM users WHERE name='a'; delete from delme where a='22'

username was:
a'; delete from delme where a='22

you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near '; delete from delme where a='22'' at line 1

if i copy and paste that query, as listed above, mysql will run it and delete the row. so why doesn't this injection work?
i'm trying to understand what's going on and if i need to escape data at all.
gnznroses is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 03-01-2008, 06:56 PM   #2 (permalink)
Contributing Member
 
Join Date: 07-24-06
Posts: 625
iTrader: 1 / 100%
Latest Blog:
None

nasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nice
PHP - MySQL doesn't support stacked queries. You can run only one query at a time.

You should still escape data to avoid any other types of sql injection. For example:

Code:
SELECT id FROM users WHERE name='a' OR BENCHMARK(1000000,SHA1(1))
nasty.web is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-01-2008, 07:07 PM   #3 (permalink)
Contributing Member
 
Join Date: 12-14-05
Posts: 109
iTrader: 0 / 0%
Latest Blog:
None

gnznroses is on the right pathgnznroses is on the right path
oh, ok, thanks. so just use mysql_real_escape_string for each form input, and then i'm all set right?
gnznroses is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-01-2008, 07:16 PM   #4 (permalink)
Contributing Member
 
Join Date: 07-24-06
Posts: 625
iTrader: 1 / 100%
Latest Blog:
None

nasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nicenasty.web is just really nice
I think, yes.
nasty.web is offline  
Add Post to del.icio.us
Reply With Quote
Old 03-05-2008, 11:17 AM   #5 (permalink)
Contributing Member
 
kyrie's Avatar
 
Join Date: 02-19-08
Posts: 87
iTrader: 0 / 0%
kyrie is liked by many
mysql_real_escape_string is the function that will help us to prevent SQL injections attacks...
__________________
Wonder Years and Dean Martin
kyrie is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
IndexScript users sql injection ScriptMan Coding Forum 2 07-26-2007 11:43 AM
Injection Effect Mong Google Forum 1 08-12-2006 08:59 PM
sql injection help snout Coding Forum 21 04-28-2006 09:25 PM
PHP and SQL injection Limit Coding Forum 5 12-25-2004 03:35 AM
Google Toolbar About.HTML HTML Injection Vulnerability imaginemn Google Forum 5 09-21-2004 11:06 AM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 06:50 PM.
© Copyright 2008 V7 Inc