H05 Log Secret Ai Service Chain
Query
// REVIEW ONLY. ARTEX-inspired behavior, not an ARTEX signature or proof of AI authorship.
// Log searches are the primary signal. Optional model follow-up needs Bedrock DATA events.
// Missing follow-up is explicitly UNKNOWN evidence, not a clean result.
let Start = ago(4h);
let End = now();
let SeedAWSAccountId = "REPLACE_WITH_12_DIGIT_ACCOUNT";
let InputsValid = assert(SeedAWSAccountId matches regex @"^[0-9]{12}$", "Set the AWS identity account.");
let Events = materialize(AWSCloudTrail
| where InputsValid and TimeGenerated between (Start .. End)
| where UserIdentityAccountId == SeedAWSAccountId
| where isnotempty(UserIdentityAccessKeyId) and isnotempty(UserIdentityArn) and isnotempty(AwsEventId)
| where isempty(ErrorCode) and isempty(ErrorMessage)
| project EventTime=TimeGenerated, AwsEventId, EventSource, EventName, RequestParameters,
AWSAccountId=UserIdentityAccountId, AwsAccessKeyId=UserIdentityAccessKeyId,
AwsPrincipalArn=UserIdentityArn, SourceIpAddress);
let Searches = Events
| where EventSource == "logs.amazonaws.com" and EventName == "FilterLogEvents"
| where tostring(parse_json(RequestParameters).filterPattern) matches regex @"(?i)(password|secret|AKIA|presigned|s3://|invoice|billing|fund)"
| project AWSAccountId, AwsAccessKeyId, AwsPrincipalArn, SearchTime=EventTime, SearchEventId=AwsEventId,
SearchSourceIp=SourceIpAddress, RequestedLimit=toint(parse_json(RequestParameters).limit);
let SecretReads = Events
| where EventSource == "secretsmanager.amazonaws.com" and EventName == "GetSecretValue"
| project AWSAccountId, AwsAccessKeyId, AwsPrincipalArn, SecretTime=EventTime, SecretEventId=AwsEventId;
let ModelUse = Events
| where EventSource in ("bedrock.amazonaws.com", "bedrock-runtime.amazonaws.com")
| where EventName in ("InvokeModel", "InvokeModelWithResponseStream", "Converse", "ConverseStream")
| project AWSAccountId, AwsAccessKeyId, AwsPrincipalArn, ModelTime=EventTime,
ModelEventId=AwsEventId, ModelOperation=EventName, ModelSourceIp=SourceIpAddress;
let SecretFollowup = Searches
| join kind=inner SecretReads on AWSAccountId, AwsAccessKeyId, AwsPrincipalArn
| where SecretTime between (SearchTime .. (SearchTime + 10m))
| summarize SecretEvents=make_set(SecretEventId, 20) by SearchEventId;
let OrderedAiChains = Searches
| join kind=inner SecretReads on AWSAccountId, AwsAccessKeyId, AwsPrincipalArn
| where SecretTime between (SearchTime .. (SearchTime + 10m))
| join kind=inner ModelUse on AWSAccountId, AwsAccessKeyId, AwsPrincipalArn
| where ModelTime between (SecretTime .. (SecretTime + 10m))
| summarize LastModelUse=max(ModelTime), ModelEvents=make_set(ModelEventId, 20),
ModelOperations=make_set(ModelOperation, 10), ModelSources=make_set(ModelSourceIp, 20)
by SearchEventId;
Searches
| join kind=leftouter SecretFollowup on SearchEventId
| join kind=leftouter OrderedAiChains on SearchEventId
| extend EvidenceState=case(isnotnull(LastModelUse), "Ordered log-to-secret-to-model requests observed",
array_length(SecretEvents) > 0, "Secret follow-up observed; model follow-up NOT OBSERVED / coverage unknown",
"Log search observed; follow-up NOT OBSERVED / coverage and outcome unknown"),
CorrelationBasis="Exact key/session for follow-ups; keywords, limit=1000 and speed are not attribution",
NextStep="H01 for Entra identity; H06 for issued keys; validate business purpose and data-event selectors"
| project SearchTime, SearchEventId, AWSAccountId, AwsAccessKeyId, AwsPrincipalArn, SearchSourceIp,
RequestedLimit, SecretEvents, LastModelUse, ModelEvents, ModelOperations, ModelSources,
EvidenceState, CorrelationBasis, NextStep
| order by SearchTime desc
| take 1000Explanation
This query is designed to analyze AWS CloudTrail logs to identify specific patterns of behavior related to log searches, secret access, and model usage within a specified AWS account over the last four hours. Here's a simplified breakdown:
-
Setup:
- The query defines a time range from four hours ago to the current time.
- It requires a valid 12-digit AWS account ID to be set.
-
Data Collection:
- It collects events from AWS CloudTrail logs where the specified AWS account is involved, ensuring that certain fields are not empty and there are no errors.
-
Log Searches:
- It filters for events where logs are being searched, specifically looking for sensitive keywords like "password", "secret", or "billing" in the search patterns.
-
Secret Access:
- It identifies events where secrets are accessed using AWS Secrets Manager.
-
Model Usage:
- It tracks events related to the use of AI models on AWS Bedrock.
-
Correlation:
- It checks if secret access events follow log searches within a 10-minute window.
- It further checks if model usage follows secret access within another 10-minute window.
-
Results:
- The query summarizes the findings, indicating whether a sequence of log search, secret access, and model usage was observed.
- It classifies the evidence state based on the observed patterns and provides guidance on the next steps for investigation.
-
Output:
- The results are ordered by the time of the log search and limited to the most recent 1000 entries.
In essence, the query is designed to detect and analyze potentially suspicious sequences of actions involving log searches, secret access, and AI model usage, providing insights into the behavior and suggesting further investigative actions.