How the attack works
A Lambda function runs with an execution role chosen when the function is created (CreateFunction) or changed later (UpdateFunctionConfiguration). Choosing the role requires iam:PassRole on it. A principal that can pass a privileged role and create or update functions can therefore run code with that role's permissions, even if its own permissions are limited: one of the best-known AWS privilege escalation paths. A related path needs no PassRole at all: UpdateFunctionCode on a function that already has a privileged role replaces its code, and the next invocation runs that code with the role. Sysdig documented an intrusion in which this step led from exposed credentials to administrator access.
iam:PassRole is a permission, not an API call, so it never appears in CloudTrail by itself. The role shows up in the Lambda call that receives it: requestParameters.role on CreateFunction and on UpdateFunctionConfiguration when the role is changed. Lambda logs these events with versioned names (CreateFunction20150331, UpdateFunctionConfiguration20150331v2, UpdateFunctionCode20150331v2), so rules that match the plain API names miss them. A function does not have to be invoked by its creator either: CreateEventSourceMapping, logged as CreateEventSourceMapping20150331, makes Lambda run it for the records that arrive on a stream or a queue.
What an attacker needs
- Credentials for a principal allowed to call iam:PassRole on a privileged role that trusts lambda.amazonaws.com.
- lambda:CreateFunction, or lambda:UpdateFunctionConfiguration on an existing function, plus a way to run it (invoke permission, a trigger or a schedule).
- For the variant without PassRole, lambda:UpdateFunctionCode on a function that already runs with a privileged role.
Impact
Code execution with the passed role's permissions. If the role is an administrator or can modify IAM, the attacker escalates to full account control.
Detection rules
Lambda Event Source Mapping Created
Detects Lambda CreateEventSourceMapping calls (logged as CreateEventSourceMapping20150331). An event source mapping makes Lambda read from a stream or a queue and invoke a function with what it reads. A principal that created a function with a privileged execution role, but has no permission to invoke it, can attach the function to an event source it is able to write to, and the function then runs without an Invoke call by that principal. AWS lists the call among the Lambda management events, with the versioned event name. The rule matches every new mapping: check the function and the event source in the request parameters, and whether the same caller created or changed the function shortly before. It also matches attempts that failed (errorCode present): check errorCode, because an unauthorized attempt is worth seeing.
title: Lambda Event Source Mapping Created
id: 3ede36ef-d92a-462b-a47f-1bc0d130d2aa
status: experimental
description: >-
Detects Lambda CreateEventSourceMapping calls (logged as
CreateEventSourceMapping20150331). An event source mapping makes Lambda
read from a stream or a queue and invoke a function with what it reads. A
principal that created a function with a privileged execution role, but
has no permission to invoke it, can attach the function to an event source
it is able to write to, and the function then runs without an Invoke call
by that principal. AWS lists the call among the Lambda management events,
with the versioned event name. The rule matches every new mapping: check
the function and the event source in the request parameters, and whether
the same caller created or changed the function shortly before.
It also matches attempts that failed (errorCode present): check errorCode,
because an unauthorized attempt is worth seeing.
references:
- https://docs.aws.amazon.com/lambda/latest/dg/logging-using-cloudtrail.html
- https://docs.aws.amazon.com/lambda/latest/api/API_CreateEventSourceMapping.html
- https://attack.mitre.org/techniques/T1648/
author: Forestall
date: 2026-11-18
tags:
- attack.execution
- attack.t1648
logsource:
product: aws
service: cloudtrail
detection:
selection:
eventSource: lambda.amazonaws.com
eventName|startswith: CreateEventSourceMapping20150331
condition: selection
falsepositives:
- Deployments by CI/CD pipelines and infrastructure-as-code tools that connect functions to queues and streams. Add the deployment roles to a filter_* selection on userIdentity.arn and keep alerting on mappings created by people or unknown roles.
level: low
False positives
- Deployments by CI/CD pipelines and infrastructure-as-code tools that connect functions to queues and streams. Add the deployment roles to a filter_* selection on userIdentity.arn and keep alerting on mappings created by people or unknown roles.
Lambda Function Code Updated
Detects Lambda UpdateFunctionCode calls (logged as UpdateFunctionCode20150331v2). Replacing the code of a function that already runs with a privileged execution role runs the caller's code with that role and needs no iam:PassRole. Every deployment matches, so scope the rule to the functions whose execution role is privileged (requestParameters.functionName) or exclude the deployment roles. It also matches attempts that failed (errorCode present): check errorCode, because an unauthorized attempt is worth seeing.
title: Lambda Function Code Updated
id: e22c7268-a46e-41b8-be27-ea9b9a9cb7a3
status: experimental
description: >-
Detects Lambda UpdateFunctionCode calls (logged as
UpdateFunctionCode20150331v2). Replacing the code of a function that already
runs with a privileged execution role runs the caller's code with that role
and needs no iam:PassRole. Every deployment matches, so scope the rule to
the functions whose execution role is privileged
(requestParameters.functionName) or exclude the deployment roles.
It also matches attempts that failed (errorCode present): check errorCode,
because an unauthorized attempt is worth seeing.
references:
- https://docs.aws.amazon.com/lambda/latest/dg/logging-using-cloudtrail.html
- https://docs.aws.amazon.com/lambda/latest/api/API_UpdateFunctionCode.html
author: Forestall
date: 2026-11-11
tags:
- attack.execution
- attack.t1648
logsource:
product: aws
service: cloudtrail
detection:
selection:
eventSource: lambda.amazonaws.com
eventName|startswith: UpdateFunctionCode20150331
condition: selection
falsepositives:
- Every code deployment by CI/CD pipelines, infrastructure-as-code tools and developers. Useful only after it is limited to functions with privileged execution roles or to callers outside the deployment roles.
level: low
False positives
- Every code deployment by CI/CD pipelines, infrastructure-as-code tools and developers. Useful only after it is limited to functions with privileged execution roles or to callers outside the deployment roles.
Lambda Function Created with an Execution Role
Detects Lambda CreateFunction calls (logged as CreateFunction20150331). Every new function is given an execution role in requestParameters.role; triage by checking whether that role is more privileged than the caller. It also matches attempts that failed (errorCode present): check errorCode, because an unauthorized attempt is worth seeing.
title: Lambda Function Created with an Execution Role
id: 340fedbf-224c-4e27-b225-b3bc875587ef
status: experimental
description: >-
Detects Lambda CreateFunction calls (logged as CreateFunction20150331). Every
new function is given an execution role in requestParameters.role; triage by
checking whether that role is more privileged than the caller.
It also matches attempts that failed (errorCode present): check errorCode,
because an unauthorized attempt is worth seeing.
references:
- https://docs.aws.amazon.com/lambda/latest/dg/logging-using-cloudtrail.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html
author: Forestall
date: 2026-11-10
tags:
- attack.execution
- attack.t1648
logsource:
product: aws
service: cloudtrail
detection:
selection:
eventSource: lambda.amazonaws.com
eventName|startswith: CreateFunction20150331
condition: selection
falsepositives:
- Deployments by CI/CD pipelines and infrastructure-as-code tools; allow-list the deployment roles and keep alerting on functions created by people or unknown roles.
level: low
False positives
- Deployments by CI/CD pipelines and infrastructure-as-code tools; allow-list the deployment roles and keep alerting on functions created by people or unknown roles.
Lambda Function Execution Role Changed
Detects Lambda UpdateFunctionConfiguration calls (logged as UpdateFunctionConfiguration20150331v2) that send an execution role in requestParameters.role. The event does not carry the previous role, so confirm that the role changed. Swapping the role of an existing function is rarer than creating one and a direct PassRole escalation step. It also matches attempts that failed (errorCode present): check errorCode, because an unauthorized attempt is worth seeing.
title: Lambda Function Execution Role Changed
id: 7ab8dd1b-20b1-46c5-b6a2-09134076ef9f
status: experimental
description: >-
Detects Lambda UpdateFunctionConfiguration calls (logged as
UpdateFunctionConfiguration20150331v2) that send an execution role in
requestParameters.role. The event does not carry the previous role, so
confirm that the role changed. Swapping the role of an existing function is
rarer than creating one and a direct PassRole escalation step.
It also matches attempts that failed (errorCode present): check errorCode,
because an unauthorized attempt is worth seeing.
references:
- https://docs.aws.amazon.com/lambda/latest/dg/logging-using-cloudtrail.html
- https://docs.aws.amazon.com/lambda/latest/api/API_UpdateFunctionConfiguration.html
- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html
author: Forestall
date: 2026-11-10
tags:
- attack.execution
- attack.t1648
logsource:
product: aws
service: cloudtrail
detection:
selection:
eventSource: lambda.amazonaws.com
eventName|startswith: UpdateFunctionConfiguration20150331
requestParameters.role|exists: true
condition: selection
falsepositives:
- Role changes deployed by infrastructure-as-code pipelines, and configuration updates that send the unchanged role again; allow-list the deployment roles.
level: medium
False positives
- Role changes deployed by infrastructure-as-code pipelines, and configuration updates that send the unchanged role again; allow-list the deployment roles.
Detection logic
Patterns that need more than one event, a baseline or knowledge of your own environment. Each is a hypothesis to build and tune in your SIEM, not a ready rule.
Function given a role and wired to a trigger by the same principal
Creating a function with a role is deployment work, and so is adding a trigger. A principal outside the deployment roles that does both within minutes has built something that runs with the role without anyone invoking it, which is the escalation path completed.
- A
CreateFunction20150331event fromlambda.amazonaws.com, or anUpdateFunctionConfiguration20150331v2event that carriesrequestParameters.role. NoterequestParameters.functionNameand the caller inuserIdentity.arn. - Within 30 minutes the same caller makes a
CreateEventSourceMapping20150331or anAddPermission20150331v2call whose request names the same function. - Check what the role in
requestParameters.rolecan do and whether the caller is one of your deployment roles.
EventsCreateFunction20150331UpdateFunctionConfiguration20150331v2CreateEventSourceMapping20150331AddPermission20150331v2
LimitsEvery deployment pipeline produces this sequence, so it is useful only for callers outside the deployment roles. The 30 minutes are a starting point. A function that is run through a direct Invoke call leaves no management event, because Invoke is a data event.
Triage
- Check what the role in requestParameters.role can do, and whether the caller (userIdentity.arn) could already do the same without it.
- Check whether the caller is the usual deployment pipeline, and look for Invoke events or new triggers for the same function shortly after.
- For UpdateFunctionCode, look up the execution role of the function named in requestParameters.functionName; a code change on a function with an administrator role by anyone but the pipeline is the signal.
- If not approved, remove the function or restore its previous role and review CloudTrail for actions taken by the role's sessions.
Response
Once the attack is confirmed:
- Stop the function from running the attacker's code. Remove its triggers and schedules, then delete the function, or restore its previous code and execution role from the deployment pipeline.
- Revoke the active sessions of the execution role. Credentials that the function already obtained stay valid until they expire, even after the function is gone, unless the sessions are revoked.
- Review CloudTrail for what the sessions of the role did, and remove what they created, such as users, access keys, roles and policy changes.
- Contain the principal that created or changed the function, and take away its
iam:PassRoleon the privileged role. - Check the other functions that use the same role for code changes nobody deployed, and confirm that the role is no longer passed to new functions.
Mitigation
- Scope iam:PassRole to specific role ARNs and use the iam:PassedToService condition key; never allow it on Resource
"*". - Keep Lambda execution roles least-privilege, and do not let administrator roles trust lambda.amazonaws.com.
- Restrict lambda:CreateFunction, UpdateFunctionConfiguration and UpdateFunctionCode to deployment pipelines in production accounts.
Frequently asked questions
Why can I not alert on iam:PassRole directly?
`iam:PassRole` is a permission, not an API call, so it never appears in CloudTrail by itself. The role shows up in the Lambda call that receives it, in `requestParameters.role` of `CreateFunction` and of `UpdateFunctionConfiguration` when the role is changed. The rules therefore watch those Lambda events.
Why does a rule that matches the plain name CreateFunction find nothing?
Lambda logs these events with versioned names, such as `CreateFunction20150331`, `UpdateFunctionConfiguration20150331v2` and `UpdateFunctionCode20150331v2`. A rule that matches the plain API name misses them. The rules on this page match the start of the versioned name.
Will CloudTrail show the function being invoked afterwards?
Only if data events for Lambda are logged. `Invoke` is a data event. AWS documents that CloudTrail does not log most data events by default and that Event history does not record them. Without that setting, look for new triggers on the function and for the activity of the sessions of its execution role.
Is a code update on an existing function really a privilege escalation?
It is when the function already runs with a privileged execution role. `UpdateFunctionCode` replaces the code, the next invocation runs it with that role, and no `iam:PassRole` is needed. Every deployment produces the same event, so the rule is useful only when it is limited to functions with privileged roles or to callers outside the deployment roles.
References
- MITRE ATT&CK T1648: Serverless Execution
- Logging AWS Lambda API calls using AWS CloudTrail (versioned event names)
- Grant a user permissions to pass a role to an AWS service (PassRole in CloudTrail)
- How to use the PassRole permission with IAM roles
- Sysdig: AI-assisted cloud intrusion achieves admin access in 8 minutes
- Revoke IAM role temporary security credentials