來源:http://bbs.ichunqiu.com/thread-9811-1-1.html?from=ch
社區(qū):i春秋
時間:2016年8月10日
作者:池寒
前言:
最近一個朋友組了個隊去打CTF治宣,然后拉我去助他一臂之力(差人,拉我去打醬油砌滞。侮邀。。)布持,然后我就去了豌拙。由于技術(shù)渣,只能旁觀题暖。過程:
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主届,不懂,就到這兒了待德。
總結(jié):
雖然我很菜君丁,但是能跟許多大牛一起討論問題,即使拿不到flag将宪,也學到了很多東西绘闷。社區(qū):i春秋
時間:2016年8月10日
作者:池寒
前言:
最近一個朋友組了個隊去打CTF,然后拉我去助他一臂之力(差人较坛,拉我去打醬油印蔗。。丑勤。)华嘹,然后我就去了。由于技術(shù)渣法竞,只能旁觀耙厚。
過程:
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
=
base
64
_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
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
abcdefghijklmnopqrstuvwxyz'
)
{
????
$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
=
md
5
(
$rnd.$
key
)
;
????
$s
=
0
;
????
for
(
$i
=
0
;$i
<
strlen
(
$txt
)
;$i
+
+
)
{
????????
if
(
$s
=
=
32
)
$s
=
0
;
????????
$ttmp .
=
$txt[$i]
^
$
key
[
+
+
$s];
????
}
????
return
base
64
_encode
(
$rnd.$ttmp
)
;
}
function decrypt
(
$txt
,
$
key
)
{
????
$txt
=
base
64
_decode
(
$txt
)
;
????
$rnd
=
substr
(
$txt
,
0
,
4
)
;
????
$txt
=
substr
(
$txt
,
4
)
;
????
$
key
=
md
5
(
$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
+
+
)
{
????????
$tmp
1
.
=
chr
(
ord
(
$tmp[$i]
)
-10
)
;
????
}
????
return
$tmp
1
;
}
$username
=
decrypt
(
$_COOKIE['user']
,
$
key
)
;
if
(
$username
=
=
'system'
)
{
????
echo $flag;
}
else
{
????
setcookie
(
'user'
,
encrypt
(
'guest'
,
$
key
)
)
;
????
echo
"It's Works!"
;
}
最后通過解密代碼跑出flag贯要,不懂暖侨,就到這兒了。
總結(jié):
雖然我很菜崇渗,但是能跟許多大牛一起討論問題字逗,即使拿不到flag,也學到了很多東西宅广。