@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,881 @@
1
+ <!-- aegis-local: forked 2026-04-23 from SnailSploit/Claude-Red@c74d53e2938b59f111572e0819265a1e73029393; attribution preserved, see ATTRIBUTION.md -->
2
+
3
+ # SKILL: Race Conditions
4
+
5
+ ## Metadata
6
+ - **Skill Name**: race-condition
7
+ - **Folder**: offensive-race-condition
8
+ - **Source**: https://github.com/SnailSploit/offensive-checklist/blob/main/race-condition.md
9
+
10
+ ## Description
11
+ Race condition (TOCTOU) testing checklist: identifying timing windows, Burp Suite Turbo Intruder, Last-Byte sync technique, rate limit bypass, double-spend attacks, and concurrent request exploitation. Use for web app race condition testing or bug bounty time-of-check-to-time-of-use bugs.
12
+
13
+ ## Trigger Phrases
14
+ Use this skill when the conversation involves any of:
15
+ `race condition, TOCTOU, timing attack, Turbo Intruder, last-byte sync, rate limit bypass, double spend, concurrent request, race window, time of check, time of use`
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
+ # Race Conditions
31
+
32
+ ## Shortcut
33
+
34
+ - Spot the features prone to race conditions in the target application and copy the corresponding requests.
35
+ - Send multiple of these critical requests to the server simultaneously. You should craft requests that should be allowed once but not allowed multiple times.
36
+ - Check the results to see if your attack has succeeded. And try to execute the attack multiple times to maximize the chance of success.
37
+ - Consider the impact of the race condition you just found.
38
+
39
+ ## Mechanisms
40
+
41
+ Race conditions occur when the behavior of a system depends on the relative timing or sequence of events that can happen in different orders. In web application security, race conditions happen when multiple concurrent processes or threads access and manipulate the same resource simultaneously without proper synchronization.
42
+
43
+ ```mermaid
44
+ sequenceDiagram
45
+ participant Thread1 as Thread 1
46
+ participant Resource
47
+ participant Thread2 as Thread 2
48
+
49
+ Thread1->>Resource: Read value (100)
50
+ Thread2->>Resource: Read value (100)
51
+ Thread1->>Thread1: Calculate new value (100-10=90)
52
+ Thread2->>Thread2: Calculate new value (100-10=90)
53
+ Thread1->>Resource: Write new value (90)
54
+ Thread2->>Resource: Write new value (90)
55
+ Note over Resource: Expected final value: 80<br/>Actual final value: 90
56
+ ```
57
+
58
+ A race condition becomes a security vulnerability when it affects security controls or business logic. The critical types include:
59
+
60
+ - Time-of-Check to Time-of-Use (TOCTOU): When a check is performed, but circumstances change before the result of the check is used
61
+ - Read-Modify-Write: When multiple processes read, modify, and write back a shared resource without coordination
62
+ - Thread Safety Issues: When multithreaded applications improperly handle shared resources
63
+ - Resource Allocation Races: Competition for limited resources like database connections or memory
64
+
65
+ ```mermaid
66
+ graph TD
67
+ subgraph "Common Race Condition Types"
68
+ A[Race Conditions] --> B[TOCTOU]
69
+ A --> C[Read-Modify-Write]
70
+ A --> D[Thread Safety Issues]
71
+ A --> E[Resource Allocation]
72
+
73
+ B --> B1["Check balance, then debit"]
74
+ C --> C1["Update counter or balance"]
75
+ D --> D1["Shared cache or session data"]
76
+ E --> E1["Limited coupon or inventory"]
77
+ end
78
+ ```
79
+
80
+ Common vulnerable scenarios include:
81
+
82
+ - Account Balance Manipulation: Making multiple withdrawals/transfers simultaneously
83
+ - Coupon/Promotion Code Reuse: Using a single-use code multiple times
84
+ - File Upload Processing: Uploading and accessing temporary files before validation completes
85
+ - Registration Processes: Creating multiple accounts with the same unique identifier
86
+ - Token Verification: Using authentication tokens multiple times before they're invalidated
87
+
88
+ ## Hunt
89
+
90
+ ### Identifying Race Condition Vulnerabilities
91
+
92
+ #### Target Functionality Selection
93
+
94
+ Focus on features handling state changes, limited resources, or critical operations:
95
+
96
+ - Financial Transactions: Fund transfers, withdrawals, purchases
97
+ - Inventory Systems: Stock allocation, reservation systems
98
+ - Coupon/Points Systems: Redeeming coupons, points, or rewards
99
+ - Voting/Rating Systems: Likes, upvotes, downvotes, polls
100
+ - Membership/Subscription Actions: Inviting users, joining/leaving groups, following/unfollowing users
101
+ - Registration Systems: Account creation with unique attributes
102
+ - Resource Management: Uploading, processing, or accessing resources
103
+ - Rate-Limited Actions: Password resets, login attempts, API endpoints with usage limits
104
+
105
+ #### Testing Prerequisites
106
+
107
+ 1. Tools for sending parallel requests:
108
+ - Burp Suite Turbo Intruder or Repeater (multi-threaded)
109
+ - Custom scripts with threading capabilities
110
+ - Race condition testing frameworks (e.g., Racepwn)
111
+
112
+ 2. Request capturing and analysis capabilities:
113
+ - HTTP proxy for intercepting and modifying traffic
114
+ - Response analysis tools for detecting race-related anomalies
115
+
116
+ 3. Network Proximity: Consider the physical or network location of your testing infrastructure relative to the target server. Minimizing latency (e.g., using a VPS in the same region/provider as the target) can significantly increase the chances of winning a race condition.
117
+
118
+ #### Testing Methodology
119
+
120
+ ```mermaid
121
+ flowchart TD
122
+ A[Race Condition Testing] --> B[Baseline Analysis]
123
+ A --> C[Race Condition Detection]
124
+ A --> D[Timing Manipulation]
125
+ A --> E[Proof of Concept]
126
+
127
+ B --> B1[Identify state-changing operations]
128
+ B --> B2[Document normal transaction flow]
129
+
130
+ C --> C1[Send identical requests simultaneously]
131
+ C --> C2[Observe state changes]
132
+
133
+ D --> D1[Identify critical timing windows]
134
+ D --> D2[Vary delays between requests]
135
+
136
+ E --> E1[Create reproducible exploit]
137
+ E --> E2[Document impact scenarios]
138
+ ```
139
+
140
+ 1. Baseline Behavior Analysis:
141
+ - Identify state-changing operations
142
+ - Understand normal request/response patterns
143
+ - Document application's standard transaction flow
144
+
145
+ 2. Race Condition Detection:
146
+ - Send identical requests simultaneously (10-100 threads)
147
+ - Observe effects on application state
148
+ - Look for anomalies in responses or state changes
149
+
150
+ 3. Timing Manipulation:
151
+ - Identify critical timing windows
152
+ - Target synchronization points
153
+ - Test with varying delays between requests
154
+
155
+ ### Advanced Testing Techniques
156
+
157
+ #### API-Based Race Condition Testing
158
+
159
+ 1. Identify stateful API endpoints
160
+ 2. Create automated scripts for parallel API requests:
161
+
162
+ ```python
163
+ import requests
164
+ import threading
165
+
166
+ def make_request():
167
+ requests.post('https://target.com/api/redeem',
168
+ json={'coupon_code': 'ONCE123'},
169
+ headers={'Authorization': 'Bearer token'})
170
+
171
+ threads = []
172
+ for _ in range(20):
173
+ t = threading.Thread(target=make_request)
174
+ threads.append(t)
175
+ t.start()
176
+
177
+ for t in threads:
178
+ t.join()
179
+ ```
180
+
181
+ #### Transaction-Based Race Condition Testing
182
+
183
+ 1. Identify multi-step transactions
184
+ 2. Find the critical state change requests
185
+ 3. Execute the final step in parallel before state updates propagate:
186
+ ```
187
+ Step 1: Start purchase (single request)
188
+ Step 2: Apply coupon (single request)
189
+ Step 3: Send 20 simultaneous "confirm order" requests
190
+ ```
191
+
192
+ #### Thread Synchronization Testing
193
+
194
+ Create coordinated attacks that target specific timing windows:
195
+
196
+ ```python
197
+ import requests
198
+ import threading
199
+ import time
200
+
201
+ start_gate = threading.Event()
202
+
203
+ def synchronized_request():
204
+ start_gate.wait() # All threads wait here until flag is set
205
+ requests.post('https://target.com/api/withdraw',
206
+ json={'amount': '100'},
207
+ headers={'Authorization': 'Bearer token'})
208
+
209
+ threads = []
210
+ for _ in range(50):
211
+ t = threading.Thread(target=synchronized_request)
212
+ t.daemon = True
213
+ threads.append(t)
214
+ t.start()
215
+
216
+ # Release all threads simultaneously
217
+ time.sleep(2) # Ensure all threads are waiting
218
+ start_gate.set()
219
+ ```
220
+
221
+ #### Network-Level Timing Manipulation
222
+
223
+ Beyond application-level threading, manipulating network-level timing can be effective:
224
+
225
+ - **HTTP/2 / HTTP/3 Single-Packet & Last-Byte-Sync Techniques**: Classic HTTP/1.1 pipelining is disabled on most servers. Modern testers rely on HTTP/2 multiplexing or HTTP/3 streams to achieve micro-second concurrency. Burp Repeater (2023.9+) and Turbo Intruder expose this as _Send group in parallel (single-packet attack)_.
226
+ - **Last-Byte-Sync / Request Splitting**: Open multiple connections, send almost-complete requests, then flush the final bytes simultaneously. In Burp, send each tab using the _single packet attack_ gate; or in Turbo Intruder:
227
+
228
+ ```python
229
+ def queueRequests(target, wordlists):
230
+ engine = RequestEngine(
231
+ endpoint=target.endpoint,
232
+ concurrentConnections=1,
233
+ engine=Engine.BURP2)
234
+
235
+ for _ in range(20):
236
+ engine.queue(target.req, gate='race')
237
+
238
+ engine.openGate('race')
239
+ ```
240
+
241
+ #### Rate-Limiter and CAPTCHA Races
242
+
243
+ - Send concurrent login or OTP requests across multiple sessions/IPs to probe shared counters.
244
+ - Look for global vs per-user vs per-IP buckets; test burst vs sustained patterns.
245
+
246
+ ## Vulnerabilities
247
+
248
+ ### Common Race Condition Vulnerability Patterns
249
+
250
+ ```mermaid
251
+ graph LR
252
+ subgraph "Race Condition Vulnerability Impacts"
253
+ A[Race Conditions] --> B[Financial Systems]
254
+ A --> C[Account & Authentication]
255
+ A --> D[Resource Management]
256
+ A --> E[Application-Specific]
257
+ A --> F[Rate Limiting & Anti-Automation]
258
+
259
+ B --> B1[Double Withdrawal]
260
+ B --> B2[Transaction Rollback Abuse]
261
+
262
+ C --> C1[Multiple Account Creation]
263
+ C --> C2[Token Reuse]
264
+ C --> C3[MFA Bypass]
265
+
266
+ D --> D1[Upload-Download Race]
267
+ D --> D2[Resource Over-allocation]
268
+
269
+ E --> E1[Shopping Cart Race]
270
+ E --> E2[Auction Sniping]
271
+ F --> F1[OTP/Reset Code Reuse]
272
+ F --> F2[CAPTCHA Reuse]
273
+ end
274
+ ```
275
+
276
+ #### Financial Systems Vulnerabilities
277
+
278
+ - Double Withdrawal: Processing the same withdrawal request twice
279
+ - Transaction Rollback Abuse: Initiating a transaction rollback while completing the transaction
280
+ - Balance Check Bypass: Racing between balance verification and transaction processing
281
+
282
+ #### Account and Authentication Vulnerabilities
283
+
284
+ - Multiple Account Creation: Creating accounts with the same unique identifier
285
+ - Token Reuse: Using one-time tokens multiple times
286
+ - Session Fixation Race: Racing between session creation and authentication
287
+ - MFA Bypass: Racing between MFA checks and authenticated resource access
288
+
289
+ #### Resource Management Vulnerabilities
290
+
291
+ - Upload-Download Race: Accessing uploaded files before security checks complete
292
+ - Resource Allocation Race: Over-allocating limited resources
293
+ - Temporary File Races: Operating on temporary files during processing
294
+
295
+ #### Specific Application Patterns
296
+
297
+ - Shopping Cart Race Conditions: Adding items at specific discount windows
298
+ - Auction Sniping Race: Timing bids to bypass minimum increments
299
+ - Reservation System Races: Double-booking limited inventory
300
+
301
+ ### Time-Sensitive Vulnerabilities
302
+
303
+ 1. Send parallel password reset requests for the same account
304
+ 2. Check if reset tokens are identical
305
+ 3. Test by changing victim's username in one request
306
+ 4. Analyze response times for potential race conditions
307
+
308
+ ### Session Handling Bypass
309
+
310
+ Some application frameworks (like PHP with default session handling) lock session files when `session_start()` is called, preventing concurrent requests from the _same_ session from executing simultaneously. If the application allows a user to have multiple active sessions, this can be bypassed:
311
+
312
+ 1. Authenticate multiple times to obtain several valid session identifiers (e.g., `PHPSESSID`).
313
+ 2. Assign a unique session ID to each concurrent request in your race condition attack. This makes the server treat each request as originating from a different session, circumventing the session lock.
314
+
315
+ ### Database Isolation Level Testing
316
+
317
+ Different database isolation levels handle concurrency differently. Test each level to identify race vulnerabilities:
318
+
319
+ **PostgreSQL Isolation Levels:**
320
+
321
+ ```sql
322
+ -- READ UNCOMMITTED (treats as READ COMMITTED in PostgreSQL)
323
+ BEGIN TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
324
+
325
+ -- READ COMMITTED (default) - prone to races
326
+ BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
327
+ SELECT balance FROM accounts WHERE id = 123;
328
+ -- Race window here
329
+ UPDATE accounts SET balance = balance - 100 WHERE id = 123;
330
+ COMMIT;
331
+
332
+ -- REPEATABLE READ - prevents some races
333
+ BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;
334
+
335
+ -- SERIALIZABLE - strongest protection
336
+ BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
337
+ ```
338
+
339
+ **Testing Strategy:**
340
+
341
+ 1. Identify critical transactions in the application
342
+ 2. Send concurrent requests during the transaction window
343
+ 3. Check if inconsistent state occurs
344
+ 4. Test with explicit table locking:
345
+ ```sql
346
+ SELECT * FROM table FOR UPDATE; -- Row-level lock
347
+ LOCK TABLE table IN EXCLUSIVE MODE; -- Table-level lock
348
+ ```
349
+
350
+ **MySQL/MariaDB:**
351
+
352
+ ```sql
353
+ -- Test for missing row locks
354
+ START TRANSACTION;
355
+ SELECT balance FROM accounts WHERE id = 123;
356
+ -- Send parallel transactions here
357
+ UPDATE accounts SET balance = balance - 100 WHERE id = 123;
358
+ COMMIT;
359
+
360
+ -- Test with explicit locking
361
+ SELECT * FROM accounts WHERE id = 123 FOR UPDATE;
362
+ ```
363
+
364
+ **Testing for Advisory Locks:**
365
+
366
+ ```sql
367
+ -- PostgreSQL advisory locks
368
+ SELECT pg_try_advisory_lock(12345);
369
+
370
+ -- Test if application uses them
371
+ -- Send parallel requests and monitor pg_locks table
372
+ SELECT * FROM pg_locks WHERE locktype = 'advisory';
373
+ ```
374
+
375
+ ### WebSocket Race Conditions
376
+
377
+ WebSocket connections maintain persistent state and can be vulnerable to race conditions:
378
+
379
+ **Message Processing Races:**
380
+
381
+ ```javascript
382
+ // Send concurrent WebSocket messages
383
+ const ws = new WebSocket("wss://target.com/socket");
384
+
385
+ ws.onopen = () => {
386
+ // Send multiple messages rapidly
387
+ for (let i = 0; i < 50; i++) {
388
+ ws.send(
389
+ JSON.stringify({
390
+ action: "transfer",
391
+ amount: 100,
392
+ to: "attacker",
393
+ }),
394
+ );
395
+ }
396
+ };
397
+ ```
398
+
399
+ **Connection Upgrade Races:**
400
+
401
+ ```bash
402
+ # Multiple simultaneous WebSocket handshakes
403
+ for i in {1..20}; do
404
+ curl -i -N \
405
+ -H "Connection: Upgrade" \
406
+ -H "Upgrade: websocket" \
407
+ -H "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
408
+ -H "Sec-WebSocket-Version: 13" \
409
+ https://target.com/socket &
410
+ done
411
+ wait
412
+ ```
413
+
414
+ **Testing Scenarios:**
415
+
416
+ - Concurrent authentication messages
417
+ - Simultaneous room/channel joins
418
+ - Parallel state-changing commands
419
+ - Race between disconnect and final message processing
420
+
421
+ ### Cloud & Serverless Race Conditions
422
+
423
+ #### AWS Lambda Specific
424
+
425
+ **Concurrent Execution Testing:**
426
+
427
+ ```python
428
+ import boto3
429
+ import concurrent.futures
430
+
431
+ lambda_client = boto3.client('lambda')
432
+
433
+ def invoke_lambda():
434
+ return lambda_client.invoke(
435
+ FunctionName='vulnerable-function',
436
+ InvocationType='RequestResponse',
437
+ Payload='{"action": "redeem_coupon", "code": "SAVE50"}'
438
+ )
439
+
440
+ # Test concurrent invocations
441
+ with concurrent.futures.ThreadPoolExecutor(max_workers=50) as executor:
442
+ futures = [executor.submit(invoke_lambda) for _ in range(50)]
443
+ results = [f.result() for f in futures]
444
+ ```
445
+
446
+ **Reserved Concurrency Bypass:**
447
+
448
+ - Check if Lambda has reserved concurrency limits
449
+ - Test if multiple accounts/regions bypass limits
450
+ - Monitor CloudWatch for ConcurrentExecutions metric
451
+
452
+ **DynamoDB Conditional Write Testing:**
453
+
454
+ ```python
455
+ import boto3
456
+ from boto3.dynamodb.conditions import Attr
457
+
458
+ dynamodb = boto3.resource('dynamodb')
459
+ table = dynamodb.Table('coupons')
460
+
461
+ # Test if conditional writes are used
462
+ def redeem_coupon():
463
+ table.update_item(
464
+ Key={'code': 'SAVE50'},
465
+ UpdateExpression='SET used = :val',
466
+ ConditionExpression=Attr('used').eq(False), # Should prevent races
467
+ ExpressionAttributeValues={':val': True}
468
+ )
469
+ ```
470
+
471
+ #### GCP Cloud Functions
472
+
473
+ **Concurrent Trigger Testing:**
474
+
475
+ ```bash
476
+ # Test HTTP-triggered Cloud Functions
477
+ for i in {1..50}; do
478
+ curl -X POST https://region-project.cloudfunctions.net/function \
479
+ -H "Content-Type: application/json" \
480
+ -d '{"action": "claim_reward"}' &
481
+ done
482
+ wait
483
+ ```
484
+
485
+ #### Azure Functions
486
+
487
+ **Singleton Testing:**
488
+
489
+ ```csharp
490
+ // Check if Azure Functions use Singleton attribute
491
+ [Singleton] // Should prevent concurrent execution
492
+ public static void Run([QueueTrigger("queue")] string msg) { }
493
+ ```
494
+
495
+ ### Protocol-specific attack primitives
496
+
497
+ - **Single-Packet Attack (HTTP/2)** and **Last-Byte-Sync (HTTP/1)** research (PortSwigger Black Hat 2023) enables ≤ 4 µs request skew; both are now directly supported in Burp Repeater and Turbo Intruder.
498
+
499
+ ### GraphQL & gRPC considerations
500
+
501
+ - GraphQL batch mutations can bypass conventional CSRF and rate-limit controls. Replay a single POST body containing 20 identical mutations to test for duplicated state changes.
502
+ - For gRPC, open multiple concurrent `SendMsg` frames before the backend commits state.
503
+
504
+ ### Cloud & serverless concurrency
505
+
506
+ - Serverless functions (AWS Lambda, GCP Cloud Run, Azure Functions) may process the same event in parallel. Mitigate with idempotency keys or reserved-concurrency settings.
507
+
508
+ ### Observability & detection
509
+
510
+ - Enable distributed tracing (OpenTelemetry, Jaeger) and emit duplicate-call metrics within the same trace span to surface race-condition symptoms.
511
+
512
+ ### Modern defensive patterns
513
+
514
+ - Use atomic **UPSERT / ON CONFLICT** statements for write-once semantics.
515
+ - Implement **Idempotency-Key** headers (IETF draft 2024) with short-TTL storage.
516
+ - Employ Redis/etcd Redlock or PostgreSQL advisory locks for cross-service resource locking.
517
+
518
+ ### Additional resources
519
+
520
+ - PortSwigger white-paper _Smashing the State Machine_ + labs (Black Hat 2023).
521
+ - OWASP ASVS v5 (2024) section 7.6 "Concurrency Controls".
522
+
523
+ ## Impact Assessment
524
+
525
+ #### Critical Impact Scenarios
526
+
527
+ - **Financial Loss**: Double spending, incorrect account balances
528
+ - **Privilege Escalation**: Bypassing authentication or authorization
529
+ - **Data Integrity Violations**: Corrupting database state
530
+ - **Denial of Service**: Exhausting limited resources
531
+ - **Information Disclosure**: Accessing partially processed data
532
+
533
+ #### Example Exploits
534
+
535
+ 1. **Banking Application Double-Withdrawal**:
536
+ - Initial balance: $1000
537
+ - Send 10 simultaneous withdrawal requests for $100 each
538
+ - Result: $1000 debited but balance only decreases once
539
+ 2. **E-commerce Coupon Reuse**:
540
+ - Single-use coupon provides $50 discount
541
+ - Send 5 parallel requests using the same coupon
542
+ - Result: Multiple $50 discounts applied
543
+
544
+ 3. **Account Registration Email Verification Bypass**:
545
+ - Send multiple verification requests with different tokens
546
+ - Race between verification and account provision
547
+ - Result: Account verified without valid email
548
+
549
+ ## Methodologies
550
+
551
+ ### Tools
552
+
553
+ #### Race Condition Testing Tools
554
+
555
+ - **Burp Suite Extensions**:
556
+ - Turbo Intruder: High-volume parallel request sender.
557
+ - Authorize: Manipulation of tokens/session data
558
+ - Collaborator: For detecting out-of-band effects
559
+
560
+ - **Specialized Tools**:
561
+ - Racepwn: Purpose-built race condition testing framework
562
+ - Race-the-Web: Web application race condition finder
563
+ - Raceocat: CLI scanner that replays raw-socket requests for µs-precision
564
+ - URL-Race-Condition-Scanner: Generates and races endpoints from Burp history
565
+ - OWASP ZAP with parallel request scripts
566
+
567
+ #### Custom Scripting
568
+
569
+ - **Python with Threading/Asyncio**:
570
+
571
+ ```python
572
+ import asyncio
573
+ import aiohttp
574
+
575
+ async def make_request(session):
576
+ async with session.post('https://target.com/api/action',
577
+ data={'param': 'value'}) as response:
578
+ return await response.text()
579
+
580
+ async def main():
581
+ async with aiohttp.ClientSession() as session:
582
+ tasks = [make_request(session) for _ in range(50)]
583
+ responses = await asyncio.gather(*tasks)
584
+ # Analyze responses
585
+
586
+ asyncio.run(main())
587
+ ```
588
+
589
+ - **Multi-threaded Testing with Go**:
590
+
591
+ ```go
592
+ package main
593
+
594
+ import (
595
+ "net/http"
596
+ "sync"
597
+ )
598
+
599
+ func main() {
600
+ var wg sync.WaitGroup
601
+ for i := 0; i < 50; i++ {
602
+ wg.Add(1)
603
+ go func() {
604
+ http.Post("https://target.com/api/action",
605
+ "application/json",
606
+ strings.NewReader(`{"param":"value"}`))
607
+ wg.Done()
608
+ }()
609
+ }
610
+ wg.Wait()
611
+ }
612
+ ```
613
+
614
+ ### Testing Strategies
615
+
616
+ #### Comprehensive Race Condition Test Methodology
617
+
618
+ ```mermaid
619
+ sequenceDiagram
620
+ participant Tester
621
+ participant Application
622
+ participant Database
623
+
624
+ Note over Tester: Preparation Phase
625
+ Tester->>Application: Identify state-changing operations
626
+ Tester->>Application: Create test accounts
627
+ Tester->>Tester: Prepare concurrent request tools
628
+
629
+ Note over Tester: Discovery Phase
630
+ Tester->>Application: Send 50+ parallel requests
631
+ Application->>Database: Multiple concurrent operations
632
+ Note over Database: Race condition occurs
633
+ Database->>Application: Inconsistent state
634
+ Application->>Tester: Observe anomalous behavior
635
+
636
+ Note over Tester: Exploitation Phase
637
+ Tester->>Tester: Fine-tune timing parameters
638
+ Tester->>Application: Execute optimized attack
639
+ Tester->>Tester: Document impact
640
+ ```
641
+
642
+ 1. **Preparation Phase**:
643
+ - Map application functionality with state changes
644
+ - Create multiple test accounts
645
+ - Prepare parallel request tools and monitoring
646
+
647
+ 2. **Discovery Phase**:
648
+ - Test for TOCTOU issues in all critical functions
649
+ - Test multi-step transactions with simultaneous final steps
650
+ - Look for resource contention vulnerabilities
651
+ - Test file operations for race conditions
652
+
653
+ 3. **Exploitation Phase**:
654
+ - Fine-tune timing and concurrency parameters
655
+ - Create proof-of-concept exploits for confirmed issues
656
+ - Measure impact with controlled exploitation
657
+ - Document findings with clear reproduction steps
658
+
659
+ 4. **Verification Phase**:
660
+ - Test different concurrency levels (10, 50, 100 requests)
661
+ - Vary timing patterns (synchronized vs staggered)
662
+ - Test across different network conditions
663
+
664
+ ### Real-World Testing Examples
665
+
666
+ #### E-commerce Application Testing
667
+
668
+ 1. Add limited stock item to cart
669
+ 2. Send 20 simultaneous checkout requests
670
+ 3. Verify if multiple purchases succeed despite limited inventory
671
+
672
+ #### Banking Application Testing
673
+
674
+ 1. Identify fund transfer functionality
675
+ 2. Create 50 simultaneous transfer requests for the same amount
676
+ 3. Verify account balance after transfers complete
677
+ 4. Check for transaction logs inconsistencies
678
+
679
+ #### API Testing for Race Conditions
680
+
681
+ 1. Identify stateful API endpoints
682
+ 2. Create requests that modify shared resources
683
+ 3. Execute requests simultaneously from multiple clients
684
+ 4. Verify resource state consistency
685
+
686
+ ## Advanced Race Condition Scenarios
687
+
688
+ ### Multi-Endpoint Race Conditions
689
+
690
+ When functionality chains with multiple requests, for example in e-commerce:
691
+
692
+ ```
693
+ - /product --> for the product
694
+ - /cart --> Add to cart that product
695
+ - /cart/checkout --> Buy that product
696
+ ```
697
+
698
+ 1. Send all required requests to Burp repeater in sequence
699
+ 2. Create tabs for each request
700
+ 3. Use "Send Parallel (single Packet Attack)" for execution
701
+
702
+ ### Single-Endpoint Race Conditions
703
+
704
+ Common in email change functionality:
705
+
706
+ 1. Setup:
707
+ ```
708
+ Account A: Attacker --> attacker@email.com
709
+ Account B: Victim --> victim@email.com
710
+ ```
711
+ 2. When application updates email in database before confirmation
712
+ 3. Send parallel requests changing email between attacker and victim addresses
713
+ 4. If application generates confirmation links simultaneously, both may be sent to the same email
714
+ 5. Impact: Potential for Account Takeover
715
+
716
+ ## Remediation Recommendations
717
+
718
+ - **Transaction Isolation**: Implement proper database transaction isolation levels
719
+ - **Pessimistic Locking**: Lock resources before operations
720
+ - **Optimistic Concurrency Control**: Use version numbers or timestamps
721
+ - **Atomic Operations**: Use atomic operations where supported
722
+ - **Idempotent APIs**: Design APIs to be safely retried
723
+ - **Distributed Locks**: Implement distributed locking for microservices
724
+ - **Queue-Based Architecture**: Process requests sequentially through queues
725
+ - **Rate Limiting**: Enforce reasonable request rates per user
726
+ - **Stateful Synchronization**: Maintain consistent application state
727
+ - **Unique Constraint Enforcement**: Database-level constraint validation
728
+
729
+ ### Connection Pool Exhaustion Races
730
+
731
+ Applications using connection pools (database, Redis, HTTP clients) can be vulnerable:
732
+
733
+ ```python
734
+ # Test connection pool exhaustion
735
+ import requests
736
+ import threading
737
+
738
+ def hold_connection():
739
+ # Keep connection open without releasing
740
+ r = requests.get('https://target.com/long-running-query', stream=True)
741
+ # Don't close, hold for 30 seconds
742
+ time.sleep(30)
743
+
744
+ # Exhaust pool
745
+ threads = []
746
+ for _ in range(100): # More than pool size
747
+ t = threading.Thread(target=hold_connection)
748
+ threads.append(t)
749
+ t.start()
750
+
751
+ # Now test if race conditions occur in queue processing
752
+ ```
753
+
754
+ **Testing Strategy:**
755
+
756
+ 1. Identify endpoints that hold connections (long-running queries, file downloads)
757
+ 2. Exhaust the pool with held connections
758
+ 3. Test critical operations during exhaustion
759
+ 4. Check if timeouts cause race conditions in cleanup logic
760
+
761
+ ### CI/CD Pipeline Race Conditions
762
+
763
+ Deployment processes can have race conditions affecting security:
764
+
765
+ **Artifact Deployment Races:**
766
+
767
+ - Multiple pipelines deploying same artifact simultaneously
768
+ - Race between artifact upload and deployment
769
+ - Container image tag races (`latest` tag pointing to old image)
770
+
771
+ **Database Migration Races:**
772
+
773
+ ```bash
774
+ # Two deployment instances running migrations simultaneously
775
+ # Test by triggering parallel deployments
776
+
777
+ # Check for migration locks
778
+ kubectl get pods -l job-name=db-migrate
779
+
780
+ # Test concurrent schema changes
781
+ ```
782
+
783
+ **Configuration Deployment:**
784
+
785
+ - Race between config update and application reload
786
+ - Multiple instances reading stale configuration
787
+ - Secret rotation during active requests
788
+
789
+ **Testing Approach:**
790
+
791
+ 1. Trigger multiple simultaneous deployments
792
+ 2. Monitor for corrupted artifacts or partial deployments
793
+ 3. Check database migration logs for conflicts
794
+ 4. Verify configuration consistency across instances
795
+
796
+ ## Real World Cases and CVEs
797
+
798
+ ### Notable Race Condition Vulnerabilities
799
+
800
+ 1. **CVE-2023-6690 - GitHub Enterprise Server**:
801
+ - GraphQL mutation race condition
802
+ - Low-privileged users could grant themselves site-admin privileges
803
+ - Impact: Complete administrative takeover
804
+
805
+ 2. **CVE-2021-41091 - Docker (Moby)**:
806
+ - Race condition in permission check during container removal
807
+ - Allowed non-root users to delete arbitrary files
808
+ - Impact: Host system compromise
809
+
810
+ 3. **CVE-2019-5736 - runc Container Escape**:
811
+ - Race condition in container runtime
812
+ - Attacker could overwrite host runc binary
813
+ - Impact: Container escape to host
814
+
815
+ 4. **CVE-2016-5195 - Dirty COW (Linux Kernel)**:
816
+ - Race condition in memory management (Copy-on-Write)
817
+ - Allowed privilege escalation to root
818
+ - Impact: Complete system compromise
819
+
820
+ 5. **PayPal - Double Payment Race Condition**:
821
+ - Concurrent payment requests processed twice
822
+ - User charged once but vendor paid twice
823
+ - Impact: Financial loss
824
+
825
+ 6. **Shopify - Gift Card Race Condition**:
826
+ - Single-use gift cards redeemed multiple times
827
+ - Race in balance check and deduction logic
828
+ - Impact: Financial fraud
829
+
830
+ 7. **Uber - Promotional Code Race**:
831
+ - One-time promo codes used multiple times
832
+ - Concurrent ride requests with same code
833
+ - Impact: Revenue loss
834
+
835
+ ### HackerOne Reports
836
+
837
+ 1. **Flag Submission**: Race condition allowing multiple submissions of the same CTF flag, increasing user points unfairly
838
+ 2. **Invite System**: Race condition allowing invitation of same member multiple times to a single team
839
+ 3. **Retest Payment**: Race condition allowing multiple payments for a single retest
840
+ 4. **Group Member Management**: Race condition preventing admin from removing group members
841
+ 5. **User Following**: Race condition allowing multiple follows of the same user
842
+ 6. **Report Voting**: Race condition enabling multiple upvotes/downvotes on a single report
843
+ 7. **CTF Group Joining**: Race condition allowing multiple joins to the same CTF group
844
+ 8. **Invitation Limit Bypass**: Race condition bypassing the invitation limit restriction
845
+ 9. **Gift Card Redemption**: Race condition enabling multiple redemptions of the same gift card
846
+ 10. **OAuth Token Generation**: Race during token generation allowed multiple valid tokens for single authorization code
847
+
848
+ ### Impact Categories
849
+
850
+ - **Critical**: Financial loss, privilege escalation, data corruption
851
+ - **High**: Business logic bypass, resource exhaustion, unauthorized access
852
+ - **Medium**: Rate limit bypass, duplicate operations, inconsistent state
853
+ - **Low**: UI glitches, non-security-impacting inconsistencies
854
+
855
+ ## Burp Suite Testing Methods
856
+
857
+ ### Using Burp 2023.9.x or Higher
858
+
859
+ 1. Send the request to repeater for multiple instances
860
+ 2. Create tabs for all requests and select "Send Parallel (single Packet Attack)"
861
+ 3. Execute and analyze results
862
+
863
+ ### Using Turbo Intruder for Rate Limit Testing
864
+
865
+ ```python
866
+ def queueRequests(target, wordlists):
867
+ engine = RequestEngine(endpoint=target.endpoint,
868
+ concurrentConnections=1,
869
+ engine=Engine.BURP2)
870
+
871
+ passwords = wordlists.clipboard
872
+
873
+ for password in passwords:
874
+ engine.queue(target.req, password, gate='1')
875
+
876
+ engine.openGate('1')
877
+
878
+ def handleResponse(req, interesting):
879
+ table.add(req)
880
+ ```
881
+