当前位置:网站首页>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()){ .......进行封装 }
边栏推荐
- Why cluster chat server introduces load balancer
- [shader realizes roundwave circular ripple effect _shader effect Chapter 6]
- Junior intern, ByteDance, after sharing, has been offered
- Union and union all of Hana SQL
- Broadcast (broadcast)
- Failed to introspect class feignclientfactorybean exception troubleshooting
- Chapter 2 回归
- High numbers | calculation of triple integral 2 | high numbers | handwritten notes
- 大三实习生,字节跳动面经分享,已拿Offer
- 集群聊天服务器:Model数据层的框架设计和数据库代码的封装
猜你喜欢

VLAN comprehensive experiment

Unity - 3D mathematics -vector3

Basic syntax of MySQL DDL and DML and DQL
![[Yugong series] June 2022.Net architecture class 084- micro service topic ABP vNext micro service communication](/img/29/b73edbdb2409f40c904d126f9185d1.png)
[Yugong series] June 2022.Net architecture class 084- micro service topic ABP vNext micro service communication

Chapter 2 回归

Mysql database index

-2021 sorting and sharing of the latest required papers related to comparative learning

Basic knowledge of mobile phone testing

High numbers | calculation of double integral 2 | high numbers | handwritten notes

Qt桌面白板工具其一(解决曲线不平滑的问题——贝塞尔曲线)
随机推荐
Green Tao theorem (3): anti uniform functions and their generated sigma Algebras
& 9 nodemon automatic restart tool
Mysql database index
Connect with Hunan Ca and use U_ Key login
Jianzhi offer II 115. reconstruction sequence: topological sorting construction problem
What is Kai Niu? Excuse me, is it safe to open a stock account by mobile phone?
First acquaintance with JS (programming suitable for beginners)
Flink principle and development summary (detailed)
现在完全不知道怎么同步
googletest
LeetCode_ 376_ Wobble sequence
High numbers | calculation of double integral 2 | high numbers | handwritten notes
1062 Talent and Virtue
Cluster chat server: Framework Design of model data layer and encapsulation of database code
MySql的DDL和DML和DQL的基本语法
Synchro esp32c3 Hardware Configuration Information serial port Print Output
Network learning infrared module, 8-way emission independent control
集群聊天服务器:chatService业务层
Chapter1 数据清洗
Cluster chat server: cluster and distributed theory