Privilege Escalation Attack
How Privilege Escalation Works
Privilege escalation is a fundamental attack technique where an attacker gains higher-level permissions than they should have. The core principle is simple: an attacker starts with limited access and manipulates the system to obtain elevated privileges.
Vertical privilege escalation involves moving up the permission hierarchy. A low-privileged user might exploit vulnerabilities to become an administrator. Horizontal privilege escalation means accessing resources belonging to users at the same permission level—like viewing another user's account data.
Common escalation vectors include:
- Authentication bypasses - Exploiting flaws in login mechanisms to access accounts without proper credentials
- Authorization bypasses - Circumventing permission checks to access restricted resources
- Session hijacking - Stealing session tokens to impersonate legitimate users
- Credential stuffing - Using breached username/password combinations across services
- Password spraying - Testing common passwords against many accounts systematically
The attack typically follows this pattern: reconnaissance to identify target systems, initial compromise through a vulnerability, privilege elevation through exploitation, and maintaining access for malicious purposes. Attackers often chain multiple vulnerabilities—for example, using an authentication bypass to log in, then exploiting an authorization flaw to access admin functions.
Privilege Escalation Against APIs
APIs present unique privilege escalation opportunities due to their stateless nature and complex permission models. Unlike traditional web applications, APIs often expose multiple endpoints that interact with different data objects and user roles.
Common API privilege escalation scenarios include:
Broken Object Level Authorization (BOLA) - The most prevalent API vulnerability. APIs receive object identifiers (user IDs, document IDs, order numbers) in requests but fail to verify whether the requester has permission to access those objects. An attacker simply modifies these identifiers to access other users' data.
Excessive data exposure - APIs return more data than necessary in responses. An attacker with basic access might receive admin-level information in API responses due to improper data filtering.
Missing function-level authorization - APIs check if a user is authenticated but not whether they're authorized for specific actions. A regular user might invoke admin-only endpoints if authorization checks are missing.
Parameter pollution - Manipulating request parameters to bypass authorization logic. For example, adding extra parameters that confuse the backend's permission evaluation.
Business logic flaws - APIs implement complex workflows where attackers discover sequences of actions that grant unintended elevated access. This might involve exploiting race conditions or state transitions.
Consider this vulnerable API endpoint:
GET /api/users/{userId}/profile HTTP/1.1
Authorization: Bearer valid.jwt.tokenThe API validates the JWT token (authentication) but doesn't verify if the requester owns the profile being accessed (authorization). An attacker with any valid token can substitute any userId value to access any profile.
Another example involves admin-only endpoints that lack proper authorization checks:
POST /api/admin/delete-user HTTP/1.1
Authorization: Bearer user.jwt.token
{ "userId": "[email protected]" }If the endpoint doesn't verify admin privileges, any authenticated user can delete accounts.
Detection and Prevention
Detecting privilege escalation requires systematic testing of authorization mechanisms. Security teams should map out all permission levels in their system and verify that each role can only access appropriate resources.
Static analysis helps identify potential authorization flaws by examining code for missing permission checks, improper use of authentication vs authorization, and hardcoded privilege assumptions.
Dynamic testing involves actively attempting privilege escalation through techniques like:
- Modifying object identifiers in API requests
- Accessing endpoints meant for other user roles
- Testing API endpoints without authentication
- Attempting to invoke admin functions with regular user credentials
- Analyzing API responses for data leakage
Automated scanning tools can systematically test for common privilege escalation patterns. middleBrick's API security scanner, for example, tests for BOLA vulnerabilities by automatically substituting object identifiers with values belonging to other users and checking if unauthorized access succeeds. The scanner tests 12 security categories in parallel, including authentication bypasses, privilege escalation attempts, and authorization flaws.
Prevention strategies include implementing the principle of least privilege—users and services should only have the minimum permissions necessary. Every API endpoint should enforce authorization checks, not just authentication. Object-level authorization should be applied consistently across all endpoints that access user-specific data.
Defense in depth involves multiple layers of protection. Rate limiting can slow down automated privilege escalation attempts. Input validation prevents parameter manipulation attacks. Security logging and monitoring can detect unusual access patterns that might indicate privilege escalation attempts.
Regular security assessments are essential. APIs evolve rapidly, and new endpoints or modified workflows can introduce authorization gaps. Continuous monitoring with tools like middleBrick's Pro plan can scan APIs on a configurable schedule, alerting teams when new privilege escalation vulnerabilities appear.
For critical APIs, consider implementing anomaly detection that flags unusual access patterns, such as a user suddenly accessing data objects they've never accessed before or attempting actions outside their normal behavior patterns.
Frequently Asked Questions
What's the difference between authentication and authorization in API security?
Authentication verifies who you are—confirming your identity through credentials like passwords, API keys, or JWT tokens. Authorization determines what you're allowed to do—checking your permissions against access control policies. An API can authenticate you successfully but still deny access if you lack proper authorization. Both are essential: authentication without authorization is like having a valid ID but no access badge; authorization without authentication is like having a badge but no verified identity.
How can I test my APIs for privilege escalation vulnerabilities?
Manual testing involves systematically attempting to access resources and endpoints beyond your permission level. Try modifying object identifiers, accessing admin endpoints with regular credentials, and testing API responses for data leakage. Automated tools like middleBrick can scan your APIs in 5-15 seconds, testing for BOLA vulnerabilities and other authorization flaws without requiring credentials or configuration. The scanner provides a security risk score (A-F) with prioritized findings and remediation guidance, making it easy to identify and fix privilege escalation vulnerabilities before attackers exploit them.