← Laboratorios
🐷 Lab · TLS Detection · Snort / Suricata

Snort / Suricata β€” DetecciΓ³n TLS con JA3

Reglas de detecciΓ³n en tiempo real para identificar huellas TLS maliciosas usando Snort 3 y Suricata. Incluye ejemplos de C2 conocidos y tΓ©cnicas de evasiΓ³n.

Snort 3 y Suricata soportan la palabra clave ja3.hash (Suricata) y ssl_state + content (Snort 3) para detectar huellas JA3 directamente en el flujo TLS sin necesidad de descifrar el trΓ‘fico.

Estructura de una regla Snort 3 / Suricata

SNORT RULE SYNTAX AnatomΓ­a de una regla β€” cada campo explicado
β”Œβ”€ AcciΓ³n: alert | drop | pass | log
β”‚  β”Œβ”€ Protocolo: tcp | udp | tls | http | dns
β”‚  β”‚  β”Œβ”€ IP Origen   β”Œβ”€ Puerto Origen
β”‚  β”‚  β”‚              β”‚       β”Œβ”€ DirecciΓ³n del flujo: β†’ (unidireccional) | <> (bidireccional)
β”‚  β”‚  β”‚              β”‚       β”‚   β”Œβ”€ IP Destino     β”Œβ”€ Puerto Destino
β”‚  β”‚  β”‚              β”‚       β”‚   β”‚                  β”‚
alert tls $HOME_NET any -> $EXTERNAL_NET $HTTPS_PORTS \
(
  msg:"JA3 - Metasploit Meterpreter detectado";    ← Mensaje de alerta
  ja3.hash; content:"e7d705a3286e19ea42f587b344ee6865";  ← DetecciΓ³n del hash
  flow:established,to_server;                        ← DirecciΓ³n del flujo TLS
  classtype:trojan-activity;                         ← ClasificaciΓ³n MITRE/Snort
  sid:9000001;                                       ← ID ΓΊnico de la regla
  rev:1;                                             ← RevisiΓ³n
  metadata:affected_product Any, attack_target Client_Endpoint,
           created_at 2024_01_01, deployment Perimeter,
           performance_impact Low, signature_severity Critical,
           updated_at 2024_01_01;                    ← Metadatos opcionales pero ΓΊtiles
)

Variables de red β€” snort.conf / suricata.yaml

SNORT CONFIG Variables a configurar antes de usar las reglas
# En snort.conf (Snort 3) o suricata.yaml

# Red interna β€” ajustar a tu topologΓ­a
ipvar HOME_NET [192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12]

# Puertos HTTPS estΓ‘ndar y alternativos
portvar HTTPS_PORTS [443, 8443, 4443, 8080, 8888]

# Puertos no estΓ‘ndar donde puede ocurrir C2 vΓ­a TLS
portvar C2_PORTS [4444, 5555, 1337, 8888, 9999, 55553]

# InspecciΓ³n TLS habilitada
config enable_deep_teredo_inspection  # si corresponde
# preprocessor ssl: trustservers, noinspect_encrypted

Clases de alerta relevantes para JA3

Classtype Prioridad Uso
trojan-activity 1 (CrΓ­tica) Malware confirmado: Emotet, Dridex, Meterpreter
attempted-intrusion 1 (Alta) Frameworks de ataque: Metasploit, Cobalt Strike
policy-violation 2 (Media) Herramientas dual-use: curl no autorizado, Go tools
suspicious-activity 2 (Media) JA3 inusual sin clasificar, TLS en puertos no estΓ‘ndar
network-scan 3 (Baja) Nmap SSL scanning, reconocimiento

Snort 3 incluye el keyword ja3.hash de forma nativa desde la versiΓ³n 3.1.x con el plugin TLS. Las reglas detectan el hash en el primer paquete del handshake sin necesidad de descifrar el trΓ‘fico.

Reglas de detecciΓ³n β€” Malware C2 conocido

SNORT 3 RULES local.rules β€” frameworks de ataque confirmados
# ── METASPLOIT METERPRETER ────────────────────────────────────────────────
# JA3: e7d705a3286e19ea42f587b344ee6865
# Detecta el Client Hello de Meterpreter en cualquier puerto TLS.
# Meterpreter usa un set de cipher suites muy bΓ‘sico y antiguo (SSLv3/TLS1.0).
alert tls $HOME_NET any -> $EXTERNAL_NET any (
  msg:"SOC-LAB JA3 Metasploit Meterpreter Activity";
  ja3.hash; content:"e7d705a3286e19ea42f587b344ee6865";
  flow:established,to_server;
  classtype:trojan-activity;
  priority:1;
  sid:9000001; rev:2;
)

# ── COBALT STRIKE β€” DEFAULT PROFILE (pre-4.x) ─────────────────────────────
# JA3: de350869b8c85de67a350c8d186f11e6
# Importante: Cobalt Strike 4.x con Malleable C2 puede cambiar esta huella.
# Complementar con detecciΓ³n de certificate fingerprint (JA3S).
alert tls $HOME_NET any -> $EXTERNAL_NET any (
  msg:"SOC-LAB JA3 Cobalt Strike Default Beacon";
  ja3.hash; content:"de350869b8c85de67a350c8d186f11e6";
  flow:established,to_server;
  classtype:trojan-activity;
  priority:1;
  sid:9000002; rev:2;
)

# ── EMOTET C2 ─────────────────────────────────────────────────────────────
alert tls $HOME_NET any -> $EXTERNAL_NET any (
  msg:"SOC-LAB JA3 Emotet C2 Communication";
  ja3.hash; content:"8bab54f22de07d88e90f5e8e5edb5a69";
  flow:established,to_server;
  classtype:trojan-activity;
  priority:1;
  sid:9000003; rev:1;
)

# ── DRIDEX / BITPAYMER ────────────────────────────────────────────────────
alert tls $HOME_NET any -> $EXTERNAL_NET any (
  msg:"SOC-LAB JA3 Dridex Exfiltration";
  ja3.hash; content:"19e29534fd49dd27d09234e7b95b86c1";
  flow:established,to_server;
  classtype:trojan-activity;
  priority:1;
  sid:9000004; rev:1;
)

Reglas para herramientas dual-use

SNORT 3 RULES dual-use.rules β€” herramientas legΓ­timas usadas maliciosamente
# ── PYTHON REQUESTS / urllib3 ─────────────────────────────────────────────
# LegΓ­timo en servidores de producciΓ³n, sospechoso en workstations.
# La regla solo alerta desde hosts NO clasificados como servidores.
alert tls $HOME_NET any -> $EXTERNAL_NET $HTTPS_PORTS (
  msg:"SOC-LAB JA3 Python requests β€” verificar legitimidad";
  ja3.hash; content:"b386946a5a44d1ddcc843bc75336dfce";
  flow:established,to_server;
  classtype:policy-violation;
  priority:2;
  sid:9000010; rev:1;
)

# ── GOLANG DEFAULT TLS ────────────────────────────────────────────────────
# Muchas herramientas de red escritas en Go: legΓ­timas e ilegΓ­timas.
# Correlacionar con reputaciΓ³n de IP destino.
alert tls $HOME_NET any -> $EXTERNAL_NET any (
  msg:"SOC-LAB JA3 Golang Default TLS β€” revisar contexto";
  ja3.hash; content:"51c64c77e60f3980eea90869b68c58a8";
  flow:established,to_server;
  classtype:suspicious-activity;
  priority:2;
  sid:9000011; rev:1;
)

# ── TOR BROWSER / CS OVERLAP ─────────────────────────────────────────────
# Hash compartido por Tor y algunos configs de CS. Alto FP si hay usuarios Tor legΓ­timos.
alert tls $HOME_NET any -> $EXTERNAL_NET any (
  msg:"SOC-LAB JA3 Tor/CS overlap β€” investigar destino";
  ja3.hash; content:"a0e9f5d64349fb13191bc781f81f42e1";
  flow:established,to_server;
  classtype:suspicious-activity;
  priority:2;
  sid:9000012; rev:1;
)

Reglas basadas en patrones de cipher suites

SNORT 3 RULES anomaly.rules β€” detecciΓ³n por comportamiento, sin hash fijo
# ── TLS CON CIPHER NULL (sin cifrado real) ───────────────────────────────
# TLS_NULL_WITH_NULL_NULL = 0x0000 β€” trΓ‘fico en claro dentro del handshake
# Nunca deberΓ­a verse en trΓ‘fico legΓ­timo de producciΓ³n
alert tls $HOME_NET any -> any any (
  msg:"SOC-LAB TLS NULL Cipher Suite β€” posible evasiΓ³n/debug";
  ssl_state:client_hello;
  content:"|00 00|"; offset:40; depth:200;
  classtype:suspicious-activity;
  priority:1;
  sid:9000020; rev:1;
)

# ── TLS EN PUERTO NO ESTÁNDAR ─────────────────────────────────────────────
# C2 sobre TLS en puertos 4444, 5555, 8888, etc.
# Snort necesita deep inspection habilitado para ver el handshake
alert tcp $HOME_NET any -> $EXTERNAL_NET [4444,5555,1337,9999,8888,55553] (
  msg:"SOC-LAB TLS Handshake en puerto C2 conocido";
  ssl_state:client_hello;
  flow:established,to_server;
  classtype:suspicious-activity;
  priority:2;
  sid:9000021; rev:1;
)

# ── CLIENT HELLO SIN SNI ──────────────────────────────────────────────────
# La extensiΓ³n SNI (type 0x0000) estΓ‘ presente en casi todos los browsers.
# Su ausencia sugiere herramienta de lΓ­nea de comandos o malware.
# Offset depende de la estructura exacta del TLS record β€” ajustar en lab.
alert tls $HOME_NET any -> $EXTERNAL_NET $HTTPS_PORTS (
  msg:"SOC-LAB TLS Client Hello sin extensiΓ³n SNI";
  ssl_state:client_hello;
  content:!"|00 00|"; offset:45; depth:20;  # PosiciΓ³n aproximada de extension type 0
  classtype:suspicious-activity;
  priority:3;
  sid:9000022; rev:1;
)

Suricata tiene soporte nativo de JA3 y JA3S desde la versiΓ³n 4.1. Los keywords ja3.hash, ja3.string, ja3s.hash y ja3s.string permiten una sintaxis mΓ‘s limpia que Snort para detecciΓ³n TLS.

Suricata β€” Reglas JA3 nativas

SURICATA RULES suricata-ja3.rules β€” sintaxis nativa de Suricata
# ── METASPLOIT con ja3.hash nativo ───────────────────────────────────────
alert tls any any -> any any (
  msg:"SURICATA JA3 Metasploit Meterpreter";
  ja3.hash; content:"e7d705a3286e19ea42f587b344ee6865";
  sid:9100001; rev:1;
  classtype:trojan-activity;
)

# ── COBALT STRIKE ─────────────────────────────────────────────────────────
alert tls any any -> any any (
  msg:"SURICATA JA3 Cobalt Strike Default";
  ja3.hash; content:"de350869b8c85de67a350c8d186f11e6";
  sid:9100002; rev:1;
  classtype:trojan-activity;
)

# ── JA3 + JA3S (server side) β€” DETECCIΓ“N BIDIRECCIONAL ───────────────────
# JA3S es la huella del SERVER Hello β€” permite identificar el C2 server.
# El par (JA3, JA3S) es mΓ‘s especΓ­fico que cualquiera de los dos solos.
# JA3S de Cobalt Strike default: 649d6810e8392f63dc311eecb6b7098b
alert tls any any -> any any (
  msg:"SURICATA JA3+JA3S Cobalt Strike bidireccional";
  ja3.hash; content:"de350869b8c85de67a350c8d186f11e6";
  ja3s.hash; content:"649d6810e8392f63dc311eecb6b7098b";
  sid:9100003; rev:1;
  classtype:trojan-activity;
)

# ── BUSCAR POR STRING JA3 (sin hash β€” ΓΊtil para anΓ‘lisis) ─────────────────
# ja3.string contiene el string pre-MD5 β€” permite buscar patrones en las listas
# Ejemplo: detectar cualquier client con versiΓ³n TLS 769 (TLS 1.0)
alert tls any any -> any any (
  msg:"SURICATA JA3 versiΓ³n TLS 1.0 β€” legacy/sospechoso";
  ja3.string; content:"769,"; startswith;
  sid:9100010; rev:1;
  classtype:suspicious-activity;
)

# ── CIPHER LIST MUY CORTA β€” posible tool simple/malware ──────────────────
# JA3 strings de Metasploit empiezan con la versiΓ³n + pocos ciphers
alert tls any any -> any any (
  msg:"SURICATA JA3 cipher list mΓ­nima β€” investigar cliente";
  ja3.string; content:"769,4,5,10,9,100,"; startswith;
  sid:9100011; rev:1;
  classtype:suspicious-activity;
)

Configurar Suricata para JA3 β€” suricata.yaml

YAML suricata.yaml β€” habilitar logging JA3
# En suricata.yaml β€” habilitar el output de eve.json con JA3
outputs:
  - eve-log:
      enabled: yes
      filetype: regular
      filename: /var/log/suricata/eve.json
      types:
        - alert:
            # Incluir campos TLS en alerts
            metadata: yes
        - tls:
            # ─── CRÍTICO: habilitar campos JA3 en logs TLS ───
            enabled: yes
            extended: yes    # Incluye ja3, ja3s, sni, cert hash
            custom:
              - ja3          # Hash JA3 del client
              - ja3s         # Hash JA3S del server
              - sni          # Server Name Indication
              - version      # VersiΓ³n TLS negociada
              - certificate  # Fingerprint del certificado
              - issuer       # Emisor del certificado

# Habilitar la inspecciΓ³n TLS
app-layer:
  protocols:
    tls:
      enabled: yes
      detection-ports:
        dp: 443, 8443, 4443     # Agregar puertos C2 si detectΓ‘s beaconing

# Si usΓ‘s reglas JA3, asegurar que el fichero de reglas estΓ© referenciado:
rule-files:
  - /etc/suricata/rules/suricata-ja3.rules
  - /etc/suricata/rules/local.rules

Verificar que JA3 funciona

BASH Testear extracciΓ³n JA3 en Suricata
# Correr Suricata sobre un PCAP de prueba y ver el JSON
suricata -r captura.pcap -l /tmp/suricata-output/ -c /etc/suricata/suricata.yaml

# Ver eventos TLS con JA3 en el output JSON
cat /tmp/suricata-output/eve.json | python3 -m json.tool | grep -A 20 '"event_type": "tls"'

# Ejemplo de salida esperada:
# {
#   "timestamp": "2024-01-15T10:30:00.000000+0000",
#   "event_type": "tls",
#   "src_ip": "192.168.1.105",
#   "dest_ip": "185.220.101.4",
#   "tls": {
#     "sni": "update.evil.example.com",
#     "version": "TLS 1.2",
#     "ja3": {
#       "hash": "e7d705a3286e19ea42f587b344ee6865",
#       "string": "769,4-5-10-9-100-98-3-6-19-18-99,15,"
#     }
#   }
# }

# Ver solo alerts de JA3 malicioso
jq 'select(.event_type == "alert" and .alert.signature | startswith("SURICATA JA3"))' \
  /tmp/suricata-output/eve.json

Los falsos positivos (FP) son el mayor problema de las reglas JA3. Un hash que coincide con Metasploit puede tambiΓ©n ser generado por una aplicaciΓ³n legacy legΓ­tima. El tuning es crΓ­tico para un SIEM efectivo.

Estrategias para reducir FP

1
Modo detecciΓ³n antes de bloqueo

Empezar con alert, nunca con drop directamente. Correr la regla en modo IDS (solo detecciΓ³n) por 5-7 dΓ­as. Analizar los hits: ΒΏson IPs internas conocidas? ΒΏHorarios de negocio? ΒΏDestinos en whitelist? Solo convertir a drop cuando la precisiΓ³n es > 95%.

2
Excluir IPs y subredes conocidas

Usando la variable $HOME_NET y listas de exclusiΓ³n en Snort/Suricata. Si tenΓ©s servidores de build que usan curl intensivamente, excluirlos del scope de la regla: alert tls $HOME_NET !$BUILD_SERVERS -> $EXTERNAL_NET any (...)

3
Correlacionar con reputaciΓ³n de IP destino

Una conexiΓ³n con JA3 de curl hacia 8.8.8.8 (DNS de Google) es legΓ­tima. La misma conexiΓ³n hacia 185.220.x.x (Tor exit nodes) o una IP en Shodan con puertos 4444 abiertos merece investigaciΓ³n. Usar threat intel feeds en paralelo con la detecciΓ³n JA3.

4
Usar threshold para alertas repetidas

En Snort 3: keyword threshold para no generar 1000 alertas de la misma conexiΓ³n C2. En Suricata: detection-filter. Ejemplo: alerta una vez por minuto por IP destino ΓΊnico, no en cada paquete del stream.

Threshold y suppress en Snort 3

SNORT 3 CONFIG threshold.conf β€” control de volumen de alertas
# ── THRESHOLD β€” limitar alertas por IP fuente ─────────────────────────────
# Generar alerta solo la primera vez por IP fuente en un perΓ­odo de 5 minutos
# Evita flood de alertas de un C2 en beaconing continuo
threshold gen_id 1, sig_id 9000001, type limit, track by_src, count 1, seconds 300

# ── SUPPRESS β€” silenciar un host especΓ­fico (whitelist) ───────────────────
# Si un servidor legΓ­timo genera FP con la regla 9000010 (Python requests),
# suprimir para esa IP especΓ­fica
suppress gen_id 1, sig_id 9000010, track by_src, ip 10.10.1.55

# ── SUPPRESS por red completa ─────────────────────────────────────────────
# Suprimir regla de curl para todos los servidores de CI/CD
suppress gen_id 1, sig_id 9000010, track by_src, ip 10.10.100.0/24

# ── DETECTION FILTER en Suricata (equivalente) ────────────────────────────
# En la regla, agregar el keyword detection_filter:
alert tls $HOME_NET any -> $EXTERNAL_NET any (
  msg:"SURICATA JA3 Golang Default TLS";
  ja3.hash; content:"51c64c77e60f3980eea90869b68c58a8";
  detection_filter: track by_src, count 5, seconds 60;  ← mΓ­nimo 5 veces en 60s
  sid:9100015; rev:1;
)

Resumen β€” ΒΏCuΓ‘ndo usar quΓ© enfoque?

Escenario Enfoque recomendado Riesgo de FP
Hash JA3 = Metasploit confirmado Regla con drop en IPS mode Muy bajo
Hash JA3 = Cobalt Strike default Alert + correlaciΓ³n con IP reputation Bajo
Hash JA3 = curl / Python Alert solo en workstations, no en servidores Medio
JA3 hash de Golang Alert con threshold + correlaciΓ³n Alto
TLS en puerto no estΓ‘ndar Alert, investigaciΓ³n manual Medio
Client Hello sin SNI Alert con baja prioridad, revisiΓ³n periΓ³dica Alto

CorrelaciΓ³n multi-evento con flowbits

Los flowbits permiten correlacionar mΓΊltiples eventos en la misma sesiΓ³n TCP. Esto reduce falsos positivos al requerir que se cumplan dos condiciones para generar una alerta.

snort3 CorrelaciΓ³n JA3 + Data Exfil con flowbits
# Paso 1: Detectar sesiΓ³n con JA3 Cobalt Strike y marcarla
alert tls any any -> any any (
  msg:"JA3 Cobalt Strike detectado β€” sesiΓ³n marcada";
  flow:established,to_server;
  ja3.hash; content:"de350869b8c85de67a350c8d186f11e6"; nocase;
  flowbits:set,ja3.cobaltstrike;
  flowbits:noalert;
  classtype:trojan-activity;
  sid:9000010; rev:1;
)

# Paso 2: Alertar si la sesiΓ³n marcada transfiere datos
alert tcp any any -> any any (
  msg:"Cobalt Strike β€” transferencia de datos post-JA3";
  flow:established;
  flowbits:isset,ja3.cobaltstrike;
  dsize:>1024;
  threshold:type both, track by_src, count 5, seconds 60;
  classtype:trojan-activity;
  sid:9000011; rev:1;
)

# Paso 3: Limpiar el flowbit al cerrar sesiΓ³n
alert tcp any any -> any any (
  msg:"Cobalt Strike β€” sesiΓ³n finalizada";
  flow:established;
  flowbits:isset,ja3.cobaltstrike;
  flags:F;
  flowbits:unset,ja3.cobaltstrike;
  flowbits:noalert;
  sid:9000012; rev:1;
)
La correlaciΓ³n flowbits es mucho mΓ‘s robusta que una regla JA3 simple: requiere que el fingerprint sospechoso estΓ© activo Y que la sesiΓ³n transfiera datos. Esto elimina falsos positivos de scanners o herramientas legΓ­timas que usan el mismo JA3 sin transferir payload.

Falsos positivos comunes y mitigaciΓ³n

Algunas herramientas legΓ­timas generan JA3 idΓ©nticos o similares a los de malware. Es fundamental mantener una whitelist y ajustar las reglas antes de producciΓ³n.

Herramienta / Contexto JA3 / Comportamiento AcciΓ³n recomendada
curl / libcurl 51c64c77... (documentado) Whitelist IPs de servidores conocidos
Python requests (urllib3) VarΓ­a con versiΓ³n OpenSSL Correlacionar con User-Agent + IP
Go net/http 72a589da... (similar a malware) Validar dominio destino + IP reputaciΓ³n
Scanners internos (Nessus, Qualys) JA3 de herramienta conocida Suppress por IP scanner: suppress gen_id 1, sig_id 9000001, track by_src, ip 10.0.0.50
Software corporativo (Slack, Teams) Electron/Chrome JA3 Whitelist por dominio destino (.slack.com)
⚠️ ESTRATEGIA DE TUNING Nunca desplegar reglas JA3 directamente en modo block/drop en producción. Primero desplegÑ en alert-only durante 2 semanas, analizÑ los falsos positivos y construí tu suppress list antes de activar bloqueo.

ContinuΓ‘ el lab TLS: JA3 Core Β· Wireshark Β· QRadar Β· FortiGate Β· TeorΓ­a TLS

← Volver al inicio