JAVA代码审计一文审计SQL注入
2023-2-15 21:50:6 Author: HACK安全(查看原文) 阅读量:6 收藏

在进行挖掘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注入很简单,接下来简要分析一下

可以看到在第二行


文章来源: http://mp.weixin.qq.com/s?__biz=Mzg2NjU0MjA0Ng==&mid=2247487213&idx=1&sn=2c158eca1a477c473251d0ba6e43162d&chksm=ce48065cf93f8f4ae2028cf65ea6c07ab47219ad6fa907df448dfdb6c6dcf5c7158144b363dc#rd
如有侵权请联系:admin#unsafe.sh