來源:http://bbs.ichunqiu.com/thread-9811-1-1.html?from=ch
社區(qū):i春秋
時間:2016年8月10日
作者:池寒
前言:
最近一個朋友組了個隊去打CTF,然后拉我去助他一臂之力(差人,拉我去打醬油。。。),然后我就去了。由于技術渣,只能旁觀。過程:
0x01
有一道題很有有意思,好像是21題,貌似最后只有18個人做出來了。

額,沒錯,就是一個妹紙的照片,據(jù)說許多人盯著妹紙看了一天都沒做出來。0x02
注意URL,發(fā)現(xiàn)可能是文件包含,這種URL表單是filename,然后嘗試用讀取這個文件http://218.76.35.75:20106/index.php?image=index.php

查看源代碼
明顯是base64,解碼得到:[AppleScript]純文本查看復制代碼

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
*CreatedbyPhpStorm.
*User:pfven
*Date:2016/7/20
*Time:21:35
*/
include 'header.php';
if(isset($_GET["image"])){
$file=$_GET['image'];
$file=preg_replace("/[^a-zA-Z0-9.]+/","",$file);
$file=str_replace("config","_",$file);
$txt=base64_encode(file_get_contents($file));
echo"";
}else{
header("Location: index.php?image=heihei.jpg");
exit();
}
include 'footer.php';
//***
發(fā)現(xiàn)是代碼泄漏
PhpStorm是一個php 的IDE。由于編輯器為了防止突然斷電,保存項目。都會建立自己的文件夾。
每個項目的配置存儲在項目所在目錄的 .idea 文件夾中,并以XML格式保存配置。如果你設置的是 “default project settings 默認項目設置”,那么這個默認設置將會自動應用到下一個最新創(chuàng)建的項目上。
于是就找.idea的文件夾,找到了這個http://218.76.35.75:20106/.idea/workspace.xml
然后就讀取function_crypt.php
發(fā)現(xiàn)沒什么有用的信息,于是看了下之前base64解出來的源代碼
[AppleScript]純文本查看復制代碼
1
$file=preg_replace("/[^a-zA-Z0-9.]+/","",$file);
正則匹配,不是a到z,A到Z,0到9和.的全刪
[AppleScript]純文本查看復制代碼
1
$file=str_replace("config","_",$file);
config換成_
然后就是這樣了
http://218.76.35.75:20106/index.php?image=functionconfigcrypt.php
查看源代碼,繼續(xù)解base64
[AppleScript]純文本查看復制代碼
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
*CreatedbyPhpStorm.
*User:pfv
*Date:2016/7/20
*Time:17:19
*/
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
$tmp .=chr(ord($txt[$i])+10);
}
$txt=$tmp;
$rnd=random(4);
$key=md5($rnd.$key);
$s=0;
for($i=0;$i
if($s==32)$s=0;
$ttmp .=$txt[$i]^$key[++$s];
}
returnbase64_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
if($s==32)$s=0;
$tmp .=$txt[$i]^$key[++$s];
}
for($i=0;$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"It's Works!";
}
最后通過解密代碼跑出flag,不懂,就到這兒了。
總結:
雖然我很菜,但是能跟許多大牛一起討論問題,即使拿不到flag,也學到了很多東西。社區(qū):i春秋
時間:2016年8月10日
作者:池寒
前言:
最近一個朋友組了個隊去打CTF,然后拉我去助他一臂之力(差人,拉我去打醬油。。。),然后我就去了。由于技術渣,只能旁觀。
過程:
0x01
有一道題很有有意思,好像是21題,貌似最后只有18個人做出來了。
額,沒錯,就是一個妹紙的照片,據(jù)說許多人盯著妹紙看了一天都沒做出來。
0x02
注意URL,發(fā)現(xiàn)可能是文件包含,這種URL表單
是filename,然后嘗試用讀取這個文件
http://218.76.35.75:20106/index.php?image=index.php
查看源代碼
明顯是base64,解碼得到:
<?php
/**
?* Created by PhpStorm.
?* User: pfven
?* Date: 2016/7/20
?* Time: 21:35
?*/
include 'header.php';if(isset($_GET["image"])){
????$file = $_GET['image'];
????$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/png;base64,".$txt."'></img>";
}else {
?????header("Location: index.php?image=heihei.jpg");
????exit();
}include 'footer.php';//***
發(fā)現(xiàn)是代碼泄漏
PhpStorm是一個php 的IDE。由于編輯器為了防止突然斷電,保存項目。都會建立自己的文件夾。
每個項目的配置存儲在項目所在目錄的 .idea 文件夾中,并以XML格式保存配置。如果你設置的是 “default project settings 默認項目設置”,那么這個默認設置將會自動應用到下一個最新創(chuàng)建的項目上。
于是就找.idea的文件夾,找到了這個http://218.76.35.75:20106/.idea/workspace.xml
然后就讀取function_crypt.php
發(fā)現(xiàn)沒什么有用的信息,于是看了下之前base64解出來的源代碼
$file = preg_replace("/[^a-zA-Z0-9.]+/","", $file);
正則匹配,不是a到z,A到Z,0到9和.的全刪
$file = str_replace("config","_", $file);
config換成_
然后就是這樣了
http://218.76.35.75:20106/index.php?image=functionconfigcrypt.php
查看源代碼,繼續(xù)解base64
<?php
/**
?* Created by PhpStorm.
?* User: pfv
?* Date: 2016/7/20
?* Time: 17:19
?*/
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 "It's Works!";
}最后通過解密代碼跑出flag,不懂,就到這兒了。
總結:
雖然我很菜,但是能跟許多大牛一起討論問題,即使拿不到flag,也學到了很多東西。