CmdID

CmdID / Rules / Windows

Python Inline Command Execution

A Sigma rule for process creation on Windows, by Nasreddine Bencherchali (Nextron Systems).

medium 1 ATT&CK technique 3 programs it names

What it looks for

its detection, as SigmaHQ writes it
detection:
  filter_main_python_1:
    ParentCommandLine|contains: '-E -s -m ensurepip -U --default-pip'
    ParentImage|endswith: '\python.exe'
    ParentImage|startswith:
      - 'C:\Program Files\Python'
      - 'C:\Program Files (x86)\Python'
  filter_main_python_trace:
    CommandLine|contains|all:
      - '-W ignore::DeprecationWarning'
      - '[''install'', ''--no-cache-dir'', ''--no-index'', ''--find-links'','
      - '''--upgrade'', ''pip'''
    ParentImage|startswith:
      - 'C:\Program Files\Python'
      - 'C:\Program Files (x86)\Python'
  filter_optional_pip:
    CommandLine|contains|all:
      - '<pip-setuptools-caller>'
      - 'exec(compile('
  filter_optional_vscode:
    - ParentImage|endswith: '\AppData\Local\Programs\Microsoft VS Code\Code.exe'
    - ParentImage:
        - 'C:\Program Files\Microsoft VS Code\Code.exe'
        - 'C:\Program Files (x86)\Microsoft VS Code\Code.exe'
  selection_cli:
    CommandLine|contains: ' -c'
  selection_img:
    - OriginalFileName: 'python.exe'
    - Image|endswith:
        - 'python.exe'
        - 'python3.exe'
        - 'python2.exe'
  condition: all of selection_* and not 1 of filter_main_* and not 1 of filter_optional_*

The rule’s detection, its selections and fields in order of name. The whole rule, with its references and false positives, is on SigmaHQ, by Nasreddine Bencherchali (Nextron Systems), under the Detection Rule License 1.1. CmdID evaluates it on a command line alone: a test on what a command line cannot show, such as the parent process or the user, is not met.

None of the everyday examples and documented commands on CmdID’s program pages trips it. To see whether a command line does, paste it into CmdID.

Programs and files it names

their pages here

ATT&CK

the techniques it is tagged with
T1059Command and Scripting Interpreter