|
| 1 | +# Vulnerable Python Test Application |
| 2 | + |
| 3 | +⚠️ **WARNING: This application contains intentional security vulnerabilities for testing and SBOM generation purposes only. DO NOT use in production!** |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +This project is designed to: |
| 8 | +- Generate Software Bill of Materials (SBOM) with vulnerable dependencies |
| 9 | +- Test vulnerability scanning tools across all severity levels |
| 10 | +- Demonstrate common security issues in Python applications |
| 11 | + |
| 12 | +## Vulnerabilities by Severity |
| 13 | + |
| 14 | +### 🔴 CRITICAL Severity (Score 9.0-10.0) |
| 15 | + |
| 16 | +#### Code Vulnerabilities: |
| 17 | +1. **Remote Code Execution via Pickle** (`/load_data`) |
| 18 | + - Insecure deserialization allows arbitrary code execution |
| 19 | + - CVSS: 10.0 |
| 20 | + |
| 21 | +2. **Arbitrary File Upload** (`/upload`) |
| 22 | + - No file type or content validation |
| 23 | + - Can lead to remote code execution |
| 24 | + - CVSS: 9.8 |
| 25 | + |
| 26 | +3. **Direct Code Execution via eval()** (`/calculate`) |
| 27 | + - User input passed directly to eval() |
| 28 | + - Complete system compromise possible |
| 29 | + - CVSS: 10.0 |
| 30 | + |
| 31 | +4. **YAML Deserialization RCE** (`/load_config`) |
| 32 | + - Unsafe YAML loading with arbitrary code execution |
| 33 | + - CVSS: 9.8 |
| 34 | + |
| 35 | +#### Dependency Vulnerabilities: |
| 36 | +- **Django 3.2.12** - CVE-2022-28346 (SQL Injection) - CVSS 9.8 |
| 37 | +- **Pillow 8.3.2** - CVE-2022-22817 (Buffer Overflow) - CVSS 9.8 |
| 38 | +- **paramiko 2.10.1** - CVE-2022-24302 (Auth bypass) - CVSS 9.8 |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +### 🟠 HIGH Severity (Score 7.0-8.9) |
| 43 | + |
| 44 | +#### Code Vulnerabilities: |
| 45 | +1. **SQL Injection** (`/user`) |
| 46 | + - Unparameterized SQL queries |
| 47 | + - Database compromise |
| 48 | + - CVSS: 8.8 |
| 49 | + |
| 50 | +2. **XML External Entity (XXE)** (`/parse_xml`) |
| 51 | + - Allows reading arbitrary files |
| 52 | + - CVSS: 8.2 |
| 53 | + |
| 54 | +3. **Server-Side Request Forgery** (`/fetch`) |
| 55 | + - Access to internal network resources |
| 56 | + - CVSS: 8.6 |
| 57 | + |
| 58 | +4. **OS Command Injection** (`/ping`) |
| 59 | + - Arbitrary system command execution |
| 60 | + - CVSS: 8.8 |
| 61 | + |
| 62 | +5. **Path Traversal** (`/read_file`) |
| 63 | + - Read arbitrary files from filesystem |
| 64 | + - CVSS: 7.5 |
| 65 | + |
| 66 | +6. **Hardcoded Secret Key** |
| 67 | + - Session hijacking possible |
| 68 | + - CVSS: 7.4 |
| 69 | + |
| 70 | +#### Dependency Vulnerabilities: |
| 71 | +- **Flask 2.0.0** - CVE-2023-30861 (Cookie parsing) - CVSS 7.5 |
| 72 | +- **requests 2.25.0** - CVE-2023-32681 (Header leak) - CVSS 6.1 |
| 73 | +- **Jinja2 2.11.3** - CVE-2024-22195 (XSS) - CVSS 6.1 |
| 74 | +- **lxml 4.6.3** - CVE-2021-43818 (XXE) - CVSS 7.1 |
| 75 | +- **PyYAML 5.3.1** - CVE-2020-14343 (Code execution) - CVSS 9.8 |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +### 🟡 MEDIUM Severity (Score 4.0-6.9) |
| 80 | + |
| 81 | +#### Code Vulnerabilities: |
| 82 | +1. **Cross-Site Scripting (XSS)** (`/search`) |
| 83 | + - Reflected XSS allows script injection |
| 84 | + - CVSS: 6.1 |
| 85 | + |
| 86 | +2. **Server-Side Template Injection** (`/hello`) |
| 87 | + - Can lead to information disclosure or RCE |
| 88 | + - CVSS: 6.5 |
| 89 | + |
| 90 | +3. **Missing CSRF Protection** (`/transfer`) |
| 91 | + - State-changing operations without tokens |
| 92 | + - CVSS: 6.5 |
| 93 | + |
| 94 | +4. **Insecure Session Management** (`/login`) |
| 95 | + - No secure or httponly flags |
| 96 | + - CVSS: 5.3 |
| 97 | + |
| 98 | +5. **Open Redirect** (`/redirect`) |
| 99 | + - Unvalidated redirects for phishing |
| 100 | + - CVSS: 4.7 |
| 101 | + |
| 102 | +6. **Debug Mode Enabled** |
| 103 | + - Exposes sensitive information |
| 104 | + - CVSS: 5.3 |
| 105 | + |
| 106 | +7. **Insecure Cookie Configuration** |
| 107 | + - Session hijacking risk |
| 108 | + - CVSS: 5.3 |
| 109 | + |
| 110 | +#### Dependency Vulnerabilities: |
| 111 | +- **Werkzeug 2.0.0** - CVE-2023-25577 (Security bypass) - CVSS 5.3 |
| 112 | +- **cryptography 3.3.1** - CVE-2023-23931 (Cipher weakness) - CVSS 6.5 |
| 113 | +- **certifi 2021.5.30** - CVE-2022-23491 (Cert validation) - CVSS 6.8 |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +### 🟢 LOW Severity (Score 0.1-3.9) |
| 118 | + |
| 119 | +#### Code Vulnerabilities: |
| 120 | +1. **Information Disclosure** (`/divide`) |
| 121 | + - Verbose error messages with stack traces |
| 122 | + - CVSS: 3.7 |
| 123 | + |
| 124 | +2. **Weak Password Requirements** (`/register`) |
| 125 | + - No complexity enforcement |
| 126 | + - CVSS: 3.1 |
| 127 | + |
| 128 | +3. **Missing Security Headers** (`/page`) |
| 129 | + - No X-Frame-Options, CSP, etc. |
| 130 | + - CVSS: 3.1 |
| 131 | + |
| 132 | +4. **Predictable Resource IDs** (`/invoice/<id>`) |
| 133 | + - Sequential IDs enable enumeration (IDOR) |
| 134 | + - CVSS: 3.5 |
| 135 | + |
| 136 | +5. **Verbose Server Banner** (`/info`) |
| 137 | + - Information disclosure |
| 138 | + - CVSS: 2.7 |
| 139 | + |
| 140 | +6. **CORS Misconfiguration** |
| 141 | + - Allows all origins |
| 142 | + - CVSS: 3.1 |
| 143 | + |
| 144 | +#### Dependency Vulnerabilities: |
| 145 | +- **urllib3 1.26.4** - CVE-2021-33503 (ReDoS) - CVSS 5.9 |
| 146 | +- **setuptools 56.0.0** - CVE-2022-40897 (ReDoS) - CVSS 5.9 |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +## Vulnerability Statistics |
| 151 | + |
| 152 | +- **Total Code Vulnerabilities**: 24 |
| 153 | + - Critical: 4 |
| 154 | + - High: 6 |
| 155 | + - Medium: 7 |
| 156 | + - Low: 7 |
| 157 | + |
| 158 | +- **Total Dependency CVEs**: 14 |
| 159 | + - Critical: 3 |
| 160 | + - High: 5 |
| 161 | + - Medium: 3 |
| 162 | + - Low: 2 |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## Authentication Module (auth.py) |
| 167 | + |
| 168 | +Additional vulnerabilities in the authentication module: |
| 169 | + |
| 170 | +1. **Hardcoded Credentials** (HIGH) - Default admin credentials in code |
| 171 | +2. **Weak Hashing** (MEDIUM) - MD5 used for password hashing |
| 172 | +3. **Insecure Deserialization** (CRITICAL) - Pickle vulnerability |
| 173 | +4. **Hardcoded Encryption Key** (HIGH) - Static encryption key |
| 174 | +5. **Insecure Random** (MEDIUM) - Using random instead of secrets for tokens |
| 175 | +6. **Path Traversal** (HIGH) - Unsanitized file path handling |
| 176 | +7. **Plaintext Password Storage** (HIGH) - Passwords stored without encryption |
| 177 | +8. **Timing Attack** (LOW) - Direct string comparison for authentication |
| 178 | + |
| 179 | +--- |
| 180 | + |
| 181 | +## Installation |
| 182 | + |
| 183 | +```bash |
| 184 | +pip install -r requirements.txt |
| 185 | +``` |
| 186 | + |
| 187 | +## Usage |
| 188 | + |
| 189 | +**DO NOT RUN THIS APPLICATION ON A PUBLIC NETWORK!** |
| 190 | + |
| 191 | +For testing purposes only: |
| 192 | + |
| 193 | +```bash |
| 194 | +python app.py |
| 195 | +``` |
| 196 | + |
| 197 | +The app will run on `http://0.0.0.0:5000` |
| 198 | + |
| 199 | +## Testing Endpoints |
| 200 | + |
| 201 | +### Critical Vulnerabilities |
| 202 | +- `POST /load_data` - Pickle deserialization |
| 203 | +- `POST /upload` - File upload |
| 204 | +- `GET /calculate?expr=1+1` - Code execution |
| 205 | +- `POST /load_config` - YAML deserialization |
| 206 | + |
| 207 | +### High Vulnerabilities |
| 208 | +- `GET /user?id=1` - SQL injection |
| 209 | +- `POST /parse_xml` - XXE injection |
| 210 | +- `GET /fetch?url=http://example.com` - SSRF |
| 211 | +- `GET /ping?host=localhost` - Command injection |
| 212 | +- `GET /read_file?file=readme.txt` - Path traversal |
| 213 | + |
| 214 | +### Medium Vulnerabilities |
| 215 | +- `GET /search?q=<script>alert(1)</script>` - XSS |
| 216 | +- `GET /hello?name={{7*7}}` - SSTI |
| 217 | +- `POST /transfer` - CSRF |
| 218 | +- `POST /login` - Insecure session |
| 219 | +- `GET /redirect?url=http://evil.com` - Open redirect |
| 220 | + |
| 221 | +### Low Vulnerabilities |
| 222 | +- `GET /divide?a=10&b=0` - Error disclosure |
| 223 | +- `POST /register` - Weak passwords |
| 224 | +- `GET /page` - Missing headers |
| 225 | +- `GET /invoice/123` - IDOR |
| 226 | +- `GET /info` - Information disclosure |
| 227 | + |
| 228 | +## SBOM Generation |
| 229 | + |
| 230 | +Generate SBOM using various tools: |
| 231 | + |
| 232 | +```bash |
| 233 | +# Using pip-audit |
| 234 | +pip-audit -r requirements.txt |
| 235 | + |
| 236 | +# Using CycloneDX |
| 237 | +cyclonedx-py -r -i requirements.txt -o sbom.json |
| 238 | + |
| 239 | +# Using Syft |
| 240 | +syft dir:. -o cyclonedx-json |
| 241 | + |
| 242 | +# Using SPDX |
| 243 | +pip install spdx-tools |
| 244 | +``` |
| 245 | + |
| 246 | +## Security Testing Tools |
| 247 | + |
| 248 | +Test this application with: |
| 249 | + |
| 250 | +### Static Analysis (SAST) |
| 251 | +```bash |
| 252 | +# Bandit |
| 253 | +bandit -r . -f json -o bandit_report.json |
| 254 | + |
| 255 | +# Semgrep |
| 256 | +semgrep --config=auto . |
| 257 | +``` |
| 258 | + |
| 259 | +### Dependency Scanning |
| 260 | +```bash |
| 261 | +# pip-audit |
| 262 | +pip-audit |
| 263 | + |
| 264 | +# Safety |
| 265 | +safety check |
| 266 | + |
| 267 | +# Grype |
| 268 | +grype dir:. |
| 269 | +``` |
| 270 | + |
| 271 | +### Dynamic Analysis (DAST) |
| 272 | +- OWASP ZAP |
| 273 | +- Burp Suite |
| 274 | +- Nikto |
| 275 | + |
| 276 | +## Legal Disclaimer |
| 277 | + |
| 278 | +This code is provided for **educational and testing purposes only**. The vulnerabilities are intentional and should **never** be deployed to production environments. Use at your own risk. |
| 279 | + |
| 280 | +## License |
| 281 | + |
| 282 | +This is demonstration code for security testing. No warranty provided. |
0 commit comments