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 |
Telemetry coverage
Rules detecting the same action
These rules filter on the same operation.
Rule body
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
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
EventName | in |
| field:"aws::eventName" kind:in |
Output fields
These fields are emitted when the rule matches.
| Field | Source |
|---|---|
AWSRegion | project |
EventName | project |
EventSource | project |
EventTypeName | project |
Name | project |
SourceIpAddress | project |
TimeGenerated | project |
UpnSuffix | project |
UserIdentityArn | project |
UserName | project |
instanceId_ | project |