Skip to content

Commit 038465d

Browse files
committed
Implement Phase 2 security testing features: XSS detection, header security analysis, auth bypass testing, and parameter tampering detection
1 parent ee16929 commit 038465d

5 files changed

Lines changed: 697 additions & 34 deletions

File tree

README.md

Lines changed: 105 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The API Security Scanner performs automated security assessments of API endpoint
1515
- **HTTP Method Validation**
1616
- **Security Header Analysis**
1717
- **Parameter Tampering Detection**
18+
- **Cross-Site Scripting (XSS) Vulnerabilities**
19+
- **Authentication Bypass Testing**
1820

1921
Built with performance and reliability in mind, the scanner uses concurrent execution to efficiently test multiple endpoints simultaneously while providing detailed security reports.
2022

@@ -24,6 +26,10 @@ Built with performance and reliability in mind, the scanner uses concurrent exec
2426
- **Authentication Testing**: Validates basic auth credentials and identifies access control issues
2527
- **SQL Injection Detection**: Comprehensive payload-based testing for SQL injection vulnerabilities
2628
- **HTTP Method Validation**: Ensures proper HTTP method handling and prevents method-based attacks
29+
- **XSS Vulnerability Detection**: Tests for cross-site scripting vulnerabilities using common payloads
30+
- **Header Security Analysis**: Analyzes HTTP response headers for security issues
31+
- **Authentication Bypass Testing**: Tests for authentication vulnerabilities
32+
- **Parameter Tampering Detection**: Tests for parameter manipulation vulnerabilities
2733
- **Concurrent Execution**: High-performance parallel testing of multiple endpoints
2834
- **Detailed Reporting**: Comprehensive security assessments with risk analysis
2935

@@ -34,13 +40,6 @@ Built with performance and reliability in mind, the scanner uses concurrent exec
3440
- **Configurable Timeouts**: Prevents hanging requests with configurable timeouts
3541

3642
### 📊 Reporting & Output
37-
<<<<<<< HEAD
38-
- **Multiple Output Formats**: Text-based detailed reports
39-
- **Risk Assessment**: Automated risk scoring and remediation recommendations
40-
- **Comprehensive Logging**: Structured logging for debugging and audit purposes
41-
- **Score-based Metrics**: 100-point scoring system for security posture assessment
42-
43-
=======
4443
- **Multiple Output Formats**: Text, JSON, HTML, CSV, and XML output formats
4544
- **Risk Assessment**: Automated risk scoring and remediation recommendations
4645
- **Structured Logging**: Configurable logging with multiple formats (text, JSON)
@@ -51,7 +50,6 @@ Built with performance and reliability in mind, the scanner uses concurrent exec
5150
- **Rate Limiting**: Configurable request rate and concurrency limits
5251
- **Endpoint Reachability Testing**: Pre-flight validation of API endpoints
5352

54-
>>>>>>> feature/new-feature
5553
## 🛠️ Installation
5654

5755
### Prerequisites
@@ -100,14 +98,10 @@ docker run --rm -v $(pwd)/config.yaml:/app/config.yaml api-security-scanner
10098
| Option | Description | Default |
10199
|--------|-------------|---------|
102100
| `-config` | Path to configuration file | `config.yaml` |
103-
<<<<<<< HEAD
104-
| `-output` | Output format (text, json) | `text` |
105-
=======
106101
| `-output` | Output format (text, json, html, csv, xml) | `text` |
107102
| `-validate` | Validate configuration only, don't run tests | `false` |
108103
| `-log-level` | Log level (debug, info, warn, error) | `info` |
109104
| `-log-format` | Log format (text, json) | `text` |
110-
>>>>>>> feature/new-feature
111105
| `-timeout` | Request timeout in seconds | `10` |
112106
| `-verbose` | Enable verbose logging | `false` |
113107

@@ -135,14 +129,22 @@ injection_payloads:
135129
- "'; DROP TABLE users;--"
136130
- "1' OR '1'='1"
137131
- "admin'--"
138-
<<<<<<< HEAD
139-
=======
132+
133+
# XSS test payloads
134+
xss_payloads:
135+
- "<script>alert('XSS')</script>"
136+
- "'><script>alert('XSS')</script>"
137+
- "<img src=x onerror=alert('XSS')>"
140138

141139
# Rate limiting configuration
142140
rate_limiting:
143141
requests_per_second: 10
144142
max_concurrent_requests: 5
145-
>>>>>>> feature/new-feature
143+
144+
# Custom headers
145+
headers:
146+
"User-Agent": "API-Security-Scanner/1.0"
147+
"X-Scanner": "true"
146148
```
147149
148150
## 📋 Configuration Reference
@@ -172,7 +174,25 @@ injection_payloads:
172174
- "'; DROP TABLE users;--" # SQL DROP statement
173175
- "1' OR '1'='1" # Numeric SQL injection
174176
- "admin'--" # Comment-based SQL injection
175-
- "<script>alert('XSS')</script>" # XSS payload (if testing web APIs)
177+
```
178+
179+
### XSS Payloads Configuration
180+
181+
```yaml
182+
xss_payloads:
183+
- "<script>alert('XSS')</script>" # Basic script tag injection
184+
- "'><script>alert('XSS')</script>" # Attribute breaking injection
185+
- "<img src=x onerror=alert('XSS')>" # Image tag injection
186+
- "javascript:alert('XSS')" # JavaScript URI injection
187+
```
188+
189+
### Headers Configuration
190+
191+
```yaml
192+
headers:
193+
"User-Agent": "API-Security-Scanner/2.0"
194+
"X-Test-Header": "test-value"
195+
"Accept": "application/json"
176196
```
177197
178198
## 📊 Sample Output
@@ -192,26 +212,45 @@ Test Results:
192212
Details: Method validation successful
193213
- Injection Test: PASSED
194214
Details: No injection vulnerabilities detected
215+
- XSS Test: PASSED
216+
Details: No XSS vulnerabilities detected
217+
- Header Security Test: PASSED
218+
Details: All security headers present
219+
- Auth Bypass Test: PASSED
220+
Details: Authentication properly enforced
221+
- Parameter Tampering Test: PASSED
222+
Details: Parameter validation successful
195223

196224
Risk Assessment:
197225
No significant risks detected.
198226

199227
Endpoint: https://api.example.com/v1/data
200-
Overall Score: 50/100
228+
Overall Score: 25/100
201229
Test Results:
202230
- Auth Test: PASSED
203231
Details: Authentication successful
204232
- HTTP Method Test: PASSED
205233
Details: Method validation successful
206234
- Injection Test: FAILED
207235
Details: Potential SQL injection detected with payload: ' OR '1'='1
236+
- XSS Test: FAILED
237+
Details: Potential XSS detected with payload: <script>alert('XSS')</script>
238+
- Header Security Test: FAILED
239+
Details: Missing security headers: X-Frame-Options, X-Content-Type-Options
240+
- Auth Bypass Test: FAILED
241+
Details: Endpoint accessible without authentication
242+
- Parameter Tampering Test: PASSED
243+
Details: Parameter validation successful
208244

209245
Risk Assessment:
210246
- SQL injection vulnerabilities pose a significant data breach risk.
247+
- Cross-site scripting vulnerabilities could allow malicious script execution.
248+
- Insecure headers may expose sensitive information or lack security protections.
249+
- Authentication bypass vulnerabilities could allow unauthorized access to protected resources.
211250

212251
Overall Security Assessment:
213-
Average Security Score: 75/100
214-
Critical Vulnerabilities Detected: 1
252+
Average Security Score: 62/100
253+
Critical Vulnerabilities Detected: 2
215254

216255
Moderate security risks detected. Address identified vulnerabilities promptly.
217256
```
@@ -224,6 +263,10 @@ The scanner uses a 100-point scoring system:
224263
- **Authentication Failure**: -30 points
225264
- **HTTP Method Failure**: -20 points
226265
- **Injection Vulnerability**: -50 points
266+
- **XSS Vulnerability**: -40 points
267+
- **Header Security Issues**: -25 points
268+
- **Auth Bypass Vulnerability**: -35 points
269+
- **Parameter Tampering Vulnerability**: -30 points
227270

228271
### Risk Levels
229272

@@ -263,6 +306,42 @@ The scanner validates HTTP method handling by:
263306
3. Checking for method-based access control issues
264307
4. Ensuring REST compliance
265308

309+
### XSS Vulnerability Testing
310+
311+
The scanner tests for XSS vulnerabilities by:
312+
313+
1. Sending baseline requests to establish normal response patterns
314+
2. Testing with various XSS payloads
315+
3. Analyzing response content for unsanitized payload reflection
316+
4. Looking for indicators of successful XSS execution
317+
318+
### Header Security Analysis
319+
320+
The scanner analyzes HTTP response headers by:
321+
322+
1. Checking for presence of recommended security headers
323+
2. Identifying insecure information disclosure headers
324+
3. Validating cookie security attributes
325+
4. Analyzing CORS policy configurations
326+
327+
### Authentication Bypass Testing
328+
329+
The scanner tests for authentication bypass by:
330+
331+
1. Sending requests without authentication credentials
332+
2. Testing with invalid credentials
333+
3. Checking for common bypass headers
334+
4. Analyzing response codes for unauthorized access
335+
336+
### Parameter Tampering Detection
337+
338+
The scanner tests for parameter tampering by:
339+
340+
1. Modifying parameter values in requests
341+
2. Adding extra parameters to requests
342+
3. Testing for IDOR (Insecure Direct Object Reference)
343+
4. Analyzing response behavior for parameter changes
344+
266345
## 🔧 Advanced Configuration
267346

268347
### Rate Limiting
@@ -412,16 +491,16 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
412491
- [x] Concurrent execution
413492
- [x] Detailed reporting
414493

415-
### Phase 2: Enhanced Testing (Planned)
416-
- [ ] XSS vulnerability detection
417-
- [ ] NoSQL injection testing
418-
- [ ] Security header analysis
419-
- [ ] Rate limiting and throttling
494+
### Phase 2: Enhanced Testing
495+
- [x] XSS vulnerability detection
496+
- [x] Security header analysis
497+
- [x] Authentication bypass testing
498+
- [x] Parameter tampering detection
420499

421500
### Phase 3: Advanced Features (Planned)
501+
- [ ] NoSQL injection testing
422502
- [ ] OpenAPI/Swagger integration
423503
- [ ] API discovery and crawling
424-
- [ ] Multiple output formats (JSON, XML, HTML)
425504
- [ ] Historical comparison and trending
426505

427506
### Phase 4: Enterprise Features (Planned)
@@ -435,8 +514,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
435514
**Made with ❤️ for the security community**
436515

437516
[![Star on GitHub](https://img.shields.io/github/stars/elliotsecops/API-Security-Scanner.svg?style=social&label=Star)](https://github.com/elliotsecops/API-Security-Scanner)
438-
<<<<<<< HEAD
439-
[![Fork on GitHub](https://img.shields.io/github/forks/elliotsecops/API-Security-Scanner.svg?style=social&label=Fork)](https://github.com/elliotsecops/API-Security-Scanner)
440-
=======
441-
[![Fork on GitHub](https://img.shields.io/github/forks/elliotsecops/API-Security-Scanner.svg?style=social&label=Fork)](https://github.com/elliotsecops/API-Security-Scanner)
442-
>>>>>>> feature/new-feature
517+
[![Fork on GitHub](https://img.shields.io/github/forks/elliotsecops/API-Security-Scanner.svg?style=social&label=Fork)](https://github.com/elliotsecops/API-Security-Scanner)

config-test.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ injection_payloads:
1313
- "' OR '1'='1"
1414
- "'; DROP TABLE users;--"
1515

16+
xss_payloads:
17+
- "<script>alert('XSS')</script>"
18+
- "'><script>alert('XSS')</script>"
19+
- "<img src=x onerror=alert('XSS')>"
20+
- "javascript:alert('XSS')"
21+
22+
headers:
23+
"User-Agent": "API-Security-Scanner/1.0"
24+
"X-Scanner": "true"
25+
1626
rate_limiting:
1727
requests_per_second: 5
1828
max_concurrent_requests: 3

config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ injection_payloads:
1313
- "' OR '1'='1"
1414
- "'; DROP TABLE users;--"
1515

16+
xss_payloads:
17+
- "<script>alert('XSS')</script>"
18+
- "'><script>alert('XSS')</script>"
19+
- "<img src=x onerror=alert('XSS')>"
20+
- "javascript:alert('XSS')"
21+
22+
headers:
23+
"User-Agent": "API-Security-Scanner/1.0"
24+
"X-Scanner": "true"
25+
1626
rate_limiting:
1727
requests_per_second: 10
1828
max_concurrent_requests: 5

config/config.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ func Validate(config *scanner.Config) error {
6565
return fmt.Errorf("both username and password are required for authentication, or neither")
6666
}
6767

68+
// Set default XSS payloads if none provided
69+
if len(config.XSSPayloads) == 0 {
70+
config.XSSPayloads = []string{
71+
"<script>alert('XSS')</script>",
72+
"'><script>alert('XSS')</script>",
73+
"<img src=x onerror=alert('XSS')>",
74+
"javascript:alert('XSS')",
75+
}
76+
}
77+
6878
return nil
6979
}
7080

0 commit comments

Comments
 (0)