Detection rules › Sigma

Manual Execution of Script Inside of a Compressed File

Status
test
Severity
medium
Author
@kostastsale
Source
github.com/SigmaHQ/sigma

This is a threat-hunting query to collect information related to the interactive execution of a script from inside a compressed file (zip/rar). Windows will automatically run the script using scripting interpreters such as wscript and cscript binaries. From the query below, the child process is the script interpreter that will execute the script. The script extension is also a set of standard extensions that Windows OS recognizes. Selections 1-3 contain three different execution scenarios. 1. Compressed file opened using 7zip. 2. Compressed file opened using WinRar. 3. Compressed file opened using native windows File Explorer capabilities. When the malicious script is double-clicked, it will be extracted to the respected directories as signified by the CommandLine on each of the three Selections. It will then be executed using the relevant script interpreter."

MITRE ATT&CK coverage

Event coverage

Rule body yaml

title: Manual Execution of Script Inside of a Compressed File
id: 95724fc1-a258-4674-97db-a30351981c5a
status: test
description: |
    This is a threat-hunting query to collect information related to the interactive execution of a script from inside a compressed file (zip/rar). Windows will automatically run the script using scripting interpreters such as wscript and cscript binaries.

    From the query below, the child process is the script interpreter that will execute the script. The script extension is also a set of standard extensions that Windows OS recognizes. Selections 1-3 contain three different execution scenarios.
        1. Compressed file opened using 7zip.
        2. Compressed file opened using WinRar.
        3. Compressed file opened using native windows File Explorer capabilities.

    When the malicious script is double-clicked, it will be extracted to the respected directories as signified by the CommandLine on each of the three Selections. It will then be executed using the relevant script interpreter."
references:
    - https://app.any.run/tasks/25970bb5-f864-4e9e-9e1b-cc8ff9e6386a
    - https://app.any.run/tasks/fa99cedc-9d2f-4115-a08e-291429ce3692
author: '@kostastsale'
date: 2023-02-15
modified: 2024-08-13
tags:
    - attack.execution
    - attack.t1059
    - detection.threat-hunting
logsource:
    category: process_creation
    product: windows
detection:
    selection_parent_7zip:
        ParentImage|endswith: '\7z*.exe'
        CommandLine|contains: '\AppData\local\temp\7z*\'
    selection_parent_winrar:
        ParentImage|endswith: '\winrar.exe'
        CommandLine|contains: '\AppData\local\temp\rar*\'
    selection_parent_explorer:
        ParentImage|endswith: '\explorer.exe'
        CommandLine|contains:
            - '\AppData\local\temp\*.rar\'
            - '\AppData\local\temp\*.zip\'
    selection_child:
        Image|endswith:
            - '\cscript.exe'
            - '\mshta.exe'
            - '\powershell.exe'
            - '\pwsh.exe'
            - '\wscript.exe'
        CommandLine|endswith:
            - '.hta'
            - '.js'
            - '.jse'
            - '.ps1'
            - '.vbe'
            - '.vbs'
            - '.wsf'
            - '.wsh'
    condition: 1 of selection_parent_* and selection_child
falsepositives:
    - Batch files may produce a lot of noise, as many applications appear to bundle them as part of their installation process. You should baseline your environment and generate a new query excluding the noisy and expected activity. Some false positives may come up depending on your environment. All results should be investigated thoroughly before filtering out results.
level: medium

Stages and Predicates

Stage 0: condition

1 of selection_parent_* and selection_child

Stage 1: selection_parent_7zip

selection_parent_7zip:
    ParentImage|endswith: '\7z*.exe'
    CommandLine|contains: '\AppData\local\temp\7z*\'

Stage 2: selection_parent_winrar

selection_parent_winrar:
    ParentImage|endswith: '\winrar.exe'
    CommandLine|contains: '\AppData\local\temp\rar*\'

Stage 3: selection_parent_explorer

selection_parent_explorer:
    ParentImage|endswith: '\explorer.exe'
    CommandLine|contains:
        - '\AppData\local\temp\*.rar\'
        - '\AppData\local\temp\*.zip\'

Stage 4: selection_child

selection_child:
    Image|endswith:
        - '\cscript.exe'
        - '\mshta.exe'
        - '\powershell.exe'
        - '\pwsh.exe'
        - '\wscript.exe'
    CommandLine|endswith:
        - '.hta'
        - '.js'
        - '.jse'
        - '.ps1'
        - '.vbe'
        - '.vbs'
        - '.wsf'
        - '.wsh'

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
CommandLineends_with
  • .hta corpus 7 (sigma 7)
  • .js
  • .jse
  • .ps1 corpus 8 (sigma 8)
  • .vbe corpus 8 (sigma 8)
  • .vbs corpus 8 (sigma 8)
  • .wsf
  • .wsh
CommandLinematch
  • \AppData\local\temp\*.rar\
  • \AppData\local\temp\*.zip\
  • \AppData\local\temp\7z*\
  • \AppData\local\temp\rar*\
Imageends_with
  • \cscript.exe corpus 76 (sigma 76)
  • \mshta.exe corpus 69 (sigma 69)
  • \powershell.exe corpus 186 (sigma 186)
  • \pwsh.exe corpus 172 (sigma 172)
  • \wscript.exe corpus 78 (sigma 78)
ParentImageends_with
  • \7z*.exe
  • \explorer.exe corpus 14 (sigma 14)
  • \winrar.exe corpus 5 (sigma 5)