Amazon Web Services provides its users with the ability to create temporary credentials via the use of AWS Security Token Service (AWS STS). These temporary credentials work pretty much in the same manner like permanent credentials created from AWS IAM Service. There are however two differences:
Users signed with federation, cross account role, or service account role can work with IAM Service and request or create temporary credentials.
AWS Security Token Service is a global service with a single endpoint sts.amazon.com. This single endpoint however can respond to all regions and be adjusted per specific region conditions or requirements.
It is also important to understand that at times the abuse of temporary tokens may lead to the creation of permanent keys as well. Let’s start by looking at several scenarios involving permanent keys and temporary credentials.
A permanent key is used to make programmatic calls to AWS or to use the AWS Command Line Interface or AWS Tools for Powershell. * This key can be created through the GUI web IAM management interface. This key is also issued with a secret access key which allows users to make API calls. Once the permanent key, usually starting with the letters “AKIA” is issued, users can download them. These keys can last pretty much as long as needed and they are prime targets for attackers, as they usually can potentially open the doors and provide full access to the organization's account.
An AWS IAM user is limited to two permanent keys. It is not usual for an user to create or change permanent keys unless indicated by policy, attackers can potentially create an additional key to establish persistence or even escalation of privileges by using created key and subsequently target other roles. So the creation of a permanent key is in itself an event that must be monitored.
Unfortunately temporary credentials can be abused as researched by Jenko Hwong from Netskope. There are some scenarios where these credentials can be abused and provide attackers with further privileges and access in AWS environments. These scenarios can also be difficult to spot. Here are 2 scenarios where these temporary credentials via AWS STS can be abused. They all have one prerequisite which is that an attacker must get a permanent key or be able to obtain access and abuse on a temporary session via exploitation or by other means such as phishing or for example API keys leaked on the internet.
AWS Security Token Service (AWS STS) is a service for providing trusted users with temporary security credentials that can control access to your AWS resources.* These credentials work almost exactly like long-term credentials. However they are different based on two aspects. A.) Temporary security credentials are short termed (15m to 36h). B.) These temporary security credentials are generated dynamically and provided by request. Attackers can take advantage of this service by assuming roles or creating temporary tokens which can allow them to move laterally or escalate privileges.
The sts:GetSessionToken string is part of the temporary token service and it provides temporary credential information for an specific AWS account or IAM user. GetSessionToken is used to protect programmatic calls to specific AWS API operations. MFA enabled IAM users would execute GetSessionToken calls and submit a MFA code. These calls may vary if users are logging in from identity single sign on providers like Okta. Duration of GetSessionToken obtained credentials are also short term (15 minutes, up to 36 hours). According to AWS, temporary security credentials created by GetSessionToken can be used to make API calls to any AWS service with two exceptions.
These constraints however may not really prevent attackers that are able to obtain these temporary tokens as there is an extensive number of services that respond to AssumeRole API programmatic calls. Also the creation of these tokens cannot be prevented.
Here is a scenario based on abuse of Permanent Keys & AWS STS tokens (Reference - Netskope Securing AWS Temporary Tokens)
Based on the above scenarios we can come up with some initial detections for 3 scenarios related to AWS permanent and AWS STS temporary token abuse.
As explained above the creation of permanent keys in AWS. They should not be created by default and only created for programmatic access via API. AWS Permanent API access keys which usually start with AKIA* should be monitored. We can take advantage of Cloudtrail logs via AWS add-on and AWS App for AWS and create detections for the above scenarios. The next graph shows detection of creation of permanent key in an AWS IAM organization’s framework.
This first search will detect users creating permanent keys and will provide the type of event, source IP address and action.
The second search provides a more detailed picture of who is creating the keys, where this action is coming from and what possible tools are being- used while accessing AWS API.
Notice that we are excluding userIdentity.type!=AssumedRole which relates to temporary credentials so we can find specifically what user from IAM is creating permanent keys. Also notice we are getting a user agent which gives clues about operating system type and software frameworks. We also get when the keys were created, the actual key and the status of such keys.
Attackers can create temporary tokens by abusing trust relationships which are represented in the form of Roles within AWS IAM service. As a feature of AWS IAM, AWS STS service provides the AssumeRole in which allows users to temporarily access resources they may not have access to. Depending on policy context, an attacker can abuse this by using role inherited privileges from a compromised account or they can add themselves to a targeted role trust policy. By doing so the attacker is able to expand access and possibly privileges depending on the ability to target a role trust policy or even create one that allows them further access. These keys always start with ASIA*. We can craft a detection search that gives us what IP address requested sts:Assume, the identity ARN, user agent (from AWS console or CLI), access key, action, what role was requested and what role was given in response, or if it was created successfully. The detection search below should provide enough information to craft alerts and further investigation.
The above search can be further refined by specifying values in the syntax fields, for example specifying only user agents from CLI or failure status, or IP lookups from allow deny list or security groups. When dealing with Sts:Assume role it is possible to get large number of false positives so it is important to understand that this search will likely need to be refined depending on the environment.
The sts:GetSessionToken string is part of the temporary token service and it provides temporary credential information for an specific AWS account or IAM user. GetSessionToken is used to protect programmatic calls to specific AWS API operations. MFA enabled IAM users would execute GetSessionToken calls and submit MFA code. These calls may vary if users are login from identity single sign on providers like Okta. Duration of GetSessionToken obtained credentials are also short term (15 minutes, 36 hours). According to AWS, temporary security credentials created by GetSessionToken can be used to make API calls to any AWS service with two exceptions.
The above however still leaves a number of AWS services which can interact with a potentially compromised temporary token via sts:GetSessionToken.
This search can be adjusted by modifying the values of the fields (i.e status=failure). Also adding further fields to the syntax such as requestParameters.serialNumber which is used for devices authenticating via this method.
We can also look at users creating new roles as we will see in the next two screen captions.
As seen in the above screenshots we can get pretty specific details of who created a role when was created, what ARN was given and from what place it was created( I.E user agent)
We can also monitor and detect users trying to attach themselves to other trust policies, and see if they were successful and what specific role policy they requested to be attached to, the source IP address, region and date of the event. In this case we focused on status=failure but it can be changed to success for example. An attacker could give himself away by trying to attach his compromised account to different roles and failing.
As seen in the above examples it is possible to monitor and detect, actions likely related to Key compromise. We have a number of searches that will work against the outlined scenarios provided the customer has enabled and implemented cloudtrail logs.
About Splunk Security Research Team
The Security Research Team is devoted to delivering actionable intelligence to Splunk's customers, in an unceasing effort to safeguard them against modern enterprise risks. Composed of elite researchers, engineers, and consultants who have served in both public and private sector organizations, this innovative team of digital defenders monitors emerging cybercrime trends and techniques, then translates them into practical analytics that Splunk users can operationalize within their environments. Download Splunk Enterprise Security Content Update in Splunkbase to learn more.
The Splunk platform removes the barriers between data and action, empowering observability, IT and security teams to ensure their organizations are secure, resilient and innovative.
Founded in 2003, Splunk is a global company — with over 7,500 employees, Splunkers have received over 1,020 patents to date and availability in 21 regions around the world — and offers an open, extensible data platform that supports shared data across any environment so that all teams in an organization can get end-to-end visibility, with context, for every interaction and business process. Build a strong data foundation with Splunk.