EXPLORE
← Back to Explore
sigmahighHunting

Inline Python Execution - Spawn Shell Via OS System Library

Detects execution of inline Python code via the "-c" in order to call the "system" function from the "os" library, and spawn a shell.

MITRE ATT&CK

execution

Detection Query

selection_img:
  - Image|endswith:
      - /python
      - /python2
      - /python3
  - Image|contains:
      - /python2.
      - /python3.
selection_cli:
  CommandLine|contains|all:
    - " -c "
    - os.system(
  CommandLine|contains:
    - /bin/bash
    - /bin/dash
    - /bin/fish
    - /bin/sh
    - /bin/zsh
condition: all of selection_*

Author

Li Ling, Andy Parkidomo, Robert Rakowski, Blake Hartstein (Bloomberg L.P.)

Created

2024-09-02

Data Sources

linuxProcess Creation Events

Platforms

linux

Tags

attack.executionattack.t1059
Raw Content
title: Inline Python Execution - Spawn Shell Via OS System Library
id: 2d2f44ff-4611-4778-a8fc-323a0e9850cc
status: test
description: |
    Detects execution of inline Python code via the "-c" in order to call the "system" function from the "os" library, and spawn a shell.
references:
    - https://gtfobins.github.io/gtfobins/python/#shell
author: Li Ling, Andy Parkidomo, Robert Rakowski, Blake Hartstein (Bloomberg L.P.)
date: 2024-09-02
tags:
    - attack.execution
    - attack.t1059
logsource:
    category: process_creation
    product: linux
detection:
    selection_img:
        - Image|endswith:
              - '/python'
              - '/python2'
              - '/python3'
        - Image|contains:
              - '/python2.'  # python image is always of the form ../python3.10; ../python is just a symlink
              - '/python3.'
    selection_cli:
        CommandLine|contains|all:
            - ' -c '
            - 'os.system('
        CommandLine|contains:
            - '/bin/bash'
            - '/bin/dash'
            - '/bin/fish'
            - '/bin/sh'
            - '/bin/zsh'
    condition: all of selection_*
falsepositives:
    - Unknown
level: high