Detection rules › Elastic
Perl Script File Creation or Modification
Detects when a .pl file gets created or modified by a non-perl binary. Perl is a scripting language that comes pre-installed on macOS and is a trusted binary offering an extensive set of capabilities and advantages to an adversary. Its use on a macOS system is not common and therefore specific behaviors exhibited can be classified as malicious or suspicious at least.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution |
Telemetry coverage
| Platform | Record / event type |
|---|---|
| macOS | ESF event write (NOTIFY): Fires after a process writes data to a file. |
Rule body
[rule]
description = """
Detects when a .pl file gets created or modified by a non-perl binary. Perl is a scripting language that comes
pre-installed on macOS and is a trusted binary offering an extensive set of capabilities and advantages to an adversary.
Its use on a macOS system is not common and therefore specific behaviors exhibited can be classified as malicious or
suspicious at least.
"""
id = "f2fa4350-6700-46d1-b79c-fedd385f6984"
license = "Elastic License v2"
name = "Perl Script File Creation or Modification"
os_list = ["macos"]
version = "1.0.8"
query = '''
sequence by process.entity_id with maxspan=15s
[network where event.type == "start"]
[file where event.action == "modification" and file.extension == "pl" and
(process.code_signature.trusted == false or process.code_signature.exists == false) and
file.path like ("/Users/Shared/*", "/tmp/*", "/private/tmp/*", "/var/tmp/*", "/private/var/tmp/*") and
not Effective_process.executable like "/nix/store/*-nix-*/bin/nix"]
'''
min_endpoint_version = "8.16.0"
optional_actions = []
[[actions]]
action = "kill_process"
field = "Effective_process.entity_id"
state = 1
[[actions]]
action = "kill_process"
field = "process.entity_id"
state = 1
[[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.004"
name = "Unix Shell"
reference = "https://attack.mitre.org/techniques/T1059/004/"
[threat.tactic]
id = "TA0002"
name = "Execution"
reference = "https://attack.mitre.org/tactics/TA0002/"
[internal]
min_endpoint_version = "8.16.0"
Stages and Predicates
Ordered sequence: each step below must occur in order within 15s, correlated by process.entity_id.
Stage 1: network
[network where event.type == "start"]
Stage 2: file
[file where event.action == "modification" and file.extension == "pl" and
(process.code_signature.trusted == false or process.code_signature.exists == false) and
file.path like ("/Users/Shared/*", "/tmp/*", "/private/tmp/*", "/var/tmp/*", "/private/var/tmp/*") and
not Effective_process.executable like "/nix/store/*-nix-*/bin/nix"]
Exclusions
The rule actively suppresses these predicates.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
Effective_process.executable | wildcard | /nix/store/*-nix-*/bin/nix | excludes:Effective_process.executable field:"Effective_process.executable" value:"/nix/store/*-nix-*/bin/nix" |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
event.action | eq |
| field:"EventType" kind:eq value:"modification" |
event.type | eq |
| field:"event.type" kind:eq value:"start" |
file.extension | eq |
| field:"file.extension" kind:eq value:"pl" |
file.path | wildcard |
| field:"TargetFilename" kind:wildcard |
process.code_signature.exists | eq |
| field:"process.code_signature.exists" kind:eq value:"false" |
process.code_signature.trusted | eq |
| field:"process.code_signature.trusted" kind:eq value:"false" |