Hi,
http://paperhub.x10hosting.com/links.php
I have been told that it would be quite easy to do an SQL injection on this page.
Does anyone know if this is true, and if it is how would I fix it?
~Callum
Hi,
http://paperhub.x10hosting.com/links.php
I have been told that it would be quite easy to do an SQL injection on this page.
Does anyone know if this is true, and if it is how would I fix it?
~Callum
I can customise your phpBB board. Send me a PM.
lynxphp - info, tutorials and scripts
"A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."
I tried a couple of possible exploits, but I don't think any of them worked (however, I could be wrong too). What you should pay attention for sql injections to is every variable that goes in your query. For example with the order by: if $_GET["o"] is not equal to "asc" or "desc", don't use the value in your query. Pay special attention to strings that are actually dependant on user input, such as usernames. If such variables are used in your query, ALWAYS use mysql_escape_string on them, to make sure all special characters in sql are escaped.
Example:
PHP Code:$query = "SELECT * FROM `users` WHERE `login`= '".mysql_escape_string($_GET["login"])."'";
Real programmers don't document their code - if it was hard to write, it should be hard to understand.
Nothing is always absolutely so.
(visited only http://paperhub.x10hosting.com/links.php )
My suggestion would be to use POST instead of GET in every form, and to use pre-fabricated query's (if possible).
eg.
(ugly pseudo code)PHP Code:if ( POST_ob == name && POST_o == asc)
// query, no variables in here
else
if ( POST_ob == added && POST_o == desc)
// query, no variables in here
else
...
escape every user input (it couldn't hurt to escape your output, too..)
easy and cheap solution :P
Last edited by slacker3; 01-09-2010 at 04:51 PM.
Better yet, use a DB driver (such as PDO) that supports prepared statements, which aren't vulnerable to SQL injection. You still have to consider other types of injection attacks, such as XSS.
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.
My suggestion ,WE prevent SQL injections as opposed to binary, is to use URL Encoding or Hex Encoding.
I haven't seen a complete example of stopping SQL Injections, most refer to use the mysql_real_escape_string function or param statements.
Regards ~ Vishal
Giving Reputation(at bottom of my post ) is the best way to encourage the person who helped you on forums.
So is this better:
Thanks for helpingCode:<?php if(isset($_GET['ob']) && isset($_GET['o']) && (($_GET['o'] == "asc") || ($_GET['o'] == "desc")) && (($_GET['ob'] == "name") || ($_GET['ob'] == "added") || ($_GET['ob'] == "date"))) { $sql = "SELECT * FROM `links` ORDER BY `{$_GET['ob']}` {$_GET['o']}"; }else{ $sql = "SELECT * FROM `links` ORDER BY `Name` ASC"; } $result = mysqli_query($cxn,$sql) or die("SQL failed"); $num = 1; while ($row = mysqli_fetch_array($result)) { extract($row); echo "<a href=\"$Link\"><b>$Name</b></a><br /><p>$Description</p><p style=\"font-size:7pt\">Added by $added at $Date</p><br />"; $num++; } ?>
~Callum
I can customise your phpBB board. Send me a PM.
lynxphp - info, tutorials and scripts
"A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."
Yes, that code cannot create a query with any values different than legit ones. Very good
Make sure your search function is as safe as this one and you'll be sql-injection-free.
Real programmers don't document their code - if it was hard to write, it should be hard to understand.
My search boxes are written by google and phpbb, so I'm kinda hoping they're secure
Thanks again,
~Callum
I can customise your phpBB board. Send me a PM.
lynxphp - info, tutorials and scripts
"A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."
They should be fine.
You can test the most common SQL(or XSS)-injection attacks against your forms automatically
with the firefox-extension "SQL Inject-Me" (or "XSS-me") which is part of the "Exploit-Me" Suite.
List of useful Firefox Extensions on my site. (the last one in "Security auditing")
Last edited by slacker3; 01-10-2010 at 09:46 AM.