elastic / detection-rules

https://www.elastic.co/guide/en/security/current/detection-engine-overview.html
Other
1.92k stars 492 forks source link

[New Rule] AWS Signin Single Factor Console Login via Federated Session #3992

Closed terrancedejesus closed 1 month ago

terrancedejesus commented 1 month ago

Pull Request

Issue link(s): https://github.com/elastic/ia-trade-team/issues/272

Summary - What I changed

Added a new detection rule for AWS regarding single factor console logins via a federated session or token (temporary credentials). This behavior is highly unusual to login from a federated session if permissions to access the console are applied to the existing IAM user or role.

How To Test

Script to Get Temporary Creds and Create Admin Console Login URL

The script will use the already authenticated IAM user with the local AWS cli and request a federated token (temp creds) from AWS with the AdministratorAccess policy attached. Once the output is saved, it will request a sign-in token from AWS' federated endpoint and create a login URL. Once the URL is output, it can be clicked to automatically authenticate into the console.

```shell #!/bin/bash # Get federated creds output=$(aws sts get-federation-token --name consoler --policy-arns arn=arn:aws:iam::aws:policy/AdministratorAccess) # Check if the previous command was successful if [ $? -ne 0 ]; then echo "The command 'aws sts get-federation-token --name consoler' failed." exit 1 fi # Parse the output session_id=$(echo "$output" | jq -r '.Credentials.AccessKeyId') session_key=$(echo "$output" | jq -r '.Credentials.SecretAccessKey') session_token=$(echo "$output" | jq -r '.Credentials.SessionToken') # Check if parsing was successful if [ -z "$session_id" ] || [ -z "$session_key" ] || [ -z "$session_token" ]; then echo "Failed to parse session credentials." exit 1 fi # Construct the JSON credentials string json_creds=$(echo -n "{\"sessionId\":\"$session_id\",\"sessionKey\":\"$session_key\",\"sessionToken\":\"$session_token\"}") # Define the AWS federation endpoint federation_endpoint="https://signin.aws.amazon.com/federation" # Make the HTTP request to get the sign-in token resp=$(curl -s "$federation_endpoint" \ --get \ --data-urlencode "Action=getSigninToken" \ --data-urlencode "SessionDuration=43200" \ --data-urlencode "Session=$json_creds" ) # Check if the curl command was successful if [ $? -ne 0 ]; then echo "The curl command failed." exit 1 fi # Extract the sign-in token signin_token=$(echo -n "$resp" | jq -r '.SigninToken') # Check if the sign-in token was extracted successfully if [ -z "$signin_token" ]; then echo "Failed to retrieve the sign-in token." exit 1 fi # URL encode the token for the login URL encoded_token=$(echo -n "$signin_token" | jq -sRr @uri) # Give the URL to login login_url="https://signin.aws.amazon.com/federation?Action=login&Issuer=example.com&Destination=https%3A%2F%2Fconsole.aws.amazon.com%2F&SigninToken=$encoded_token" echo "Login URL: $login_url" ```
Screenshot 2024-08-19 at 11 54 42 PM

Checklist

Contributor checklist

protectionsmachine commented 1 month ago

Rule: New - Guidelines

These guidelines serve as a reminder set of considerations when proposing a new rule.

Documentation and Context

Rule Metadata Checks

New BBR Rules

Testing and Validation