Detection rules › Elastic
Python Library Load and Delete
Detects Python loading a library from a user's home directory followed by immediate deletion. This technique is used by malware to execute code while removing forensic evidence.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | |
| Stealth |
Telemetry coverage
| Platform | Record / event type |
|---|---|
| macOS | ESF event unlink (NOTIFY): Fires after a file's directory entry is removed. |
Rule body
[rule]
description = """
Detects Python loading a library from a user's home directory followed by immediate deletion. This technique is used by
malware to execute code while removing forensic evidence.
"""
id = "76a1f901-4495-4cbd-a35a-7ff8d116602b"
license = "Elastic License v2"
name = "Python Library Load and Delete"
os_list = ["macos"]
reference = [
"https://unit42.paloaltonetworks.com/slow-pisces-new-custom-malware/",
"https://slowmist.medium.com/cryptocurrency-apt-intelligence-unveiling-lazarus-groups-intrusion-techniques-a1a6efda7d34",
]
version = "1.0.7"
query = '''
sequence by process.entity_id with maxspan=10s
[library where event.action == "load" and dll.path like~ "/Users/*" and process.name like~ "python*" and
not dll.name : "*.so"] as event0
[file where event.action == "deletion" and startswith~(file.path, event0.dll.path)]
'''
min_endpoint_version = "8.16.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "Effective_process.entity_id"
state = 0
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 0
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1059"
name = "Command and Scripting Interpreter"
reference = "https://attack.mitre.org/techniques/T1059/"
[[threat.technique.subtechnique]]
id = "T1059.006"
name = "Python"
reference = "https://attack.mitre.org/techniques/T1059/006/"
[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[[threat]]
framework = "MITRE ATT&CK"
[[threat.technique]]
id = "T1070"
name = "Indicator Removal"
reference = "https://attack.mitre.org/techniques/T1070/"
[[threat.technique.subtechnique]]
id = "T1070.004"
name = "File Deletion"
reference = "https://attack.mitre.org/techniques/T1070/004/"
[threat.tactic]
id = "TA0005"
name = "Defense Evasion"
reference = "https://attack.mitre.org/tactics/TA0005/"
[internal]
min_endpoint_version = "8.16.0"
Stages and Predicates
Ordered sequence: each step below must occur in order within 10s, correlated by process.entity_id.
Stage 1: library
[library where event.action == "load" and dll.path like~ "/Users/*" and process.name like~ "python*" and
not dll.name : "*.so"] as event0
Stage 2: file
[file where event.action == "deletion" and startswith~(file.path, event0.dll.path)]
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
dll.name | ends_with | .so | excludes:dll.name field:"dll.name" value:".so" |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
dll.path | wildcard |
| field:"ImageLoaded" kind:wildcard value:"/Users/*" |
event.action | eq |
| field:"EventType" kind:eq |
file.path | starts_with |
| field:"TargetFilename" kind:starts_with value:"event0.dll.path" |
process.name | wildcard |
| field:"process_name" kind:wildcard value:"python*" |