If you’d like to try it out, please clone my repo: https://github.com/cybersecbella/aws-iam-rag-auditor

git clone https://github.com/cybersecbella/aws-iam-rag-auditor.git

In 2019, a single misconfigured IAM role gave an attacker access to 100 million Capital One customer records. The attacker didn’t break any encryption, exploit any software vulnerability, or write any malware. They just asked AWS for credentials — and AWS said yes. The reason this attack was possible is #4! A policy without conditions and an HTTP request is all it took.

IAM (Identity and Access Management) is AWS’s permission system which controls who can do what to which resources. Every API call in AWS is checked against an IAM system before it executes. A wrong configuration in IAM can let an attacker with one compromised credential own your entire AWS account without ever touching a server. An attacker is after access.

Attackers abuse 4 concepts within IAM:

(1) Roles can be assumed by anyone who has the associated permissions

(2) Trust relationship - Each role has a trust policy that specifies who can take on that role. Dangerous if made too broad as an attacker can assume that role.

{ 
"Effect": "Allow",
"Principal": "*",  #star * means all or everyone, full access 
"Action": "sts:AssumeRole" 
} 

(3) Missing conditions - Conditions are necessary to make a policy secure, policies without conditions leave holes for an attacker to get in if they have access to credentials

(4) IMDS credential theft - EC2 instances (Elastic Compute Cloud instances - provides secure, scalable virtual servers in the cloud) get temporary credentials via the Instance Metadata Service at http://169.254.169.254.

curl http://169.254.169.254/latest/meta-data/iam/security-credentials/MyRole #bash

Returns live AWS credentials


Privilege Escalation Paths

Path 1 — ATT&CK: T1098.003 — Additional Cloud Credentials

Attacker needs:

To execute:

# Attacker runs this with a compromised low-privilege key 
import boto3 iam = boto3.client('iam') 

# Step 1: create a new version of any policy that grants admin 
iam.create_policy_version( 
    PolicyArn='arn:aws:iam::123456789012:policy/SomeExistingPolicy', 
    PolicyDocument=json.dumps({ 
        "Version": "2012-10-17", 
        "Statement": [{"Effect": "Allow", "Action": "*", "Resource": "*"}] 
    }), 
    SetAsDefault=True # immediately active 
) # They now have admin access 

Path 2 — ATT&CK: T1528 — Steal Application Access Token

Attacker needs:

To execute:

Path 3 - ATT&CK: T1098 — Account Manipulation

Attacker needs:

To execute:

aws iam create-access-key --user-name AdminUser # Returns: AccessKeyId + SecretAccessKey 
# don't expire and survive password resets 

Path 4 - ATT&CK: T1098.003

Attacker needs:

aws iam attach-user-policy \
  --user-name compromised-user \
  --policy-arn arn:aws:iam::aws:policy/AdministratorAccess
# They are now an admin
IAM permissionWhat attacker can doEscalation timeATT&CK
iam:CreatePolicyVersionRewrite any policy to grant admin10 secondsT1098.003
iam:PassRole + ec2:RunInstancesLaunch instance with admin role2 minutesT1528
iam:CreateAccessKeyCreate permanent admin credentials5 secondsT1098
iam:AttachUserPolicyAttach AdministratorAccess to self3 secondsT1098.003
iam:SetDefaultPolicyVersionRoll back policy to admin version5 secondsT1098.003
sts:AssumeRole (no condition)Assume any role in the account3 secondsT1078.004

Every misconfiguration and privilege escalation path above is detected by the auditor. The static checker catches wildcards and dangerous actions ➡️The RAG layer retrieves the relevant AWS documentation and explains the specific risk in plain English.


The goal of this project is to build a RAG system that relies on Faiss and Langchain to check IAM policies for misconfigurations and privilege escalation paths that will allow an attacker access.

Note: If you want to try it without using an anthropic key use

Install Ollama from https://ollama.com, then pull a model

ollama pull llama3 

# Swap in iam_auditor.py: 
from langchain_community.llms import Ollama 
llm = Ollama(model="llama3") 

Architecture aws1

Code explanations


Time to test it

python src/ingest.py

aws13

python src/app.py
>>>audit policies/admin_wildcard.json
>>>query What IAM actions enable privilege escalation
>>>paste least_privilege.json
>>>examples #to know how and what to prompt 
>>>quit #to exit CLI