Session Handling and Authentication
The Authentication Problem
Most web applications require login. When you test authenticated functionality, every request must include a valid session token. If the session expires during a long Intruder attack or Scanner run, all subsequent requests return 401/403 and your results are garbage. Session handling rules solve this by automatically detecting expired sessions and re-authenticating.
How Sessions Work in Burp
When you log in through Burp Proxy, the server returns a session cookie (e.g., session=abc123). This cookie is stored in your browser and sent with every subsequent request. Burp sees this cookie in the proxy traffic and can use it in other tools (Repeater, Intruder, Scanner) by configuring session handling.
Configuring Session Handling Rules
Go to Project options > Sessions > Session Handling Rules. Click Add to create a new rule:
- Rule name — e.g., "Re-authenticate on 401"
- Rule actions — Add action: "Run a macro"
- Macro — Record or select a macro that performs the login
- Scope — Define which URLs this rule applies to
What is a Macro?
A macro is a sequence of requests that Burp can replay. For authentication, you record a macro that:
- Sends a POST to
/loginwith username and password - Receives the session cookie in the response
When Burp detects a failed request (e.g., 401 response), it runs the macro to get a fresh session cookie, then retries the original request with the new cookie.
Recording a Login Macro
- Go to Project options > Sessions > Macros and click Add
- In the macro recorder, select the login request from your proxy history
- Configure the macro to extract the session cookie from the response:
- Click "Configure item"
- Add a custom parameter location: find
Set-Cookie: session=in the response - Define the parameter name and value extraction
- Save the macro
Testing with Multiple User Roles
To test authorization, you need at least two user accounts with different privilege levels (e.g., regular user and admin). Log in as each user through Burp Proxy, then use the session handling rules to switch between them.
In Intruder or Scanner, you can configure the session handling rule to use a specific user's macro. This lets you test whether a regular user can access admin functionality by replaying admin requests with a regular user's session cookie.
Authorization Testing
Horizontal vs Vertical Privilege Escalation
Authorization vulnerabilities come in two forms:
- Horizontal — A user can access another user's resources at the same privilege level (e.g., user A can view user B's documents)
- Vertical — A user can access functionality reserved for higher privilege levels (e.g., a regular user can access admin panels)
Testing Horizontal Privilege Escalation
- Capture requests as User A — Log in as a regular user, browse the application, and capture requests in Burp Proxy.
- Identify object references — Look for parameters that reference other users' resources:
/api/documents/1001,/api/users/5/profile,/api/orders/2001 - Switch to User B's session — Configure Burp to use User B's session cookie.
- Replay User A's requests — Send the captured requests with User B's session. If the server returns User A's data, horizontal privilege escalation exists.
Testing Vertical Privilege Escalation
- Capture admin requests — Log in as an admin, capture requests to admin-only endpoints:
/admin/users,/admin/settings,/admin/delete-user - Switch to regular user's session — Configure Burp to use a regular user's session cookie.
- Replay admin requests — Send the admin requests with the regular user's session. If the server processes them, vertical privilege escalation exists.
Using Burp's Role-Based Testing
Burp's User settings (Project options > Sessions > Users) let you define multiple users with different session handling rules. You can:
- Define User A with a macro that logs in as a regular user
- Define User B with a macro that logs in as an admin
- Configure Intruder or Scanner to iterate through users
This automates the process of testing each endpoint with each user role.
Practical Example: IDOR in a Multi-Tenant App
You are testing a project management app. You have two accounts: alice (regular user) and bob (regular user). Both are in different workspaces.
- Log in as Alice, capture:
GET /api/workspace/5/projects - Switch to Bob's session
- Replay:
GET /api/workspace/5/projects - If Bob sees Alice's workspace projects, horizontal IDOR is confirmed
Now test vertical:
- Log in as admin, capture:
GET /admin/all-workspaces - Switch to Alice's session
- Replay:
GET /admin/all-workspaces - If Alice sees all workspaces, vertical privilege escalation is confirmed
Common Authorization Flaws to Test
- Missing function-level access control — Endpoint exists but does not check if the user's role permits access
- Insecure direct object references (IDOR) — Parameter references another user's object without ownership verification
- Path traversal via authorization —
/api/users/1/fileaccessible by user 2 by changing the ID - HTTP method manipulation — GET returns 403 but POST or PUT succeeds
- Header-based authorization —
X-Admin: trueheader grants admin access
Advanced Macro Configuration
Handling Complex Login Flows
Not all logins are simple POST requests. Some applications use:
- Multi-step authentication — Username first, then password, then OTP
- CSRF tokens — Login form requires a CSRF token from a previous page
- OAuth flows — Redirect to identity provider, callback with code
- CAPTCHA — Automated solving required (or disabled in staging)
For multi-step logins, record a macro that includes all steps:
- GET
/login(to obtain CSRF token) - POST
/loginwith credentials and CSRF token - POST
/login/otpwith one-time password
Extracting Tokens from Macro Responses
When a macro performs login, you need to extract the session token from the response and use it in subsequent requests. In the macro configuration:
- Select the login request in the macro
- Click "Configure item"
- Add a Custom parameter location in the response:
- Parameter name:
session_id - Location: Find
Set-Cookie: session=in response headers - Value: Extract the cookie value
- Parameter name:
Burp automatically uses this extracted parameter in all requests within the macro and in the session handling rule.
Session Handling Rule Actions
A session handling rule can perform multiple actions when a session expires:
- Run a macro — Re-authenticate
- Set a specific cookie or parameter — Manually provide a session token
- Prompt for input — Ask the tester to manually log in
For automated testing, "Run a macro" is the most reliable. For manual testing, "Prompt for input" gives you control.
Testing Session Expiry Behavior
Applications handle session expiry differently:
- Hard expiry — Session invalidated after timeout; re-login required
- Sliding expiry — Session extended on each request; expires after inactivity
- Refresh tokens — Access token expires but refresh token obtains new access token
Test each scenario:
- Start an Intruder attack with a valid session
- Wait for the session to expire mid-attack
- Observe whether Burp's session handling rule re-authenticates automatically
- If not, the attack results after expiry are invalid — re-run with a fresh session
Practical Tip: Staging Environment Testing
Always test authenticated flows against a staging environment first. Production systems may:
- Rate-limit login attempts (locking your test accounts)
- Trigger security alerts on repeated authentication
- Have shorter session timeouts that interfere with testing
Staging environments typically have relaxed security controls and longer session timeouts, making automated testing more reliable.
Practice Problems
You are running a long Intruder attack against an authenticated endpoint. After 10 minutes, the session expires and all subsequent requests return 401. How do you configure Burp to handle this automatically?
Solution
1. Record a macro: Project options > Sessions > Macros > Add. Select the login request from proxy history. 2. Configure the macro to extract the session cookie from the login response (Configure item > Custom parameter location > find 'Set-Cookie: session=' in response). 3. Create a session handling rule: Project options > Sessions > Session Handling Rules > Add. 4. Set action to 'Run a macro' and select your login macro. 5. Set scope to the target URLs. 6. Now when Burp detects a 401, it runs the macro to re-authenticate and retries the request. You have two user accounts (userA and userB) on a document sharing app. Describe how you would test for horizontal privilege escalation using Burp.
Solution
1. Log in as userA through Burp Proxy. 2. Capture a request to a user-specific resource: GET /api/documents/1001. 3. Send the request to Repeater. 4. Configure Burp to use userB's session cookie (either via session handling rules or manually replacing the cookie). 5. Replay the request with userB's session. 6. If the response contains userA's document, horizontal privilege escalation is confirmed. 7. Repeat with different document IDs to map the scope of the vulnerability. Quiz
1. What is the purpose of a session handling rule in Burp?
2. What is the difference between horizontal and vertical privilege escalation?
3. You are testing an application that uses CSRF tokens in its login form. How do you configure a Burp macro to handle this?
4. Why is it important to test authenticated flows against a staging environment rather than production?
Flashcards
Question
What is a Burp macro?
Click to reveal answer
Answer
A sequence of requests that Burp can replay. For authentication, a macro records the login flow and extracts the session token from the response.
Question
What does a session handling rule do?
Click to reveal answer
Answer
Detects expired sessions (e.g., 401 responses) and automatically runs a macro to re-authenticate, then retries the original request with the fresh session cookie.
Question
What is horizontal privilege escalation?
Click to reveal answer
Answer
A user accessing another user's resources at the same privilege level (e.g., user A viewing user B's documents by changing an ID parameter).
Question
What is vertical privilege escalation?
Click to reveal answer
Answer
A user accessing functionality reserved for higher privilege levels (e.g., a regular user accessing admin panels or endpoints).
Question
How do you test authorization with multiple user roles in Burp?
Click to reveal answer
Answer
Define multiple users in Project options > Sessions > Users, each with their own login macro. Configure Intruder or Scanner to iterate through users, replaying requests with different session cookies.
Revision Notes
Key Takeaways
- 1. Session handling rules automatically re-authenticate when sessions expire during long tests
- 2. Macros record login sequences and extract session tokens for reuse
- 3. Horizontal privilege escalation = accessing another user's resources at the same level
- 4. Vertical privilege escalation = accessing higher-privilege functionality
- 5. Test authorization by capturing requests as one user and replaying with another user's session
- 6. Always test authenticated flows against staging first to avoid rate limits and alerts
Interview Tips
- • Describe how you configured session handling to maintain authentication during a long Scanner run
- • Explain the difference between horizontal and vertical privilege escalation with examples
- • Discuss how you test IDOR by replaying requests with different user sessions
- • Mention how you handle complex login flows (CSRF tokens, multi-step auth) in Burp macros
Cheat Sheet
Testing Authenticated Flows Cheat Sheet
Phase: Web Testing with Burp Suite | Level: intermediate
Session Handling:
- Record a macro: Project options > Sessions > Macros > Add
- Configure macro to extract session token from login response
- Create session handling rule: Project options > Sessions > Session Handling Rules
- Set action: Run a macro on 401/403
Authorization Testing:
- Horizontal: User A accesses User B's resources (same privilege level)
- Vertical: Regular user accesses admin functionality (higher privilege level)
- Capture requests as one user, replay with another user's session
Multi-User Testing:
- Define users in Project options > Sessions > Users
- Each user has their own login macro
- Configure tools to iterate through users
Common Flaws:
- Missing function-level access control
- IDOR (Insecure Direct Object References)
- HTTP method manipulation (GET blocked, POST allowed)
- Header-based authorization bypass
Tags: burp-suite, access-control
Continue Learning
Before You Start
- No prerequisites listed.