sql-injection

Prevent SQL injection in WebSQL database? (How to handle quotes in data?)

本小妞迷上赌 提交于 2019-11-30 17:20:21
问题 I'm currently importing an xml export of a mysql database into a websql database for use in an online mobile experience. Everything works fine and dandy until there are double quotes in whatever string I am inserting. Normally, in PHP I would be using something like: mysql_real_escape_string while inserting. Options I know I can try is to write regex and make functions for adding/removing slashes. There are lots of examples on google for this - but what i'm looking to see is if anyone else

Is it necessary to use mysql_real_escape_string(), when magic_quotes_gpc is on?

五迷三道 提交于 2019-11-30 16:42:42
To prevent SQL injection, is it necessary to use mysql_real_escape_string() , when magic_quotes_gpc is on? For some rare encodings, such as GBk - yes. But you should revert it not for this reason. Magic quotes should be turned off anyway (and will be in the next PHP version). So, mysql_real_escape_string() is the only escape function is left. Note that it is not sql injection prevention function. Many many people don't understand this point: it's just a part of syntax. It must be used not to "protect" anything, but to assemble syntactically correct SQL query. And must be used every time you

How does sprintf() protect against SQL injection?

荒凉一梦 提交于 2019-11-30 14:40:49
I have heard that sprintf() protects against SQL injection. Is it true? If so, how? Why people are recommending to write query like this: $sql = sprintf('SELECT * FROM TABLE WHERE COL1 = %s AND COL2 = %s',$col1,$col2); beardhatcode sprintf wont protect! it only replaces the %s you must mysql_real_escape_string so: $sql = sprintf('SELECT * FROM TABLE WHERE COL1 = "%s" AND COL2 = "%s"', mysql_real_escape_string($col1), mysql_real_escape_string($col2)); is safer injection note: I sugets you take a look at PDO , that is what I like to use for DBconections and queries That doesn't do any protection

Correct escaping of delimited identifers in SQL Server without using QUOTENAME

孤街浪徒 提交于 2019-11-30 13:22:51
Is there anything else that the code must do to sanitize identifiers (table, view, column) other than to wrap them in double quotation marks and "double up" double quotation marks present in the identifier name? References would be appreciated. I have inherited a code base that has a custom object-relational mapping (ORM) system. SQL cannot be written in the application but the ORM must still eventually generate the SQL to send to the SQL Server. All identifiers are quoted with double quotation marks. string QuoteName(string identifier) { return "\"" + identifier.Replace("\"", "\"\"") + "\"";

mysql_escape_string whole post array?

一曲冷凌霜 提交于 2019-11-30 12:52:57
I was wondering is it possible to just my_sql_escape string the whole $_POST and $_GET array so you dont miss any variables? Not sure how to test it or I would've myself. Thanks! I would use the array_walk() function. It's better suited because modifies the POST superglobal so any future uses are sanitized. array_walk_recursive( $_POST, 'mysql_real_escape_string' ); However, make sure that you don't rely on this line to completely protect your database from attacks. The best protection is limiting character sets for certain fields. Ex. Email's don't have quotes in them (so only allow letters,

Strange URL containing 'A=0 or '0=A in web server logs

半腔热情 提交于 2019-11-30 12:40:22
问题 During the last weekend some of my sites logged errors implying wrong usage of our URLs: ...news.php?lang=EN&id=23'A=0 or ...news.php?lang=EN&id=23'0=A instead of ...news.php?lang=EN&id=23 I found only one page originally which mentioned this (https://forums.adobe.com/thread/1973913) where they speculated that the additional query string comes from GoogleBot or an encoding error. I recently changed my sites to use PDO instead of mysql_* . Maybe this change caused the errors? Any hints would

Proving SQL Injection

别说谁变了你拦得住时间么 提交于 2019-11-30 09:48:37
I'm trying to simply prove here that this simple function isn't good enough to prevent every sql injection in the world: Function CleanForSQL(ByVal input As String) As String Return input.Replace("'", "''") End Function Here is a typical insert statement from one of our apps: Database.DBUpdate("UPDATE tblFilledForms SET Text1 = '" + CleanForSQL(txtNote.Text) + "' WHERE FilledFormID = " + DGVNotes.SelectedRows(0).Cells("FilledFormID").Value.ToString) I know its not secure, because of googling and looking up other questions on StackOverflow.com. Here is one question that I found in which all

Prepared statements and second order SQL injections

喜夏-厌秋 提交于 2019-11-30 09:44:37
问题 I have read somewhere here that using prepared statements in PDO makes your app only immune to first order SQL injections, but not totally immune to second order injections. My question is: if we used prepared statements in all queries inlcuding SELECT queries and not only in INSERT query, then how can a second order sql injection be possible? For example in the following queries there is no chance for a 2nd order injection: write: INSERT INTO posts (userID,text,date) VALUES(?,?,?) read:

Correct PHP method to store special chars in MySQL DB

江枫思渺然 提交于 2019-11-30 09:14:51
问题 Using PHP, what is the best way to store special characters (like the following) in a MSQUL database, to avoid injections. « " ' é à ù This is how I do it now: $book_text=$_POST['book_text']; $book_text=htmlentities($book_text, "ENT_QUOTES"); $query=//DB query to insert the text Then: $query=//DB query to select the text $fetch=//The fetch of $book_text $book_text=html_entity_decode($book_text); This way, all my text is formatted in HTML entities. But I think this takes up a lot of database

Does LINQ's ExecuteCommand provide protection from SQL injection attacks?

让人想犯罪 __ 提交于 2019-11-30 08:54:23
问题 I've got a situation where I need to use LINQ's ExecuteCommand method to run an insert. Something like (simplified for purposes of this question): object[] oParams = { Guid.NewGuid(), rec.WebMethodID }; TransLogDataContext.ExecuteCommand ( "INSERT INTO dbo.Transaction_Log (ID, WebMethodID) VALUES ({0}, {1})", oParams); The question is if this is SQL injection proof in the same way parameterized queries are? 回答1: Did some research, and I found this: In my simple testing, it looks like the