Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
MySQL Injection Attacks
Old 10-20-2010, 10:41 PM MySQL Injection Attacks
Novice Talker

Posts: 11
Trades: 0
I have a few specific questions about PHP, MySQL, and injection attacks. They are:

1. For mysql_query(), the documentation says that, "mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier." The part that is bold is what I am curious about. Does the fact that multiple queries are not supported mean that if I use this function that MySQL injection attacks are thwarted by this function?

2. I've read about the mysql_real_escape_string() function, and I am wondering is this sufficient to prevent against MySQL injection attacks or is this just one piece of the puzzle?

3. Do functions like mysql_fetch_array() or mysql_fetch_assoc() only process one query like mysql_query() or is it best to use mysql_real_escape_string() before using them?

4. How effective are stored procedures to prevent against injection attacks? Will they thwart these attacks on their own?

Thanks!
zenthoef is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-21-2010, 05:14 PM Re: MySQL Injection Attacks
portkey's Avatar
Skilled Talker

Posts: 55
Name: Erica Dion
Trades: 0
I can try to answer these to the best of my abilities

1. Multiple queries are not supported means just as is says, you can't have more than one query in that single function. MySQL Injection implies that a piece of a query is inserted, not an entire one. Just inserting a little piece can hack the whole query.

2. If you're really worried about SQL Injection, then I would recommend widening your focus. PHP has a couple functions to help but you can still use IF statements to check for particular, common ways of injection.

3. mysql_fetch_array() and mysql_fetch_assoc() only fetch an executed query. Your question here didn't really make any sense so maybe you didn't realize this? For example, a common use of these functions would look like this:
PHP Code:
$query mysql_query("SELECT * FROM dual");
while(
$row mysql_fetch_assoc($query)) {
   
/*statements */

4. Anything you can do in a stored procedure again you could do with PHP. Stored Procedures should be used more for extensive SQL statements that return a wider set of results.

Overall, MySQL Injection is mainly a threat where part of the SQL statement is dependent on a variable that maybe the user inputs. For example, when validating a user who logs in, a SQL statement would check for a username in the database to match the one supplied, but if they enter a tidbit from a SQL WHERE clause, it could completely change the statement.
PHP Code:
$query "SELECT * FROM user_tables WHERE u_name='$input' LIMIT 1";
/* given input is: test' OR 'x'='x */
$query "SELECT * FROM user_tables WHERE u_name='test' OR 'x'='x' LIMIT 1" 
Obviously, that second query would always be true and return a false positive. Hope that helps!
__________________
Hysterical Web Design

Please login or register to view this content. Registration is FREE

Fair priced and reliable web design services that complement your website needs
portkey is offline
Reply With Quote
View Public Profile Visit portkey's homepage!
 
Old 10-22-2010, 01:01 AM Re: MySQL Injection Attacks
vivekar's Avatar
Webmaster Talker

Posts: 612
Trades: 0
I would recommend you read PHP5 Power Programming, where author explains you on "How to write secure code".
Many techniques such as input sanitization and HMAC Verification are explained in detail.

Also, read this very good thread on XSS.
http://www.webmaster-talk.com/php-fo...s-attacks.html
__________________

Please login or register to view this content. Registration is FREE
(Active since 2003) |
Please login or register to view this content. Registration is FREE
vivekar is offline
Reply With Quote
View Public Profile Visit vivekar's homepage!
 
Reply     « Reply to MySQL Injection Attacks
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46361 seconds with 12 queries