Execution

T1059.006: Python

Adversaries may abuse Python commands and scripts for execution. Python is a very popular scripting/programming language, with capabilities to perform many functions. Python can be executed interactiv...

T1059.006 · Sub-technique ·4 platforms ·19 groups

Description

Adversaries may abuse Python commands and scripts for execution. Python is a very popular scripting/programming language, with capabilities to perform many functions. Python can be executed interactively from the command-line (via the python.exe interpreter) or via scripts (.py) that can be written and distributed to different systems. Python code can also be compiled into binary executables.(Citation: Zscaler APT31 Covid-19 October 2020)

Python comes with many built-in packages to interact with the underlying system, such as file operations and device I/O. Adversaries can use these libraries to download and execute commands or other scripts as well as perform various malicious behaviors.

☞

Reverse Shell Cheatsheet

Read our in-depth pentesting guide related to this technique

Platforms

ESXiLinuxmacOSWindows

Mitigations (4)

Limit Software InstallationM1033

Prevent users from installing Python where not required.

Execution PreventionM1038

Denylist Python where not required.

Antivirus/AntimalwareM1049

Anti-virus can be used to automatically quarantine suspicious files.

AuditM1047

Inventory systems for unauthorized Python installations.

Threat Groups (19)

IDGroupContext
G0094Kimsuky[Kimsuky](https://attack.mitre.org/groups/G0094) has used a macOS Python implant to gather data as well as MailFetcher.py code to automatically collec...
G0035Dragonfly[Dragonfly](https://attack.mitre.org/groups/G0035) has used various types of scripting to perform operations, including Python scripts. The group was ...
G0069MuddyWater[MuddyWater](https://attack.mitre.org/groups/G0069) has developed tools in Python including [Out1](https://attack.mitre.org/software/S0594).(Citation:...
G0095Machete[Machete](https://attack.mitre.org/groups/G0095) used multiple compiled Python scripts on the victim’s system. [Machete](https://attack.mitre.org/grou...
G0128ZIRCONIUM[ZIRCONIUM](https://attack.mitre.org/groups/G0128) has used Python-based implants to interact with compromised hosts.(Citation: Google Election Threat...
G0106Rocke[Rocke](https://attack.mitre.org/groups/G0106) has used Python-based malware to install and spread their coinminer.(Citation: Anomali Rocke March 2019...
G0087APT39[APT39](https://attack.mitre.org/groups/G0087) has used a command line utility and a network scanner written in python.(Citation: BitDefender Chafer M...
G1048UNC3886[UNC3886](https://attack.mitre.org/groups/G1048) has used Python scripts to enumerate ESXi hosts and guest VMs.(Citation: Google Cloud Threat Intellig...
G1052Contagious Interview[Contagious Interview](https://attack.mitre.org/groups/G1052) has used the Python-based malware such as [InvisibleFerret](https://attack.mitre.org/sof...
G0067APT37[APT37](https://attack.mitre.org/groups/G0067) has used Python scripts to execute payloads.(Citation: Volexity InkySquid RokRAT August 2021)
G0010Turla[Turla](https://attack.mitre.org/groups/G0010) has used IronPython scripts as part of the [IronNetInjector](https://attack.mitre.org/software/S0581) t...
G1039RedCurl[RedCurl](https://attack.mitre.org/groups/G1039) has used a Python script to establish outbound communication and to execute commands using SMB port 4...
G0016APT29[APT29](https://attack.mitre.org/groups/G0016) has developed malware variants written in Python.(Citation: Symantec Seaduke 2015)
G1021Cinnamon Tempest[Cinnamon Tempest](https://attack.mitre.org/groups/G1021) has used a customized version of the [Impacket](https://attack.mitre.org/software/S0357) wmi...
G0060BRONZE BUTLER[BRONZE BUTLER](https://attack.mitre.org/groups/G0060) has made use of Python-based remote access tools.(Citation: Trend Micro Tick November 2019)
G0131Tonto Team[Tonto Team](https://attack.mitre.org/groups/G0131) has used Python-based tools for execution.(Citation: TrendMicro Tonto Team October 2020)
G1006Earth Lusca[Earth Lusca](https://attack.mitre.org/groups/G1006) used Python scripts for port scanning or building reverse shells.(Citation: TrendMicro EarthLusca...
G1055VOID MANTICORE[VOID MANTICORE](https://attack.mitre.org/groups/G1055) has utilized Python scripts to execute its malicious payloads.(Citation: FBI IC3 Flash VOID MA...
G1056TeamPCP[TeamPCP](https://attack.mitre.org/groups/G1056) has poisoned PyPi packages with malicious code and has used a 13 file modular Python framework for da...

Associated Software (40)

IDNameTypeContext
S1187reGeorgMalware[reGeorg](https://attack.mitre.org/software/S1187) is a Python-based web shell.(Citation: GitHub reGeorg 2016)
S1245InvisibleFerretMalware[InvisibleFerret](https://attack.mitre.org/software/S1245) is written in Python and has used Python scripts for execution.(Citation: Esentire Contagio...
S1164UPSTYLEMalware[UPSTYLE](https://attack.mitre.org/software/S1164) is a Python-based application.(Citation: Volexity UPSTYLE 2024)(Citation: Palo Alto MidnightEclipse...
S1032PyDCryptMalware[PyDCrypt](https://attack.mitre.org/software/S1032), along with its functions, is written in Python.(Citation: Checkpoint MosesStaff Nov 2021)
S0647TurianMalware[Turian](https://attack.mitre.org/software/S0647) has the ability to use Python to spawn a Unix shell.(Citation: ESET BackdoorDiplomacy Jun 2021)
S1223THINCRUSTMalware[THINCRUST](https://attack.mitre.org/software/S1223) can use Python scripts for command execution.(Citation: Mandiant Fortinet Zero Day)
S0409MacheteMalware[Machete](https://attack.mitre.org/software/S0409) is written in Python and is used in conjunction with additional Python scripts.(Citation: ESET Mach...
S0547DropBookMalware[DropBook](https://attack.mitre.org/software/S0547) is a Python-based backdoor compiled with PyInstaller.(Citation: Cybereason Molerats Dec 2020)
S0276KeydnapMalware[Keydnap](https://attack.mitre.org/software/S0276) uses Python for scripting to execute additional commands.(Citation: synack 2016 review)
S0196PUNCHBUGGYMalware[PUNCHBUGGY](https://attack.mitre.org/software/S0196) has used python scripts.(Citation: Morphisec ShellTea June 2019)
S0387KeyBoyMalware[KeyBoy](https://attack.mitre.org/software/S0387) uses Python scripts for installing files and performing execution.(Citation: CitizenLab KeyBoy Nov 2...
S1213Lumma StealerMalware[Lumma Stealer](https://attack.mitre.org/software/S1213) has used malicious Python scripts to execute payloads.(Citation: Cybereason LumaStealer Undat...
S0631ChaesMalware[Chaes](https://attack.mitre.org/software/S0631) has used Python scripts for execution and the installation of additional files.(Citation: Cybereason ...
S0482BundloreMalware[Bundlore](https://attack.mitre.org/software/S0482) has used Python scripts to execute payloads.(Citation: MacKeeper Bundlore Apr 2019)
S1218VIRTUALPIEMalware[VIRTUALPIE](https://attack.mitre.org/software/S1218) is a Python-based backdoor malware.(Citation: Google Cloud Threat Intelligence ESXi VIBs 2022)(C...
S0234BandookMalware[Bandook](https://attack.mitre.org/software/S0234) can support commands to execute Python-based payloads.(Citation: CheckPoint Bandook Nov 2020)
S0583PysaMalware[Pysa](https://attack.mitre.org/software/S0583) has used Python scripts to deploy ransomware.(Citation: CERT-FR PYSA April 2020)
S0374SpeakUpMalware[SpeakUp](https://attack.mitre.org/software/S0374) uses Python scripts.(Citation: CheckPoint SpeakUp Feb 2019)
S0154Cobalt StrikeMalware[Cobalt Strike](https://attack.mitre.org/software/S0154) can use Python to perform execution.(Citation: Cobalt Strike TTPs Dec 2017)(Citation: CobaltS...
S1189Neo-reGeorgMalware[Neo-reGeorg](https://attack.mitre.org/software/S1189) is a Python-based web shell.(Citation: GitHub Neo-reGeorg 2019)

Related CWE Weaknesses

References

Frequently Asked Questions

What is T1059.006 (Python)?

T1059.006 is a MITRE ATT&CK technique named 'Python'. It belongs to the Execution tactic(s). Adversaries may abuse Python commands and scripts for execution. Python is a very popular scripting/programming language, with capabilities to perform many functions. Python can be executed interactiv...

How can T1059.006 be detected?

Detection of T1059.006 (Python) typically involves monitoring system logs, network traffic, and endpoint telemetry. Use SIEM rules, EDR solutions, and behavioral analytics to identify suspicious activity associated with this technique.

What mitigations exist for T1059.006?

There are 4 documented mitigations for T1059.006. Key mitigations include: Limit Software Installation, Execution Prevention, Antivirus/Antimalware, Audit.

Which threat groups use T1059.006?

Known threat groups using T1059.006 include: Kimsuky, Dragonfly, MuddyWater, Machete, ZIRCONIUM, Rocke, APT39, UNC3886.