| name | detecting-api-enumeration-attacks |
| description | Detect and prevent API enumeration attacks including BOLA and IDOR exploitation by monitoring sequential identifier access patterns and authorization failures. |
| domain | cybersecurity |
| subdomain | api-security |
| tags | ["api-security","enumeration","bola","idor","broken-object-level-authorization","owasp-api-top-10","access-control","rate-limiting"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
Detecting API Enumeration Attacks
Overview
API enumeration attacks occur when attackers systematically probe API endpoints with sequential or predictable identifiers to discover and access unauthorized resources. Broken Object Level Authorization (BOLA), ranked as API1:2023 in the OWASP API Security Top 10, is the most critical API vulnerability. Attackers manipulate object identifiers (user IDs, order numbers, account references) in API requests to bypass authorization and access other users' data. Detection requires monitoring for patterns of rapid sequential access attempts, authorization failures, and abnormal API usage behavior.
Prerequisites
- API gateway or reverse proxy with logging enabled (Kong, AWS API Gateway, Apigee)
- SIEM platform (Splunk, Elastic SIEM, or Microsoft Sentinel)
- Access to API server logs with request details
- Web Application Firewall (WAF) with API protection capabilities
- Understanding of the API's authorization model and object identifier schemes
Attack Patterns to Detect
1. Sequential ID Enumeration
Attackers iterate through numeric or predictable identifiers:
GET /api/v1/users/1001 -> 200 OK
GET /api/v1/users/1002 -> 200 OK
GET /api/v1/users/1003 -> 403 Forbidden
GET /api/v1/users/1004 -> 200 OK
GET /api/v1/users/1005 -> 200 OK
...
Detection Indicators:
- Rapid sequential requests to the same endpoint with incrementing IDs
- Mix of 200/403/401 responses from same source
- Request rate exceeding normal user behavior
- Access to resources outside authenticated user's scope
2. UUID/GUID Enumeration
Even non-sequential identifiers can be enumerated if leaked through other endpoints:
# Attacker first harvests UUIDs from a list endpoint
GET /api/v1/posts?page=1 -> Returns post objects with author UUIDs
# Then uses those UUIDs to access restricted user data
GET /api/v1/users/a3f2c1e4-... -> Private user profile
GET /api/v1/users/b7d9e8f1-... -> Private user profile
3. Parameter Tampering Enumeration
# Authenticated as user_id=100, attempting to access other users' orders
GET /api/v1/orders?user_id=101
GET /api/v1/orders?user_id=102
GET /api/v1/orders?user_id=103
Detection Rules
Splunk Detection Queries
# Detect sequential ID enumeration on API endpoints
index=api_logs sourcetype=api_access
| rex field=uri_path "(?<endpoint>/api/v\d+/\w+/)(?<object_id>\d+)"
| stats count as request_count,
dc(object_id) as unique_ids,
values(status_code) as status_codes,
min(_time) as first_seen,
max(_time) as last_seen
by src_ip, endpoint, user_session
| eval time_span = last_seen - first_seen
| eval requests_per_second = request_count / max(time_span, 1)
| where unique_ids > 20 AND requests_per_second > 2
| eval severity = case(
unique_ids > 100, "critical",
unique_ids > 50, "high",
unique_ids > 20, "medium",
1==1, "low"
)
| sort - unique_ids
| table src_ip, endpoint, unique_ids, request_count, requests_per_second,
status_codes, severity
# Detect BOLA via authorization failure patterns
index=api_logs sourcetype=api_access status_code IN (401, 403)
| bin _time span=5m
| stats count as failure_count,
dc(uri_path) as unique_paths,
values(uri_path) as attempted_paths
by _time, src_ip, user_id
| where failure_count > 10
| eval attack_type = if(unique_paths > 5, "enumeration", "brute_force")
Elastic SIEM Detection Rules
{
"rule": {
"name": "API Object Enumeration Detection",
"description": "Detects rapid sequential access to API objects with mixed authorization results",
"type": "threshold",
"index": ["api-access-*"],
"query": {
"bool": {
"must": [
{ "regexp": { "url.path": "/api/v[0-9]+/[a-z]+/[0-9]+" } }
],
"should": [
{ "term": { "http.response.status_code": 200 } },
{
Custom Detection Script
"""API Enumeration Attack Detector
Analyzes API access logs to detect enumeration patterns
including BOLA, IDOR, and sequential ID probing.
"""
import re
import sys
import json
from collections import defaultdict
from datetime import datetime, timedelta
from dataclasses import dataclass, field
from typing import List, Dict, Optional
@dataclass
class AccessRecord:
timestamp: datetime
source_ip: str
user_id: Optional[str]
method: str
path: str
status_code: int
object_id: Optional[str] = None
@dataclass
class EnumerationAlert:
source_ip: str
user_id: Optional[str]
endpoint_pattern: str
unique_object_ids: int
total_requests: int
time_window_seconds: float
requests_per_second: float
auth_failure_ratio: float
severity: str
attack_type: str
sample_ids: List[str] = field(default_factory=list)
class EnumerationDetector:
ID_PATTERNS = [
re.(),
re.(),
re.(),
]
():
.time_window = timedelta(minutes=time_window_minutes)
.min_unique_ids = min_unique_ids
.max_rps = max_requests_per_second
.access_log: [AccessRecord] = []
() -> [AccessRecord]:
log_pattern = re.(
)
= log_pattern.(line)
:
path = .group()
object_id =
pattern .ID_PATTERNS:
id_match = pattern.search(path)
id_match:
object_id = id_match.group()
AccessRecord(
timestamp=datetime.strptime(.group(), ),
source_ip=.group(),
user_id=.group() .group() != ,
method=.group(),
path=path,
status_code=(.group()),
object_id=object_id
)
() -> [EnumerationAlert]:
alerts = []
grouped = defaultdict()
record records:
record.object_id:
endpoint = re.sub(, ,
re.sub(, , record.path))
key = (record.source_ip, record.user_id, endpoint)
grouped[key].append(record)
(src_ip, user_id, endpoint), records_group grouped.items():
(records_group) < .min_unique_ids:
records_group.sort(key= r: r.timestamp)
window_start =
window_start ((records_group)):
window_records = []
r records_group[window_start:]:
r.timestamp - records_group[window_start].timestamp <= .time_window:
window_records.append(r)
unique_ids = (r.object_id r window_records)
(unique_ids) < .min_unique_ids:
time_span = (window_records[-].timestamp -
window_records[].timestamp).total_seconds()
rps = (window_records) / (time_span, )
auth_failures = ( r window_records
r.status_code (, ))
failure_ratio = auth_failures / (window_records)
(unique_ids) > :
severity =
(unique_ids) > failure_ratio > :
severity =
(unique_ids) > :
severity =
:
severity =
ids_list = ([r.object_id r window_records
r.object_id r.object_id.isdigit()])
is_sequential = ._check_sequential(ids_list)
attack_type = is_sequential
alert = EnumerationAlert(
source_ip=src_ip,
user_id=user_id,
endpoint_pattern=endpoint,
unique_object_ids=(unique_ids),
total_requests=(window_records),
time_window_seconds=time_span,
requests_per_second=(rps, ),
auth_failure_ratio=(failure_ratio, ),
severity=severity,
attack_type=attack_type,
sample_ids=(unique_ids)[:]
)
alerts.append(alert)
alerts
() -> :
(ids) < :
:
numeric_ids = ((i) i ids)
sequential_count = (
i (, (numeric_ids))
numeric_ids[i] - numeric_ids[i-] <=
)
sequential_count / (numeric_ids) >
ValueError:
():
detector = EnumerationDetector(
time_window_minutes=,
min_unique_ids=
)
log_file = sys.argv[] (sys.argv) >
records = []
(log_file, ) f:
line f:
record = detector.parse_log_line(line.strip())
record:
records.append(record)
alerts = detector.analyze(records)
alerts:
()
alert alerts:
()
()
()
()
()
()
()
()
()
()
:
()
__name__ == :
main()
Prevention Controls
Server-Side Authorization Enforcement
def get_user_order(request, order_id):
order = Order.objects.get(id=order_id)
if order.user_id != request.user.id:
raise PermissionDenied("Not authorized to access this order")
return order
Use Unpredictable Identifiers
import uuid
class Order(Model):
id = UUIDField(default=uuid.uuid4, primary_key=True)
Implement Rate Limiting Per Endpoint
plugins:
- name: rate-limiting
config:
minute: 30
policy: redis
limit_by: credential
References