Detection rules › Splunk
Package installation (PowerShell)
Some programming languages, like Python, come with an easy, more or less official method of installing dependencies for your projects. These installers are usually tied to public code repositories where anyone can freely upload code packages for others to use. The intent of this use case is to identify installation of packages, with common repositories using pip, gem and npm. Use case will be used to with additional threat identifiers to potentially identify Dependency confusion style attacks.
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Command & Control | T1105 Ingress Tool Transfer |
References
Event coverage
| Provider | Event | Title |
|---|---|---|
| PowerShell | Event ID 4104 | Creating Scriptblock text (MessageNumber of MessageTotal). |
Rule body yaml
id: '5987.6350'
title: Package installation
description: 'Some programming languages, like Python, come with an easy, more or
less official method of installing dependencies for your projects. These installers
are usually tied to public code repositories where anyone can freely upload code
packages for others to use. The intent of this use case is to identify installation
of packages, with common repositories using pip, gem and npm. Use case will be used
to with additional threat identifiers to potentially identify Dependency confusion
style attacks. '
logic_format: Splunk
logic: '`get_endpoint_data` `get_endpoint_data_powershell` TERM(EventCode=4104) (TERM(npm)
OR TERM(pip) OR TERM(gem)) TERM(install) | regex process="(?i)install\s" | rex field=process
"(?<reqs>(?i)requirements\.txt") | rex field=process "(?<extra>(?i)(\-{2}extra)?\-index\-url(\s+\S+)")
| rex field=process "(?<source1>(?i)\-{2}source(\s+\S+)") | eval keywords=mvappend(reqs,
extra, source1) | table _time, host, user, signature_id, process, process_*, keywords
| bin span=1s | stats values(*) as * by _time, host '
techniques:
- command-and-control:ingress tool transfer
technique_id:
- T1105
data_category:
- PowerShell logs
references:
- https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610
Stages and Predicates
Stage 1: search
`get_endpoint_data` `get_endpoint_data_powershell` TERM(EventCode=4104) (TERM(npm) OR TERM(pip) OR TERM(gem)) TERM(install)
Stage 2: regex
| regex process="(?i)install\s"
Stage 3: eval
| rex field=process "(?<reqs>(?i)requirements\.txt")
Stage 4: eval
| rex field=process "(?<extra>(?i)(\-{2}extra)?\-index\-url(\s+\S+)")
Stage 5: eval
| rex field=process "(?<source1>(?i)\-{2}source(\s+\S+)")
Stage 6: eval
| eval keywords=mvappend(reqs, extra, source1)
Stage 7: table
| table _time, host, user, signature_id, process, process_*, keywords
Stage 8: bucket
| bin span=1s
Stage 9: stats
| stats values(*) as * by _time, host
Indicators
Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.
Search terms
Bare-string tokens in the SPL search body. Splunk matches each token against _raw (the untyped raw event text) anywhere it appears, not against a specific field. These don't surface in the Indicators table because they aren't predicates on a known field.
| Stage | Term |
|---|---|
| 1 | TERM |
| 1 | TERM |
| 1 | npm |
| 1 | TERM |
| 1 | pip |
| 1 | TERM |
| 1 | gem |
| 1 | TERM |
| 1 | install |