一CTF wbe题思路及解题过程

来源:http://bbs.ichunqiu.com/thread-9811-1-1.html?from=ch

社区:i春秋

时间:2016年8月10日

作者:池寒

前言:

最近一个朋友组了个队去打CTF,然后拉我去助他一臂之力(差人,拉我去打酱油。。。),然后我就去了。由于技术渣,只能旁观。过程:

0x01

有一道题很有有意思,好像是21题,貌似最后只有18个人做出来了。

额,没错,就是一个妹纸的照片,据说许多人盯着妹纸看了一天都没做出来。0x02

注意URL,发现可能是文件包含,这种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';

//***

发现是代码泄漏

PhpStorm是一个php 的IDE。由于编辑器为了防止突然断电,保存项目。都会建立自己的文件夹。

每个项目的配置存储在项目所在目录的 .idea 文件夹中,并以XML格式保存配置。如果你设置的是 “default project settings 默认项目设置”,那么这个默认设置将会自动应用到下一个最新创建的项目上。

于是就找.idea的文件夹,找到了这个http://218.76.35.75:20106/.idea/workspace.xml

然后就读取function_crypt.php

发现没什么有用的信息,于是看了下之前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

查看源代码,继续解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,也学到了很多东西。社区:i春秋


时间:2016年8月10日

作者:池寒


前言:


最近一个朋友组了个队去打CTF,然后拉我去助他一臂之力(差人,拉我去打酱油。。。),然后我就去了。由于技术渣,只能旁观。

过程:


0x01


有一道题很有有意思,好像是21题,貌似最后只有18个人做出来了。



额,没错,就是一个妹纸的照片,据说许多人盯着妹纸看了一天都没做出来。

0x02


注意URL,发现可能是文件包含,这种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
<?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';
//***


发现是代码泄漏


PhpStorm是一个php 的IDE。由于编辑器为了防止突然断电,保存项目。都会建立自己的文件夹。


每个项目的配置存储在项目所在目录的 .idea 文件夹中,并以XML格式保存配置。如果你设置的是 “default project settings 默认项目设置”,那么这个默认设置将会自动应用到下一个最新创建的项目上。


于是就找.idea的文件夹,找到了这个http://218.76.35.75:20106/.idea/workspace.xml



然后就读取function_crypt.php


发现没什么有用的信息,于是看了下之前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


查看源代码,继续解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
<?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,也学到了很多东西。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 个人学习批处理的初衷来源于实际工作;在某个迭代版本有个BS(安卓手游模拟器)大需求,从而在测试过程中就重复涉及到...
    Luckykailiu阅读 4,780评论 0 11
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,536评论 0 17
  • 在毕业之际,学生们开始慌了,为毕业论文担忧、为今后的路怎么走发愁。毕业之后有的选择继续读书,更多的还是选择就业。...
    茄子怪阅读 415评论 1 1
  • 早上下午军训,晚上就得去面试学生会。感觉自己被坑了。听师姐说学生会是一个勾心斗角尔虞我诈、嘻嘻哈哈的地方,说不如去...
    好馬不吃回头草阅读 205评论 0 0
  • 上周日是亲爱的月月生日,她叮嘱我们都不准带礼物去。阿蕾灵机一动,临摹了月月今年以来的部分朋友圈图文,虽然画的不好,...
    阿蕾阿蕾蕾阅读 312评论 0 1