mysql注入攻击案例分享

394 阅读1分钟

「这是我参与11月更文挑战的第9天,活动详情查看:2021最后一次更文挑战」。

1.背景知识点介绍

①mysql可以使用and连接两个甚至多个查询条件

②and的优先级高于or

③举例说明

select p_name,p_price from products where v_id=1002 or v_id=1003 and p_price>=10; 执行的逻辑是v_id=1003 和 p_price>=10进行组合,而不是预期需求,返回的v_id等于1003或者1002,并且p_price大于等于10。

2.案例展示

①创建代码

create table user_u( userid int not null primary key auto_increment, username varchar(50), userp varchar(30)); insert into user_u(username,userp) values('aaa','1234'),('bbb','1234'),('ccc','1234');

②验证过程

select *from user_u where username='输入账号'and userp='输入密码';

③正确和错误示范

正常登陆,输入正确账号和密码: aaa 1234 登陆失败,输入错误账号或密码任意一个错误:如aaa 123或者aaaa,1234都不能正常登陆

④注入攻击

随便输入账号abdce,密码必须为: wee 'or 1='1

select *from user_u where username='abdce' and userp='wee' or 1='1';

3.总结

为避免注入攻击,要尽量减少拼接的输入语法。