当前位置:网站首页>SQL注入攻击
SQL注入攻击
2022-07-23 21:29:00 【汤键.】
目录
什么是SQL注入攻击
- 就是利用sql语句的漏洞来对系统进行攻击
攻击演示
- 例如在输入密码时采用了sql语句验证
- 如:
select * from user where loginname='zhangsan' and password='123456'- 这条语句需要账号为zhangsan和密码为123456才能登录成功
- 可若是在账号随便输但输入密码时输入bbb' or '1'='1
- 传入语句中就是
select * from user where loginname='aaa' and password='bbb' or '1'='1'- 也对了就登录成功了
- 这就是sql注入攻击
SQL注入攻击的原理
- 按照正常道理来说,我们在密码处输入的所有内容,都应该认为是密码的组成
- 但是现在Statement对象在执行sql语句时,将密码的一部分内容当做查询条件来执行了,后边的条件一满足不就也能查询出数据
SQL注入攻击的解决
- 使用PreparedStatement预编译执行者对象
- 它会在执行sql语句之前,将sql语句进行提前编译
- 明确sql语句格式后,就不会改变了
- 剩余的内容都会认为是参数
- sql语句中的参数使用?作为占位符
- 为?占位符赋值的方法
- setXxx(参数1,参数2);
- Xxx代表数据类型
- 参数1:?的位置编号(编号从1开始)
- 参数2:?的实际参数
- 如:
String sql="SELECT * FROM user WHERE loginname=? AND password=?"; pstm = con.prepareStatement(sql); pstm.setString(1,"张三"); pstm.setString(2,"123456");
执行sql语句
//定义SQL语句 String sql = "SELECT * FROM user WHERE loginname=? AND password=?"; //获取操作对象,执行sql语句,获取结果集 st = con.prepareStatement(sql); st.setString(1,"张三"); st.setString(2,"123456"); rs = st.executeQuery(); //获取结果集 if(rs.next()){ .......进行封装 }
边栏推荐
猜你喜欢

VLAN comprehensive experiment

& 9 nodemon automatic restart tool

Mysql database index

Cluster chat server: cluster and distributed theory
![[isprint function determines whether characters can be output]](/img/c8/c06dc36dbd0bf1feeba64c7753faf5.png)
[isprint function determines whether characters can be output]

Basic principle of synchronized lock

Serveur de chat de Cluster: conception de la table de base de données

Kuberntes cloud native combat VI uses rook to build CEPH cluster

Cluster chat server: how to solve the problem of cross server communication | redis publish subscribe

Union and union all of Hana SQL
随机推荐
OpenCV图像处理——拉普拉斯金字塔
HDU - 2586 How far away ? (multiply LCA)
Unity—3D数学-Vector3
Protocol buffers 的问题和滥用
Cluster chat server: creation of project directory
【愚公系列】2022年06月 .NET架构班 084-微服务专题 Abp vNext微服务通信
TypeScript基础
Chapter1 数据清洗
Day109.尚医通:集成Nacos、医院列表、下拉列表查询、医院上线功能、医院详情查询
宇树A1机器狗手势控制
BroadCast(广播)
Several methods of obtaining longitude and latitude by cesium
Looking for the missing class name
High numbers | calculation of double integral 4 | high numbers | handwritten notes
Network learning infrared module, 8-way emission independent control
现在完全不知道怎么同步
-2021 sorting and sharing of the latest required papers related to comparative learning
Basic syntax of MySQL DDL and DML and DQL
Comment présenter votre expérience de projet lors d'une entrevue
Day109. Shangyitong: integrate Nacos, hospital list, drop-down list query, hospital online function, hospital details query