Detection rules › Kusto
AWSCloudTrail - EC2 Startup Shell Script Changed
Identifies changes to the EC2 startup script. The shell script will be executed as root/SYSTEM every time the specific instances are booted up. ref : https://github.com/RhinoSecurityLabs/pacu/blob/master/pacu/modules/ec2__startup_shell_script/main.py
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Execution | T1059 Command and Scripting Interpreter |
Rules detecting the same action
Other rules on this platform that filter on the same API call or operation.
Rule body kusto
id: f8577e4d-8481-437b-a94e-06f615985668
name: AWSCloudTrail - EC2 Startup Shell Script Changed
description: |
Identifies changes to the EC2 startup script. The shell script will be executed as root/SYSTEM every time the specific instances are booted up. ref : https://github.com/RhinoSecurityLabs/pacu/blob/master/pacu/modules/ec2__startup_shell_script/main.py
severity: Medium
status: Available
requiredDataConnectors:
- connectorId: AWS
dataTypes:
- AWSCloudTrail
queryFrequency: 15m
queryPeriod: 15m
triggerOperator: gt
triggerThreshold: 0
tactics:
- Execution
relevantTechniques:
- T1059
query: |
AWSCloudTrail
| where EventName in~ ("ModifyInstanceAttribute", "CreateLaunchTemplate")
| extend RequestParametersJson = parse_json(RequestParameters)
| where tostring(RequestParametersJson.userData) != ""
| extend userData_ = tostring(RequestParametersJson.userData)
| extend instanceId_ = tostring(RequestParametersJson.instanceId)
| project-away SourceSystem, Category, Type, TenantId, EventVersion, SessionIssuerAccountId
| extend UserName = substring(UserIdentityPrincipalid, indexof_regex(UserIdentityPrincipalid, ":") + 1)
| extend Name = split(UserName,'@')[0],UpnSuffix = split(UserName,'@')[1]
| project TimeGenerated, EventName, UserName, Name, UpnSuffix, instanceId_, AWSRegion, SourceIpAddress, EventSource, UserIdentityArn, EventTypeName
entityMappings:
- entityType: Account
fieldMappings:
- identifier: Name
columnName: Name
- identifier: UPNSuffix
columnName: UpnSuffix
- entityType: IP
fieldMappings:
- identifier: Address
columnName: SourceIpAddress
customDetails:
InstanceId: instanceId_
AWSRegion: AWSRegion
EventName: EventName
EventSource: EventSource
EventType: EventTypeName
alertDetailsOverride:
alertDisplayNameFormat: 'EC2 startup script changed on {{instanceId_}} by {{UserName}}'
alertDescriptionFormat: 'EC2 startup script changed on {{instanceId_}} by {{UserName}} in {{AWSRegion}}.'
version: 1.0.1
kind: Scheduled
Stages and Predicates
Stage 1: source
AWSCloudTrail
Stage 2: where
| where EventName in~ ("ModifyInstanceAttribute", "CreateLaunchTemplate")
Stage 3: extend
| extend RequestParametersJson = parse_json(RequestParameters)
Stage 4: where
| where tostring(RequestParametersJson.userData) != ""
Stage 5: extend
| extend userData_ = tostring(RequestParametersJson.userData)
Stage 6: extend
| extend instanceId_ = tostring(RequestParametersJson.instanceId)
Stage 7: project-away
| project-away SourceSystem, Category, Type, TenantId, EventVersion, SessionIssuerAccountId
Stage 8: extend
| extend UserName = substring(UserIdentityPrincipalid, indexof_regex(UserIdentityPrincipalid, ":") + 1)
Stage 9: extend
| extend Name = split(UserName,'@')[0],UpnSuffix = split(UserName,'@')[1]
Stage 10: project
| project TimeGenerated, EventName, UserName, Name, UpnSuffix, instanceId_, AWSRegion, SourceIpAddress, EventSource, UserIdentityArn, EventTypeName
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.
| Field | Kind | Values |
|---|---|---|
EventName | in |
|
Output fields
Fields the rule emits when it matches. Chronicle authors list these in the outcome block; they appear on the detection and $risk_score drives alerting. Sentinel / Defender XDR rules build them up through project / summarize / extend stages. Sentinel maps these into alert fields via entityMappings and customDetails; Defender XDR custom detections surface them as alert fields directly.
| Field | Source |
|---|---|
AWSRegion | project |
EventName | project |
EventSource | project |
EventTypeName | project |
Name | project |
SourceIpAddress | project |
TimeGenerated | project |
UpnSuffix | project |
UserIdentityArn | project |
UserName | project |
instanceId_ | project |