sql-injection

How to create a SQL injection attack with Shift-JIS and CP932?

荒凉一梦 提交于 2019-11-27 09:45:36
问题 I'm writing some unit tests to ensure my code isn't vulnerable to SQL injection under various charsets. According to this answer, you can create a vulnerability by injecting \xbf\x27 using one of the following charsets: big5 , cp932 , gb2312 , gbk and sjis This is because if your escaper is not configured correctly, it will see the 0x27 and try to escape it such that it becomes \xbf\x5c\x27 . However, \xbf\x5c is actually one character in these charsets, thus the quote ( 0x27 ) is left

Is mysqli_real_escape_string safe?

强颜欢笑 提交于 2019-11-27 09:25:50
I´m new in PHP and I´ve realised that my database connection, using a php form (with user and pass text inputs) was totally unsafe: This was working, but was unsafe: <?php $link=mysqli_connect('localhost','xx','xx','xx'); $sql=' SELECT * FROM usuarios WHERE username="'.$_POST['usuario'].'" AND pass="'.$_POST['usuario'].'" '; $rs=mysqli_query($link,$sql); mysqli_close($link); ?> So, I´ve read about mysqli_real_escape_string, and decided to try it out: <?php $link=mysqli_connect('localhost','xx','xx','xx'); $usuario=mysqli_real_escape_string($link, $_POST["usuario"]); $clave=mysqli_real_escape

How to cleanse dynamic SQL in SQL Server — prevent SQL injection

别等时光非礼了梦想. 提交于 2019-11-27 09:16:34
We have a ton of SQL Server stored procedures which rely on dynamic SQL. The parameters to the stored procedure are used in a dynamic SQL statement. We need a standard validation function inside these stored procedures to validate these parameters and prevent SQL injection. Assume we have these constraints: We can't rewrite the procedures to not use Dynamic SQL We can't use sp_OACreate etc., to use regular expressions for validation. We can't modify the application which calls the stored procedure to validate the parameters before they are passed to the stored procedure. Is there a set of

What does bind_param accomplish?

旧城冷巷雨未停 提交于 2019-11-27 09:05:07
I'm learning about avoiding SQL injections and I'm a bit confused. When using bind_param, I don't understand the purpose. On the manual page, I found this example: $stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)"); mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent); $code = 'DEU'; $language = 'Bavarian'; $official = "F"; $percent = 11.2; Now, assuming those 4 variables were user-inputted, I don't understand how this prevents SQL injections. By my understanding, they can still input whatever they want in there. I also can't find an

Is preventing XSS and SQL Injection as easy as does this

ぐ巨炮叔叔 提交于 2019-11-27 08:46:02
Question : Is preventing XSS (cross-site scripting) as simple using strip_tags on any saved input fields and running htmlspecialchars on any displayed output ... and preventing SQL Injection by using PHP PDO prepared statements? Here's an example: // INPUT: Input a persons favorite color and save to database // this should prevent SQL injection ( by using prepared statement) // and help prevent XSS (by using strip_tags) $sql = 'INSERT INTO TABLE favorite (person_name, color) VALUES (?,?)'; $sth = $conn->prepare($sql); $sth->execute(array(strip_tags($_POST['person_name']), strip_tags($_POST[

What is PDO, how is it related with SQL injection, and why I should use this?

谁说胖子不能爱 提交于 2019-11-27 08:44:46
问题 Actually I did google and got so many results, but I can't understand, because I'm new in this field. So what is an easy way that what is PDO, why I should use this, what is SQL injection, etc. with an example?1 Actually now my code is like that. config.php <?php $mysql_hostname = "localhost"; $mysql_user = "root"; $mysql_password = ""; $mysql_database = "testdb"; $prefix = ""; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database"); mysql

rails 3 activerecord order - what is the proper sql injection work around?

允我心安 提交于 2019-11-27 08:24:42
let us say I have a list page of users and you can sort by the different columns, when clicking 'email' it will pass sort_by=email sort_direction=asc or desc sort_by = "email" # really params[:sort_by] sort_direction = "asc" # really params[:sort_direction] User.order("#{sort_by} #{sort_direction}") # SELECT "users".* FROM "users" ORDER BY email asc so that works as expected, however if we change the sort_by sort_by = "email; DELETE from users; --" User.order("#{sort_by} #{sort_direction}") # SELECT "users".* FROM "users" ORDER BY email; DELETE from users; -- asc now we have no more users :( I

How to prevent SQL Injection with JPA and Hibernate?

点点圈 提交于 2019-11-27 08:03:06
I am developing an application using hibernate. When I try to create a Login page, The problem of Sql Injection arises. I have the following code: @Component @Transactional(propagation = Propagation.SUPPORTS) public class LoginInfoDAOImpl implements LoginInfoDAO{ @Autowired private SessionFactory sessionFactory; @Override public LoginInfo getLoginInfo(String userName,String password){ List<LoginInfo> loginList = sessionFactory.getCurrentSession().createQuery("from LoginInfo where userName='"+userName+"' and password='"+password+"'").list(); if(loginList!=null ) return loginList.get(0); else

Dynamic SQL WHERE clause generation

戏子无情 提交于 2019-11-27 07:57:28
问题 For the record, I'm using Python and SQLlite. I have a working function that generates the SQL I need, but it does not seem right. def daily(self, host=None, day=None): sql = "SELECT * FROM daily WHERE 1" if host: sql += " AND host = '%s'" % (host,) if day: sql += " AND day = '%s'" % (day,) return sql I will probably need to add multiple columns and criteria later on. Any better ideas? Edit: What does not look right is that I am constructing the SQL dynamically from Strings. This is generally

Preventing SQL Injection in C

心已入冬 提交于 2019-11-27 07:06:55
问题 I am writing a C application that takes some user input and does a few database queries. I am well aware of the risks here of SQL injection and wish to prevent it. Ideally I would use parameterized queries, but have been unable to find anything with this functionality in C so far. I am currently constructing my queries as such: char *query; asprintf(&query, "UPDATE SomeTable SET SomeField='%s';", userInput); If I am unable to do this, then I must need to filter the user input. How should this