Cracking the Code: Advanced CSRF Token Validation and Brute-force attack with BurpSuite’s Intruder

Vishal Raj
System Weakness
Published in
13 min readApr 10, 2024

--

Introduction:

In the ever-evolving landscape of cybersecurity, web applications stand as both the gateway to boundless information and the frontline of defense against malicious attacks. Among the myriad threats facing these applications, Cross-Site Request Forgery (CSRF) remains a persistent and insidious vulnerability, allowing attackers to exploit the trust between a user and a web application to perform unauthorized actions.

In response to this threat, developers have implemented CSRF protection mechanisms, chief among them the CSRF token. This token serves as a unique identifier, ensuring that each request originates from a legitimate source and not from a malicious actor. However, as attackers continually adapt their techniques, it becomes imperative for cybersecurity professionals to stay ahead of the curve.

In this article, we delve into the realm of CSRF protection, focusing specifically on the validation of CSRF tokens using BurpSuite’s Intruder tool. By leveraging session handling rules and advanced payload sets, we will explore techniques to effectively validate CSRF tokens in the face of increasingly sophisticated attacks. Through practical examples and step-by-step guidance, readers will gain a deeper understanding of CSRF protection and arm themselves with the knowledge to fortify their web applications against CSRF exploits.

Disclaimer:

The information in this article is provided for educational purposes only. The techniques and tools discussed are intended for authorized use only. The authors and publisher of this article are not responsible for any misuse or illegal activities that result from the use of these techniques and tools. We do not condone illegal activities and encourage readers to use these techniques and tools in an ethical and legal manner

Understanding CSRF Tokens and Their Importance in Web Security

Cross-Site Request Forgery (CSRF) is a type of malicious exploit where unauthorized commands are transmitted from a user that the web application trusts. These attacks occur when an attacker tricks a user’s browser into executing unwanted actions on a web application to which the user is authenticated. Such actions can include changing the user’s password, transferring funds, or making unwanted purchases.

Fig2.1 CSRF

To mitigate CSRF attacks, web applications often utilize CSRF tokens. These tokens are unique, random values generated by the server and embedded within each form or request sent to the client. When a user submits a request, the CSRF token is also submitted, and the server verifies its authenticity. If the token is missing or incorrect, the request is rejected, thereby preventing unauthorized actions.

Fig2.2 CSRF Token

The importance of CSRF tokens in web security cannot be overstated. They serve as a crucial defense mechanism against CSRF attacks by ensuring that only requests originating from the legitimate user session are processed. Without proper CSRF protection, attackers can exploit vulnerabilities to manipulate user actions, leading to severe consequences such as data breaches, financial losses, and reputational damage.

In the context of web application testing and security assessments, understanding CSRF tokens is essential for accurately assessing the resilience of an application against CSRF attacks. By incorporating CSRF token validation into penetration testing methodologies, security professionals can identify and remediate vulnerabilities before they are exploited by malicious actors.

Exploring BurpSuite: A Comprehensive Overview

I know most of us are familiar with BurpSuite, but I want to give a brief introduction about BurpSuite for those who might be new to this powerful tool.

BurpSuite is a leading web application security testing tool developed by PortSwigger Security. It is widely recognized for its comprehensive suite of features designed to assist security professionals in identifying vulnerabilities, testing web applications, and ensuring their resilience against cyber threats.

Fig3.1 BurpSuite

At its core, BurpSuite functions as a proxy server that sits between the user’s browser and the target web application, allowing for the interception and manipulation of HTTP/S requests and responses. This interception capability enables security analysts to conduct various types of assessments, including vulnerability scanning, penetration testing, and security auditing.

Key features of BurpSuite include:

1. Proxy: BurpSuite’s proxy tool facilitates the interception and modification of HTTP/S traffic between the user’s browser and the web application.

2. Scanner: BurpSuite includes an automated scanner capable of identifying common web application vulnerabilities such as SQL injection, cross-site scripting (XSS), and insecure direct object references (IDOR).

3. Repeater: The repeater tool allows security analysts to manually manipulate and resend individual HTTP/S requests, enabling detailed testing and analysis of specific functionalities or vulnerabilities within the application.

4. Intruder: BurpSuite’s intruder tool is designed for performing advanced attacks such as brute-force attacks, fuzzing, and payload manipulation.

5. Extensibility: BurpSuite supports extensibility through its robust API, allowing security professionals to develop custom extensions and integrations to enhance its functionality and automate repetitive tasks.

Overall, BurpSuite is a versatile and powerful tool that plays a crucial role in the arsenal of cybersecurity professionals. Its intuitive interface, comprehensive features, and extensibility make it a preferred choice for conducting web application security assessments.

Setting Up BurpSuit:

Before conducting brute-force attack testing with BurpSuite, it’s essential to ensure that the tool is properly configured and set up to facilitate the testing process effectively. Follow these steps to configure BurpSuite for conducting brute-force attack testing:

1. Install BurpSuite: Download and install BurpSuite from the official PortSwigger website (https://portswigger.net/burp). BurpSuite is available in both free and paid versions. For the purposes of this guide, we will focus on the free version, BurpSuite Community Edition.

2. Configure Browser Proxy Settings: Configure your web browser to use BurpSuite as a proxy server. By default, BurpSuite listens on port 8080 for HTTP traffic and port 8443 for HTTPS traffic. Adjust your browser’s proxy settings to point to these ports on localhost (127.0.0.1).

3. Certificate Installation (Optional): If you plan to intercept HTTPS traffic, install BurpSuite’s CA certificate in your browser to avoid certificate warnings. You can find the CA certificate under the “Proxy” tab in BurpSuite’s options.

4. Start BurpSuite: Launch BurpSuite and ensure that it is running correctly. We should see the Proxy “Intercept” tab and the “Target” tab in the main interface. Turn Interception off for now.

Now, let’s consider our attack scenario: we have a web application where we need to perform a brute-force attack on a form with values ranging from 1 to 50 to find the flag using BurpSuite.

However, it’s crucial to note that the web application is safeguarded with a CSRF token. This means that each request sent to the server must include a valid CSRF token to be accepted. Without this token, our requests will be rejected, thwarting our brute-force efforts.

Fig 4.1 Targeted Web Application
Fig 4.2 Web App Request and Response

However, we cannot use Intruder or Repeater to perform the brute-force attack in this scenario because both Intruder and Repeater does not support the automatic handling of CSRF tokens. Since the web application is safeguarded with a CSRF token, any request sent without a valid CSRF token will be rejected by the server.

Fig 4.3 Invalid CSRF Token

Now let’s send this request to the Intruder and start brute-force without any CSRF validation implementation to check the result. This will help us understand the baseline behavior and response of the target web application when subjected to brute-force attacks without considering CSRF protection.

Send the request from Proxy HTTP history to Intruder:

Navigate to the “Proxy” tab in BurpSuite and select the “HTTP history” sub-tab. Locate the request corresponding to the form submission we want to brute-force. Then, Right-click on the request and select “Send to Intruder” from the context menu..

i. Configure Brute-Force Attack Settings: Within BurpSuite, navigate to the “Intruder” tab and set up the attack parameters. Customize payload options, such as payload type Numbers and sets (Numbers from 1 to 50).

Fig 4.4

ii. Define Attack Positions: In the “Positions” tab of the Intruder tool, specify where payloads should be injected within the request. For a brute-force attack, these positions typically correspond to input fields such as username and password.

Fig 4.5

iii. Grep-Match: Use Grep-Match to flag the result items containing specific expressions.

Fig 4.6

iv. Start the Attack: Once all settings are configured, initiate the brute-force attack by clicking the “Start attack” button in the Intruder tab. BurpSuite will begin sending payloads to the target URL.

Fig 4.7

As evident from each response, the CSRF token is consistently flagged as invalid because Intruder persists in employing the same CSRF token across all requests. This clearly demonstrates the web application’s robust CSRF protection mechanism, effectively thwarting the brute-force attack by detecting and rejecting requests with erroneous CSRF tokens. This emphasizes the criticality of meticulous CSRF token validation in fortifying web applications against unauthorized infiltration and exploitation.

Now, let’s delve into how we can implement CSRF token validation in BurpSuit.

1. CSRF Token Validation in BurpSuite: Payload Set Techniques (Recursive Grep)

In the “Payload Positions” tab of the Intruder tool, specify where payloads should be injected within the request(items, csrf_token) and Select attack type pitchfork.

Fig 5.1

Use grep Extract to Specify CSRF Token: Utilize BurpSuite’s “grep extract” feature to automatically identify and extract CSRF tokens from responses. This ensures that the payload sets contain valid CSRF tokens obtained from legitimate sessions, enhancing the accuracy of the validation process.

Fig 5.2
Fig 5.3

3. Select Payload Sets: In BurpSuite’s Intruder tool, choose the “Payloads” tab and select the “Payload set” option. Define two payload sets:

  • The first payload set is for the “items” parameter, with the payload type set to “numbers” ranging from 1 to 50.
Fig 5.4
  • The second payload set is for the CSRF token, utilizing the recursive grep feature to extract valid tokens from responses. Set the Initial payload for first request to “NULL”.
Fig 5.5

4. Set Maximum Concurrent Requests: In the Resource Pool section of BurpSuite, set the “Maximum Concurrent Requests (Threshold)” to 1. This ensures that only one request is processed at a time, preventing potential issues with concurrency during the attack.

Fig 5.6

5. Add Grep-Match: In the Intruder’s Settings tab, after configuring payload sets, add a Grep-Match option. This option enables us to match the flag result item containing specified responses. Specify the responses that we are interested in, such as error messages or success indicators, to accurately identify successful or failed CSRF token validations during the attack.

Fig 5.7

6. Initiate the Attack: After configuring the payload sets, positions, resource pool settings, and Grep-Match option, start the attack by clicking the “Start attack” button in the Intruder tab. Verify that the CSRF token is validated in each request by examining the flagged responses(Anti-CSRF token is valid) for the specified success indicators or expected validation messages.

Fig 5.8

CSRF Token Validation in BurpSuite: Session Handling Rules

i.) Configure Macro Actions: Navigate to setting → Sessions, Click on the “Add” button within the Macros section dialog to define macro actions. A macro consists of a series of actions that BurpSuite performs automatically during a testing session. In this case, the macro actions will focus on extracting and updating CSRF tokens.

Fig 6.1

Now, select the HTTP request that the macro will execute actions on. This request typically fetch to the csrf_token by sending the GET request to web server.

Fig 6.2

In the macro configuration editor, ensure that the “Add cookies received in responses to the session handling cookie jar” option is checked. This option instructs BurpSuite to add any cookies received in server responses to the session handling cookie jar. Also, check the “Use cookies from the session handling cookie jar in requests” option. Enabling this option instructs BurpSuite to automatically include cookies from the session handling cookie jar in subsequent requests sent during the testing session.

Fig 6.3

ii.) Create a New Session Handling Rule: In the “Session handling rules” section, click on the “Add” button to create a new session handling rule. This action will prompt a dialog box where we can define the properties of the new rule.

Fig 6.4

Define Tools Scope and URL Scope: In the dialog box for creating a new session handling rule, specify the Tools scope and URL scope for the rule. URL Scope determines the target domain where this rule applies. And Tools scope determine the tools that the rule will be applied to.

Fig 6.5

After defining scope ,In the rule action, give a name to the session handling rule and click on the “Add” button and select “Run a macro.” Than after Choose the macro that we want to execute.

Fig 6.7

Now check the box labeled “Update current request with parameter matched from final macro response.” Select “Update only the following parameters and headers,” then click on the “Edit” button to add “csrf_token” to the Edit list. This ensures that any parameters(csrf_token) extracted from the final response of the macro are automatically inserted into the current request.

Next, select “Update current request with cookies from session handling cookie jar” and choose “Update only the following cookie,” adding “PHPSESSID” to the Edit list. That ensures that cookies from the session handling cookie jar are automatically included in the current request. By specifying which cookies to update, such as “PHPSESSID,” BurpSuite ensures that the session state is maintained across requests, mimicking the behavior of a real user session.

Fig 6.8

Additionally, after configuring the rule actions, click on the “Open session tracker” button to track the execution of the session handling rule. This allows us to monitor how the rule is being applied during the testing session, providing valuable insights into its effectiveness and identifying any potential issues or discrepancies in the session handling process. By actively monitoring the session tracker, we can ensure that the session handling rule is functioning as intended and troubleshoot any issues that may arise during testing. At last, Don’t forget to check the session handling rule we defined to ensure that it is enabled and actively applied during the testing session

Fig 6.9

iii.) Setting up Intruder

Furthermore, proceed to the “Intruder” section and carefully select the attack position for the brute-force attack. This step is pivotal in determining which parameters within the request will be targeted for manipulation during the attack.

Fig 7.1

Next, choose the attack type as “Spider” and set the payload to “Numbers” ranging from 1 to 50. This selection ensures that a comprehensive range of values is systematically tested, covering a broad spectrum of potential inputs.

Fig 7.2

Additionally, configure Maximum Concurrent Requests (threshold) to 1 from the resource pool settings.

Moreover, add the item to the Grep-Match section to specify the pattern or content to match in the server response.

Fig 7.3

With all configurations in place, we are now ready to initiate the brute-force attack. Click on the “Start attack” button to commence the attack process.

Fig 7.4

As depicted in Fig7.4 the Grep-Match feature displays that all the CSRF tokens are valid, indicating successful validation. Consequently, we have identified the flag, Now, let’s move to the session handling tracker to see the execution and effectiveness of the session handling rules in real-time.

Fig 7.5

The session tracker results indicate that the session handling rule executed successfully, effectively managing CSRF tokens and maintaining session integrity throughout the testing process. This ensures that requests were properly handled, and parameters such as CSRF tokens were appropriately validated and updated as needed. Overall, the session tracker confirms the smooth execution of the session handling rule, contributing to the accuracy and reliability of the testing outcomes.

Best Practices for Defending Against Brute-Force Attacks

Brute-force attacks remain a persistent threat to web applications, but there are several best practices that organizations can implement to mitigate the risk and enhance their defenses. Here are some key recommendations:

1. Implement Account Lockout Policies: Enforce account lockout policies that temporarily lock user accounts after a specified number of failed login attempts.

2. Use Strong Password Policies: Implement strong password policies that require users to create complex passwords.

3. Implement Multi-Factor Authentication (MFA): Deploy multi-factor authentication (MFA) mechanisms to add an extra layer of security beyond passwords.

4. Employ Rate Limiting and CAPTCHA: Implement rate-limiting mechanisms to restrict the number of login attempts from a single IP address or user account within a specified time period.

5. Educate Users and Administrators: Educate users and administrators about the risks of brute-force attacks and the importance of following security best practices

Summary:

This guide outlined the process of conducting a brute-force attack using BurpSuite with CSRF token validation to bolster web application security. We configured BurpSuite for attack testing, set up session handling rules, and defined macro actions for CSRF token validation. We configured the Intruder tool, enabling Grep-Match for result analysis. We emphasized the importance of analyzing results, prioritizing remediation efforts, and monitoring the session handling tracker for proper execution. By following these steps, security professionals can enhancing overall security posture.

Thank you for exploring this guide on conducting brute-force attacks with BurpSuite and CSRF token validation. Your dedication to enhancing web application security is commendable. If you have any further questions or need assistance, feel free to reach out. Happy testing!

--

--

Hi, I'm ,Vishal Raj, a cyber security student with a passion for technology and protecting digital assets from cyber threats.