在进行挖掘SQL注入的时候,首先带大家了解一下,出现问题的注入代码,以及预处理防范的代码
首先是普通的Statement查询(JDBC)
毫无疑问,下方是jdbc中,最经典的注入。就是由于拼接所导致
statement.executeQuery("select * from user where user="+拼接变量);
如上,在执行executeQuery执行SQL语句的时候,假设后面的where user=可控拼接的字符串,那么就轻而易举可以利用
Connection coon = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8","root","root");
Statement statement = coon.createStatement();
ResultSet resultSet = statement.executeQuery("select * from user where user="+拼接变量);
List<Integer> lists = new ArrayList<>();
while(resultSet.next()){
System.out.println(resultSet.getInt("id"));
System.out.println(resultSet.getString("user"));
System.out.println(resultSet.getString("pass"));
lists.add(resultSet.getInt("id"));
}
---------------------------------------------------------------------------------------------------------
String sql = "select * from user where user= "+user;
System.out.println(sql);
List<Map<String,Object>> lists = jdbcTemplate.queryForList(sql);
return lists;
继续往下看,其实修复普通的jdbc的SQL注入很简单,接下来简要分析一下
可以看到在第二行