sql注入是指应用程序对用户输入数据的合法性没有判断、没有过滤,攻击者可以在应用程序中通过表单提交特殊的字符串,该特殊字符串会改变sql的运行结果,从而在管理员毫不知情的情况下实现非法操作,以此来实现欺骗数据库执行非授权的任意查询。
sql注入的特点
广泛性:任何一个基于SQL语言的数据库都可能受到SQL注入攻击。很多开发人员都为了省事不对表单参数进行校验。
隐蔽性:SQL注入语句一般都嵌入在普通的HTTP请求中,很难与正常语句区分开,SQL注入也有很多变种。
危害大:攻击者通过SQL注入能够获取到更多数据,如管理员密码、整个系统的用户数据、他人的隐私数据、完整的数据库。
操作简单:互联网上有很多SQL注入工具,简单易懂,攻击过程简单,不需要太多专业知识。
create table user(
id int not null auto_increment primary key,
username varchar(30) comment '用户名',
password varchar(30) comment '密码'
)default charset=utf8;
insert into user(username, password) values('admin', '123456');
insert into user(username, password) values('test', '123456');
#正常查询
select * from user where username='abc' and password='123456';
#sql注入
select * from user where username='abc' and password='123456' or '1'='1';
查询到了所有的结果