arrow_back Volver a artículos

Guía Completa: Detección de Ataques en PowerShell

Aprende a detectar y monitorizar actividad maliciosa en PowerShell, incluyendo técnicas de evasión y mejores prácticas

Guía Completa: Detección de Ataques en PowerShell
person Guillermo Illera
calendar_today 17 de marzo de 2024
schedule 2 min de lectura
guias PowerShell Detección Logging Windows

Guía Completa: Detección de Ataques en PowerShell

PowerShell es una herramienta legítima que frecuentemente es abusada por atacantes. Esta guía te ayudará a implementar una detección efectiva.

Configuración de Logging

1. Script Block Logging

reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging" /v EnableScriptBlockLogging /t REG_DWORD /d 1

2. Module Logging

reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging" /v EnableModuleLogging /t REG_DWORD /d 1

3. Transcription

reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription" /v EnableTranscripting /t REG_DWORD /d 1

Técnicas de Detección

  1. Ejecución Codificada en Base64

    title: PowerShell Base64 Encoded Command
    detection:
      encoded_cmd:
        - "-enc"
        - "-encodedcommand"
      condition: any
    
  2. Descarga de Archivos

    title: PowerShell Download Cradles
    detection:
      download_methods:
        - "Invoke-WebRequest"
        - "wget"
        - "curl"
        - "Net.WebClient"
      condition: any
    
  3. Bypass de AMSI

    title: AMSI Bypass Attempt
    detection:
      keywords:
        - "AmsiUtils"
        - "[Ref].Assembly.GetType"
        - "System.Management.Automation.AmsiUtils"
      condition: any
    

Casos de Uso SIEM

Sigma Rule Example

title: Suspicious PowerShell Execution
status: experimental
description: Detects suspicious PowerShell execution patterns
detection:
    selection:
        EventID: 4104
        ScriptBlockText|contains:
            - "Hidden"
            - "Bypass"
            - "Encoded"
    condition: selection
falsepositives:
    - Legitimate administrative scripts
level: medium

Mejores Prácticas

  1. Restricción de Ejecución

    • Implementar AppLocker
    • Usar Constrained Language Mode
    • Limitar ejecución remota
  2. Monitorización

    • Centralizar logs
    • Configurar alertas
    • Revisar regularmente
  3. Respuesta

    • Documentar incidentes
    • Analizar patrones
    • Actualizar reglas

Herramientas Recomendadas

  • PowerShell Empire Detection
  • DeepBlueCLI
  • KAPE
  • Sysmon

Referencias