sql-injection

Is a SQLAlchemy query vulnerable to injection attacks?

五迷三道 提交于 2019-11-30 08:36:12
问题 I have the following query that uses like to search a blog. I am not sure if I'm making myself vulnerable to a SQL injection attack if I do this. How is SQLAlchemy handling this? Is it safe? search_results = Blog.query.with_entities(Blog.blog_title).filter(Blog.blog_title.like("%"+ searchQuery['queryText'] +"%")).all() 回答1: The underlying db-api library for whatever database you're using (sqlite3, psycopg2, etc.) escapes parameters. SQLAlchemy simply passes the statement and parameters to

Sql Injection protection with only str_replace

╄→尐↘猪︶ㄣ 提交于 2019-11-30 07:41:53
问题 I'm studying SQL injection and tried in my PHP code this query: $condition = str_replace(["'","\\"],["\\'","\\\\"], @$_GET['q']); $query = "SELECT * FROM dummy_table WHERE dummy_column = '$condition'"; DB and tables charset is set to UTF8. I can't inject anything, can someone help me please? EDIT: As pointed out by GarethD this would escape first ' and than \, allowing injection, what about this str_replace? $condition = str_replace(["\\","'"],["\\\\","\\'"], @$_GET['q']); 回答1: This isolated

function to sanitize input to Mysql database

假如想象 提交于 2019-11-30 03:42:08
I am trying to put a general purpose function together that will sanitize input to a Mysql database. So far this is what I have: function sanitize($input){ if(get_magic_quotes_qpc($input)){ $input = trim($input); // get rid of white space left and right $input = htmlentities($input); // convert symbols to html entities return $input; } else { $input = htmlentities($input); // convert symbols to html entities $input = addslashes($input); // server doesn't add slashes, so we will add them to escape ',",\,NULL $input = mysql_real_escape_string($input); // escapes \x00, \n, \r, \, ', " and \x1a

How do Django forms sanitize text input to prevent SQL injection, XSS, etc?

五迷三道 提交于 2019-11-30 03:33:21
问题 I don't see any form input sanitization in Django's form code w/r/t handling raw text. How does Django ensure that user input is sanitized when going into the database? Does it do this at all to prevent SQL injection, etc? 回答1: User input is sanitized by the database driver automatically. Explicit user input sanitization is only ever required when you are trying to assemble a single string that contains both the SQL commands and also the data that you are trying to include; proper use of the

Escaping user input from database necessary?

人走茶凉 提交于 2019-11-30 03:31:05
So I know about MySQL injection and always escape all my user input before putting it in my database. However I was wondering, imagine a user tries to submit a query to inject, and I escape it. What if I then at a later moment take this value from the database, and use it in a query. Do I have to escape it again? So: ( sql::escape() contains my escape function) $userinput = "'); DROP `table` --"; mysql_query("INSERT INTO `table` (`foo`,`bar`) VALUES ('foobar','".sql::escape($userinput)."')"); // insert php/mysql to fetch `table`.`bar` into $output here mysql_query("INSERT INTO `table2` (`foo`,

PostgreSQL - DB user should only be allowed to call functions

给你一囗甜甜゛ 提交于 2019-11-30 03:18:15
Currently I'm using PostgreSQL for my application. Since I am trying to put every SQL that contains a transaction (i.e. insert, update, delete) in a function, I stumbled upon this problem: Is it possible that a database user may only be allowed to call functions and Select-Statements while he can not call SQL-Statements which contains a transaction? By "call functions" I mean any function. Regardless if it contains a transaction or not. I already tried to create a user which can only call functions and Select-Statements. But I always end up with an error, when calling functions which contains

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

谁说胖子不能爱 提交于 2019-11-30 03:17:50
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 be useful. Additionally, all of the requests come from the same user-agent shown below. Mozilla/5.0

Which characters are actually capable of causing SQL injection in mysql

本小妞迷上赌 提交于 2019-11-30 03:05:25
We all know that we should use prepared statements or the appropriate replacement/formatting rules in order to prevent sql injection in our applications. However, when taking a look at MySQL's list of character literals, I noticed that it includes the following characters: \0 An ASCII NUL ( 0x00 ) character. \' A single quote ( ' ) character. \" A double quote ( " ) character. \b A backspace character. \n A newline (linefeed) character. \r A carriage return character. \t A tab character. \Z ASCII 26 ( Ctrl + Z ). See note following the table. \\ A backslash ( \ ) character. \% A % character. \

How can I prevent SQL injection attacks in Go while using “database/sql”?

大兔子大兔子 提交于 2019-11-30 01:46:17
Building my first web-app and want to understand SQL injection better ( https://github.com/astaxie/build-web-application-with-golang/blob/master/en/eBook/09.4.md ). How much protection against SQL injection do I get from just always using the 'database/sql' library and constructing queries using '?' instead of concatting strings? What kind of SQL injection attacks will I still have to worry about in that case? As long as you're using Prepare or Query , you're safe. // this is safe db.Query("SELECT name FROM users WHERE age=?", req.FormValue("age")) // this allows sql injection. db.Query(

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

自古美人都是妖i 提交于 2019-11-30 00:00:47
问题 To prevent SQL injection, is it necessary to use mysql_real_escape_string() , when magic_quotes_gpc is on? 回答1: 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