CAPA: Detección Automática de Capacidades de Malware
Guía práctica de CAPA de Mandiant para detección automática de capacidades de malware. Cómo funciona, interpretación de resultados, mapeo a MITRE ATT&CK, reglas custom, y integración en pipelines de análisis automatizado.
CAPA: responde "qué hace este malware" en 30 segundos
CAPA es la herramienta más eficiente para triage de muestras de malware. Un solo comando analiza un binario y produce un listado de sus capacidades mapeadas a MITRE ATT&CK, sin ejecutar la muestra y sin escribir reglas. Creada por el equipo FLARE de Mandiant, CAPA usa más de 800 reglas para identificar comportamiento malicioso.
Uso básico
# Analizar un PE
capa sample.exe
# Analizar un ELF
capa sample_linux
# Analizar shellcode
capa -f sc32 shellcode.bin # 32-bit shellcode
capa -f sc64 shellcode.bin # 64-bit shellcode
# Output verbose (mas detalle)
capa -v sample.exe
# Output muy verbose (reglas que coincidieron con ubicacion)
capa -vv sample.exe
# Output JSON (para automatizacion)
capa -j sample.exe > results.json
Interpretación del output
Output estándar
+-----------------------------+-------------------------------------------+
| ATT&CK Tactic | ATT&CK Technique |
|-----------------------------+-------------------------------------------|
| DEFENSE EVASION | Obfuscated Files or Information [T1027] |
| DISCOVERY | System Information Discovery [T1082] |
| COLLECTION | Input Capture: Keylogging [T1056.001] |
| COMMAND AND CONTROL | Application Layer Protocol [T1071] |
| EXFILTRATION | Exfiltration Over C2 Channel [T1041] |
+-----------------------------+-------------------------------------------+
+-----------------------------+-------------------------------------------+
| MBC Objective | MBC Behavior |
|-----------------------------+-------------------------------------------|
| ANTI-BEHAVIORAL ANALYSIS | Virtual Machine Detection [B0009] |
| COMMUNICATION | HTTP Communication [C0002] |
| CRYPTOGRAPHY | Encrypt Data [C0027] |
| DATA | Keylogging [F0002] |
| FILE SYSTEM | Write File [C0052] |
+-----------------------------+-------------------------------------------+
+-----------------------------+-------------------------------------------+
| Capability | Namespace |
|-----------------------------+-------------------------------------------|
| receive data | communication |
| send data | communication |
| capture keyboard input | collection/keylog |
| create process | host-interaction/process |
| encrypt data using AES | data-manipulation/encryption |
| check for virtual machine | anti-analysis/vm-detection |
| persist via Run key | persistence/registry |
| connect to HTTP server | communication/http |
+-----------------------------+-------------------------------------------+
Qué significa cada sección
| Sección | Significado |
|---|---|
| ATT&CK Tactic/Technique | Mapeo a MITRE ATT&CK. Las tácticas y técnicas que el malware puede implementar |
| MBC Objective/Behavior | Mapeo al Malware Behavior Catalog. Más granular que ATT&CK para malware |
| Capability | Descripción legible de lo que el malware puede hacer |
| Namespace | Categoría de la capacidad (communication, persistence, collection, etc.) |
Output verbose (-v)
capa -v sample.exe
# Muestra QUE regla coincidio y POR QUE:
#
# persist via Run key
# author: Mandiant
# scope: function
# att&ck: T1547.001
# references:
# - https://attack.mitre.org/techniques/T1547/001/
# matched:
# - api: RegSetValueExA @ 0x401234
# - string: "Software\\Microsoft\\Windows\\CurrentVersion\\Run" @ 0x402000
Reglas de CAPA
Estructura de una regla
rule:
meta:
name: persist via Run key
namespace: persistence/registry
authors:
- [email protected]
scopes:
static: function
att&ck:
- Persistence::Boot or Logon Autostart Execution::Registry Run Keys [T1547.001]
mbc:
- Persistence::Registry Run Keys/Startup Folder [F0012]
features:
- and:
- api: RegSetValueEx
- or:
- string: "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
- string: "Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce"
Escribir reglas custom
# Regla custom: detectar comunicacion con Telegram Bot API
rule:
meta:
name: communicate via Telegram Bot API
namespace: communication/telegram
authors:
- malwareintel
scopes:
static: function
att&ck:
- Command and Control::Application Layer Protocol [T1071]
features:
- and:
- or:
- string: "api.telegram.org"
- string: "/bot"
- string: "sendMessage"
- or:
- api: InternetOpenUrl
- api: HttpSendRequest
- api: WinHttpSendRequest
# Usar regla custom
capa -r /path/to/custom/rules/ sample.exe
Estadísticas de reglas (v7+)
CAPA incluye 800+ reglas organizadas por namespace:
| Namespace | Ejemplos |
|---|---|
communication/ | HTTP, DNS, TCP, SMTP, FTP, IRC |
persistence/ | Registry, scheduled task, service, startup |
collection/ | Keylog, screenshot, clipboard, microphone |
anti-analysis/ | VM detection, debug detection, sandbox detection |
data-manipulation/ | Encrypt (AES, RSA, RC4), compress, encode (base64) |
host-interaction/ | Process (create, inject, hollow), file, registry, service |
impact/ | Encrypt files, wipe, ransomware note |
lateral-movement/ | SMB, WMI, PsExec |
credential-access/ | LSASS, SAM, browser credentials |
Integración en pipelines
Python API
import capa.main
import capa.rules
import capa.render.result_document as rd
# Cargar reglas
rules_path = capa.main.get_default_root()
rules = capa.rules.get_rules([rules_path])
# Analizar muestra
results = capa.main.get_capabilities(rules, "sample.exe")
# Acceder a resultados
for rule_name, matches in results.items():
print(f"Capability: {rule_name}")
for addr in matches:
print(f" At: {hex(addr)}")
En pipeline CAPE
CAPE ejecuta CAPA automáticamente sobre las muestras analizadas. Los resultados aparecen en el informe bajo "CAPA".
En pipeline de triage
#!/bin/bash
# Pipeline: hash → VT → CAPA → YARA → informe
SAMPLE=$1
echo "=== TRIAGE: $SAMPLE ==="
# Hashes
sha256=$(sha256sum "$SAMPLE" | awk '{print $1}')
echo "SHA256: $sha256"
# CAPA
echo -e "\n=== CAPA ==="
capa "$SAMPLE" 2>/dev/null
# YARA
echo -e "\n=== YARA ==="
yara -r /rules/ "$SAMPLE" 2>/dev/null
echo -e "\n=== DONE ==="
Limitaciones
| Limitación | Impacto | Mitigación |
|---|---|---|
| Solo análisis estático | No detecta comportamiento dinámico | Complementar con sandbox |
| Packed binaries | Capacidades ocultas por packing | Desempaquetar primero |
| Dynamic API resolution | APIs resueltas en runtime no visibles | CAPA detecta algunos patrones de resolución dinámica |
| Custom crypto | Si el malware implementa su propio cifrado sin APIs estándar | Análisis manual necesario |
| Shellcode | Soportado pero con menos reglas | Especificar formato con -f |
Mapeo: CAPA namespace a ATT&CK
| CAPA Namespace | ATT&CK Tactic |
|---|---|
persistence/ | Persistence (TA0003) |
collection/ | Collection (TA0009) |
communication/ | Command and Control (TA0011) |
anti-analysis/ | Defense Evasion (TA0005) |
host-interaction/process/inject | Defense Evasion (T1055) |
credential-access/ | Credential Access (TA0006) |
lateral-movement/ | Lateral Movement (TA0008) |
impact/ | Impact (TA0040) |
data-manipulation/encryption | Impact (T1486 si ransomware) |
Fuentes y referencias
- Mandiant. "CAPA: The FLARE Team's Open-Source Tool." https://github.com/mandiant/capa
- Mandiant. "CAPA Rules." https://github.com/mandiant/capa-rules
- Mandiant Blog. "Introducing CAPA." 2020.
- MBC. "Malware Behavior Catalog." https://github.com/MBCProject/mbc-markdown
- MITRE ATT&CK. "Techniques Reference." https://attack.mitre.org/techniques/
Preguntas frecuentes
Libros recomendados
Artículos relacionados
Este contenido tiene fines exclusivamente educativos y de investigación en ciberseguridad defensiva. No se proporcionan binarios maliciosos ni payloads ejecutables. El uso indebido de esta información es responsabilidad exclusiva del usuario. Leer disclaimer completo.