This commit is contained in:
2026-05-28 18:42:50 -04:00
parent e671ec8ea5
commit ffb9fd50aa
6 changed files with 270 additions and 351 deletions

View File

@@ -0,0 +1,47 @@
# falco.yaml: Configuración mínima para QueComanTierra con respuesta activa
#
# Falco por defecto sólo DETECTA. Con program_output le decimos que pipe
# cada alerta que coincida con una regla CRITICAL/WARNING al response script.
rules_file:
- /etc/falco/falco_rules.yaml # reglas upstream de Falco
- /opt/qct/detection/falco_rules.yaml # reglas QueComanTierra
# ── Salidas ────────────────────────────────────────────────────────────────
json_output: true # el response script consume JSON
# stdout: útil en desarrollo / journald
stdout_output:
enabled: true
# file: persistencia local
file_output:
enabled: true
keep_alive: false
filename: /var/log/falco.log
# program_output: cada alerta se pipe al response handler
# El script recibe el JSON completo en stdin.
# keep_alive: false → proceso nuevo por alerta (más seguro, más lento).
# Para entornos de producción con alto volumen, poner true y manejar
# el stream NDJSON dentro del script.
program_output:
enabled: true
keep_alive: false
program: "/opt/qct/detection/falco_response.sh"
# ── Filtros de prioridad ───────────────────────────────────────────────────
# Solo dispara program_output para WARNING y superior.
# NOTICE/INFO se escriben a log pero no activan respuesta.
priority: warning
# ── Syscall buffer ─────────────────────────────────────────────────────────
# Aumentar si se pierden eventos durante el bulk xargs (Regla 3).
syscall_buf_size_preset: 4 # 4 MB por CPU
# ── Métricas (opcional) ────────────────────────────────────────────────────
metrics:
enabled: true
interval: 60s
resource_utilization_enabled: true

View File

@@ -0,0 +1,77 @@
#!/usr/bin/env bash
# falco_response.sh: Active response handler for QueComanTierra Falco rules
#
# Falco pipes JSON alerts here via program_output.
# Per-rule actions:
# Bash Native TCP Exfiltration → kill PID + ss --kill socket
# Shell Spawning OpenSSL Bulk Enc. → kill PID (kills openssl + parent shell)
# Mass Document Deletion by Shell → kill PID
# Hidden Encrypted Archive in Tmp → kill PID + remove the .enc file
#
# IMPORTANT: runs as root (Falco requirement). Validate PIDs before killing.
set -euo pipefail
LOG="/var/log/falco-response.log"
ALERT=$(cat) # full JSON from Falco
log() { echo "$(date -u +%FT%TZ) [RESPONSE] $*" | tee -a "$LOG" >&2; }
rule=$(echo "$ALERT" | jq -r '.rule')
pid=$(echo "$ALERT" | jq -r '.output_fields["proc.pid"] // empty')
dst_ip=$(echo "$ALERT" | jq -r '.output_fields["fd.rip"] // empty')
dst_port=$(echo "$ALERT"| jq -r '.output_fields["fd.rport"]// empty')
file=$(echo "$ALERT" | jq -r '.output_fields["fd.name"] // empty')
user=$(echo "$ALERT" | jq -r '.output_fields["user.name"]// empty')
log "RULE='$rule' PID='$pid' USER='$user'"
kill_pid() {
local p="$1"
# Validate: PID must be numeric and process must still exist
[[ "$p" =~ ^[0-9]+$ ]] || { log "PID inválido: $p"; return 1; }
[[ -d "/proc/$p" ]] || { log "PID $p ya no existe"; return 0; }
log "KILL -9 $p ($(cat /proc/$p/cmdline | tr '\0' ' '))"
kill -9 "$p" && log "PID $p terminado" || log "No se pudo matar $p"
}
kill_socket() {
local ip="$1" port="$2"
[[ -n "$ip" && -n "$port" ]] || return 0
log "Cerrando socket TCP → $ip:$port"
# ss --kill requiere iproute2 >= 5.3
ss --kill state established dst "${ip}:${port}" 2>>"$LOG" \
&& log "Socket $ip:$port cerrado" \
|| log "ss --kill falló (¿iproute2 < 5.3?)"
}
case "$rule" in
"Bash Native TCP Exfiltration")
log "ACCIÓN: matar proceso + cerrar socket"
kill_pid "$pid"
kill_socket "$dst_ip" "$dst_port"
;;
"Shell Spawning OpenSSL Bulk Encryption")
log "ACCIÓN: matar proceso openssl"
kill_pid "$pid"
;;
"Mass Document Deletion by Shell Process")
log "ACCIÓN: matar proceso de borrado masivo"
kill_pid "$pid"
;;
"Hidden Encrypted Archive Staged in Tmp")
log "ACCIÓN: matar proceso + eliminar vault"
kill_pid "$pid"
if [[ -n "$file" && "$file" == /tmp/*.enc && "$file" == /tmp/.* ]]; then
log "Eliminando vault cifrado: $file"
rm -f "$file" && log "Vault eliminado" || log "No se pudo eliminar $file"
fi
;;
*)
log "Regla desconocida, sin acción automática: $rule"
;;
esac

View File

@@ -56,8 +56,7 @@
openssl enc desde shell, posible cifrado masivo
(user=%user.name uid=%user.uid
cmd=%proc.cmdline
parent=%proc.pname ppid=%proc.ppid
container=%container.name)
parent=%proc.pname ppid=%proc.ppid)
priority: WARNING
tags: [lolbin, ransomware, T1486, T1059.004]
@@ -90,8 +89,7 @@
bash abrió conexión TCP directa, posible /dev/tcp exfiltración
(user=%user.name uid=%user.uid
dst=%fd.rip:%fd.rport
pid=%proc.pid cmd=%proc.cmdline
container=%container.name)
pid=%proc.pid cmd=%proc.cmdline)
priority: CRITICAL
tags: [lolbin, exfiltration, T1048, T1059.004]
@@ -120,8 +118,7 @@
documento de usuario eliminado por proceso shell
(user=%user.name uid=%user.uid
file=%fd.name
proc=%proc.name cmd=%proc.cmdline
container=%container.name)
proc=%proc.name cmd=%proc.cmdline)
priority: WARNING
tags: [ransomware, destruction, T1486]
@@ -149,7 +146,6 @@
archivo cifrado oculto creado en /tmp, posible vault de ransomware
(user=%user.name uid=%user.uid
file=%fd.name
proc=%proc.name cmd=%proc.cmdline
container=%container.name)
proc=%proc.name cmd=%proc.cmdline)
priority: CRITICAL
tags: [ransomware, staging, T1486, T1074]