sql-injection

PDO in Codeigniter - Protect vs SQL Injection

末鹿安然 提交于 2019-11-27 21:51:53
问题 True PHP Security experts, is PDO the way to go or would I be ok with Codeigniter's Active Record class? I have read http://codeigniter.com/forums/viewthread/179618/ and am not 100% convinced. I usually lean on experts such as Chris Shiflett and OWASP for security tips. http://shiflett.org/blog/2006/jul/the-owasp-php-top-5 Been using a homebrewed PDO DB Class in place of the Codeigniter Database files. Everytime I upload it is a relatively small pain to copy over. The main reason I use PDO is

How do I sanitize SQL without using prepared statements

夙愿已清 提交于 2019-11-27 21:21:37
For some sql statements I can't use a prepared statment, for instance: SELECT MAX(AGE) FROM ? For instance when I want to vary the table. Is there a utility that sanitizes sql in Java? There is one in ruby. Bill Karwin Right, prepared statement query parameters can be used only where you would use a single literal value . You can't use a parameter for a table name, a column name, a list of values, or any other SQL syntax. So you have to interpolate your application variable into the SQL string and quote the string appropriately. Do use quoting to delimit your table name identifier, and escape

A PHP function to prevent SQL Injections and XSS

白昼怎懂夜的黑 提交于 2019-11-27 20:45:35
问题 I am tring to make my PHP as secure as possible, and the two main things I am trying to avoid are mySQL Injections Cross-Side Scripting (XSS) This is the script I got against mySQL Injections: function make_safe($variable) { $variable = mysql_real_escape_string(trim($variable)); return $variable; } http://www.addedbytes.com/writing-secure-php/writing-secure-php-1/ Against XSS, I found this: $username = strip_tags($_POST['username']); Now I want to unite the two into a single function. Would

Is SQL injection a risk today?

余生颓废 提交于 2019-11-27 20:23:55
I've been reading about SQL injection attacks and how to avoid them, although I can never seem to make the "awful" examples given work, e.g. see this post . I created a PHP file and a table in the database, had a value passed through $_GET and tried to delete the table by doing bob'); drop table students; -- and it didn't work. PHP automatically escapes the \' and the query has an error, no harm done. Same issue when trying to replicate login "attacks" like AND WHERE 1=1 etc. example code: <?php $id = $_GET['id']; $sql = "INSERT INTO Users (Username) VALUES ($id)"; echo $sql; mysql_query($sql)

Rails SQL injection?

為{幸葍}努か 提交于 2019-11-27 19:01:10
In Rails, when I want to find by a user given value and avoid SQL injection (escape apostrophes and the like) I can do something like this: Post.all(:conditions => ['title = ?', params[:title]]) I know that an unsafe way of doing this (possible SQL injection) is this: Post.all(:conditions => "title = #{params[:title]}") My question is, does the following method prevent SQL injection or not? Post.all(:conditions => {:title => params[:title]}) Yes, it does. Only the second one is dangerous. edthix One good reference from the RoR Guides. +1 @fphilipe and @yuval Check this 5 min video from

SQL Injection and Codeigniter

拥有回忆 提交于 2019-11-27 18:52:33
Some doubts regarding Codeigniter and its Input handling capabilities. Some may be a little weird but they are doubts none-the-less. If I use the Active Record Class functions in CodeIgniter, is my input prevented against SQL injection? I read somewhere that it does, but I don't understand it how? or why? Also does xssclean deal with SQL injection in any way? is my input prevented against SQL injection? Not exactly ‘automatically’, but it does provide parameterised queries. CodeIgniter or no, you should use parameterised queries in preference to query string hacking whenever possible. $bof= "a

Site has been hacked via SQL Injection

≡放荡痞女 提交于 2019-11-27 18:08:56
Recently my site was hacked via SQL injection. The hacker used the following query to get my DB name. I cannot understand this query they wrote. Query: =-999.9%20UNION%20ALL%20SELECT%20concat(0x7e,0x27,Hex(cast(database()%20as%20char)),0x27,0x7e),0x31303235343830303536,0x31303235343830303536,0x31303235343830303536-- After the query was ran it showed an integer result, something like " 74545883 ". Can you explain how the query works? sethvargo It looks like an overflow attack . They UNION -ed with your existing query. replacing all your %20 with (space) since its url-encoded yields: =-999.9

Is “filter input, escape output” still valid with PDO

放肆的年华 提交于 2019-11-27 18:01:55
问题 I've read this before "filter input, escape output" but is filtering input really needed when I use PDO with PHP? I thought with PDO I don't need to filter input because the prepared statement takes care of sql injections. I think "escape output" is still valid, but is "filter input" still valid? 回答1: Yes, it is still valid. Filtering is not about preventing security vulnerabilities, it's about not populating your database with garbage. If you're expecting a date, make sure it at least looks

Decoding mysql_real_escape_string() for outputting HTML

百般思念 提交于 2019-11-27 17:51:57
问题 I'm trying to protect myself from sql injection and am using: mysql_real_escape_string($string); When posting HTML it looks something like this: <span class="\"className\""> <p class="\"pClass\"" id="\"pId\""></p> </span> I'm not sure how many other variations real_escape_string adds so don't want to just replace a few and miss others... How do I "decode" this back into correctly formatted HTML, with something like: html_entity_decode(stripslashes($string)); 回答1: The mysql_real_escape_string(

PHP - Does PDO quote safe from SQL Injection?

萝らか妹 提交于 2019-11-27 16:43:20
问题 $id = trim((int)$_GET['id']); $sql = 'SELECT * FROM users WHERE id = ' . $db->quote($id) . ' LIMIT 1'; $run = $db->query($sql)->fetch(); Does PDO's quote method is safe as prepared statements? Or i have to use prepared statements all the way in my script? 回答1: Basically quote() is safe as prepared statements but it depends on the proper implementation of quote() and of course also on it's consequent usage. Additionally the implementation of the used database system/PDO driver has to be taken