Performing API Inventory and Discovery
When to Use
- Mapping the complete API attack surface of an organization before a security assessment
- Identifying shadow APIs deployed by development teams without security review
- Discovering deprecated or zombie API versions that remain accessible but unmaintained
- Finding undocumented API endpoints exposed through mobile applications, SPAs, or microservices
- Building an API inventory for compliance requirements (PCI-DSS, SOC2, GDPR)
Do not use without written authorization. API discovery involves scanning network infrastructure and analyzing traffic.
Prerequisites
- Written authorization specifying the target domains and network ranges
- Passive traffic capture capability (network tap, proxy, or cloud traffic mirroring)
- Active scanning tools: Amass, subfinder, httpx, and nuclei
- JavaScript analysis tools: LinkFinder, JS-Miner, or custom parsers
- Access to cloud console (AWS, Azure, GCP) for API gateway inventory
- Burp Suite Professional for passive API endpoint discovery
Workflow
Step 1: Passive API Discovery from Traffic Analysis
import re
import json
from collections import defaultdict
# Parse HAR file from browser developer tools or proxy
def analyze_har_for_apis(har_file_path):
"""Extract API endpoints from HTTP Archive (HAR) file."""
with open(har_file_path) as f:
har = json.load(f)
api_endpoints = defaultdict(lambda: {
"methods": set(), "content_types": set(),
"auth_types": set(), "count": 0
})
for entry in har["log"]["entries"]:
url = entry["request"]["url"]
method = entry["request"]["method"]
# Identify API patterns
api_patterns = [
r'/api/', r'/v\d+/', r'/graphql', r'/rest/',
r'/ws/', r'/rpc/', r'/grpc', r'/json',
]
if any(re.search(p, url) for p in api_patterns):
# Normalize the URL (remove query params and IDs)
normalized = re.sub(r'\?.*$', '', url)
normalized = re.sub(r'/\d+(/|$)', '/{id}\\1', normalized)
normalized = re.sub(
r'/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',
'/{uuid}', normalized)
ep = api_endpoints[normalized]
ep["methods"].add(method)
ep["count"] += 1
# Detect authentication type
for header in entry["request"]["headers"]:
name = header["name"].lower()
if name == "authorization":
if "bearer" in header["value"].lower():
ep["auth_types"].add("Bearer/JWT")
elif "basic" in header["value"].lower():
ep["auth_types"].add("Basic")
elif name == "x-api-key":
ep["auth_types"].add("API Key")
# Detect content type
content_type = next(
(h["value"] for h in entry["request"]["headers"]
if h["name"].lower() == "content-type"), None)
if content_type:
ep["content_types"].add(content_type.split(";")[0])
print(f"Discovered {len(api_endpoints)} unique API endpoints:\n")
for url, info in sorted(api_endpoints.items()):
methods = ", ".join(sorted(info["methods"]))
auth = ", ".join(info["auth_types"]) or "None"
print(f" [{methods}] {url}")
print(f" Auth: {auth} | Requests: {info['count']}")
return api_endpoints
Step 2: Active API Endpoint Discovery
# DNS enumeration for API subdomains
amass enum -d example.com -o amass_results.txt
subfinder -d example.com -o subfinder_results.txt
# Filter for API-related subdomains
grep -iE '(api|rest|graphql|ws|gateway|backend|internal|staging|dev|v1|v2)' \
amass_results.txt subfinder_results.txt | sort -u > api_subdomains.txt
# Check which subdomains are alive
cat api_subdomains.txt | httpx -status-code -content-length -title \
-tech-detect -o live_apis.txt
> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.
1---2name: performing-api-inventory-and-discovery3description: "Perform API inventory and discovery to identify all API endpoints. Signals: api attack, interface testing, graphql."4zh-signals: "Performs API inventory and discovery to identify all API endpoints in 信号:api攻击,接口测试,graphql。"5when-to-use: 'Performs API inventory and discovery to identify all API endpoints in6 an organization''s environment including documented, undocumented, shadow, zombie,7 and deprecated APIs. The tester uses passive traffic analysis, active scanning,8 DNS enumeration, JavaScript analysis, and cloud resource inventory to build a comprehensive9 API catalog. Maps to OWASP API9:2023 Improper Inventory Management. Activates for10 requests involving API discovery, shadow API detection, API inventory audit, or11 attack surface mapping.1213 '14domain: cybersecurity15subdomain: api-security16tags:17- api-security18- owasp19- api-discovery20- shadow-api21- inventory22- attack-surface23version: 1.0.024author: mahipal25license: Apache-2.026nist_csf:27- PR.PS-0128- ID.RA-0129- PR.DS-1030- DE.CM-0131mitre_attack:32- T119033- T1059.00734- T1552.00135- T1078.00436- T153037metadata:38 source: https://skillmd.com/skills/dangeroussong/performing-api-inventory-and-discovery39---4041# Performing API Inventory and Discovery4243## When to Use4445- Mapping the complete API attack surface of an organization before a security assessment46- Identifying shadow APIs deployed by development teams without security review47- Discovering deprecated or zombie API versions that remain accessible but unmaintained48- Finding undocumented API endpoints exposed through mobile applications, SPAs, or microservices49- Building an API inventory for compliance requirements (PCI-DSS, SOC2, GDPR)5051**Do not use** without written authorization. API discovery involves scanning network infrastructure and analyzing traffic.5253## Prerequisites5455- Written authorization specifying the target domains and network ranges56- Passive traffic capture capability (network tap, proxy, or cloud traffic mirroring)57- Active scanning tools: Amass, subfinder, httpx, and nuclei58- JavaScript analysis tools: LinkFinder, JS-Miner, or custom parsers59- Access to cloud console (AWS, Azure, GCP) for API gateway inventory60- Burp Suite Professional for passive API endpoint discovery6162## Workflow6364### Step 1: Passive API Discovery from Traffic Analysis6566```python67import re68import json69from collections import defaultdict7071# Parse HAR file from browser developer tools or proxy72def analyze_har_for_apis(har_file_path):73 """Extract API endpoints from HTTP Archive (HAR) file."""74 with open(har_file_path) as f:75 har = json.load(f)7677 api_endpoints = defaultdict(lambda: {78 "methods": set(), "content_types": set(),79 "auth_types": set(), "count": 080 })8182 for entry in har["log"]["entries"]:83 url = entry["request"]["url"]84 method = entry["request"]["method"]8586 # Identify API patterns87 api_patterns = [88 r'/api/', r'/v\d+/', r'/graphql', r'/rest/',89 r'/ws/', r'/rpc/', r'/grpc', r'/json',90 ]9192 if any(re.search(p, url) for p in api_patterns):93 # Normalize the URL (remove query params and IDs)94 normalized = re.sub(r'\?.*$', '', url)95 normalized = re.sub(r'/\d+(/|$)', '/{id}\\1', normalized)96 normalized = re.sub(97 r'/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}',98 '/{uuid}', normalized)99100 ep = api_endpoints[normalized]101 ep["methods"].add(method)102 ep["count"] += 1103104 # Detect authentication type105 for header in entry["request"]["headers"]:106 name = header["name"].lower()107 if name == "authorization":108 if "bearer" in header["value"].lower():109 ep["auth_types"].add("Bearer/JWT")110 elif "basic" in header["value"].lower():111 ep["auth_types"].add("Basic")112 elif name == "x-api-key":113 ep["auth_types"].add("API Key")114115 # Detect content type116 content_type = next(117 (h["value"] for h in entry["request"]["headers"]118 if h["name"].lower() == "content-type"), None)119 if content_type:120 ep["content_types"].add(content_type.split(";")[0])121122 print(f"Discovered {len(api_endpoints)} unique API endpoints:\n")123 for url, info in sorted(api_endpoints.items()):124 methods = ", ".join(sorted(info["methods"]))125 auth = ", ".join(info["auth_types"]) or "None"126 print(f" [{methods}] {url}")127 print(f" Auth: {auth} | Requests: {info['count']}")128129 return api_endpoints130```131132### Step 2: Active API Endpoint Discovery133134```bash135# DNS enumeration for API subdomains136amass enum -d example.com -o amass_results.txt137subfinder -d example.com -o subfinder_results.txt138139# Filter for API-related subdomains140grep -iE '(api|rest|graphql|ws|gateway|backend|internal|staging|dev|v1|v2)' \141 amass_results.txt subfinder_results.txt | sort -u > api_subdomains.txt142143# Check which subdomains are alive144cat api_subdomains.txt | httpx -status-code -content-length -title \145 -tech-detect -o live_apis.txt146147> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.