IMDSPOOF is a cyber deception tool that spoofs an AWS IMDS service. One way that attackers are able to escalate privileges or move laterally in a cloud environment is by retrieving AWS Access keys from the IMDS service endpoint located at http://169.254.169.254/latest/meta-data/iam/security-credentials/<user>
. This tool spoofs that endpoint and redirects traffic sent to 169.254.169.254
to a local webserver that serves fake data. This can be leveraged for highly tuned detections by inserting honey AWS tokens into the response of the spoofed IMDS response.
This tool is intended to be used by blue teams on AWS instances that are NOT actively using the IMDS (version 1 or 2).
From an attacker’s perspective, they have no idea if the IMDS is being used on the EC2 instance they’re in. The goal of IMDSPOOF is to trick an attacker who lands in your cloud environment into thinking that they’re interacting with a legitimate IMDS service.
Once again, if the applications running on your EC2 instance ARE using the IMDS service, this tool WILL cause issues!
To try out IMDSPOOF in a test environment, create an EC2 instance and make sure iptables is installed (yum install iptables-services
if using amazon linux)
IMDS.go
(How To Compile Go Code)curl http://169.254.169.254/latest/meta-data/iam/security-credentials/ec2-admin
{
"Code": "Success",
"Message": "The request was successfully processed.",
"LastUpdated": "2023-11-22T03:33:51Z",
"Type": "AWS-HMAC",
"AccessKeyId": "InsertHoneyToken",
"SecretAccessKey": "InsertHoneyToken",
"Token": "HoneyToken",
"Expiration": "2023-11-22T09:33:51Z"
}
iptables -t nat -D OUTPUT -p tcp -d 169.254.169.254 --dport 80 -j DNAT --to-destination 127.0.0.1:54321
In order for this to be useful, you must change the variables at the top of the IMDS.go
file to be something more real looking. I highly recommend placing honey tokens in the file. You can leave the token
variable alone or change it to a custom one.
IMDS.go
to whatever you want returned from accessing http://169.254.169.254/latest/meta-data/iam/security-credentials/ec2-admin
var accessKey string = "InsertHoneyToken"
var secretAccessKey string = "InsertHoneyToken"
var token string = "IQoJb3Jpz2cXpQRkpVX3Uf////////////xMdLZHNjb<snip>"
The folks over at Thinkst Canary have a wonderful tool that allows you to easily generate AWS credentials that will generate an alert on usage.
Note down the honeytoken provided
aws_access_key_id = AKIA....
aws_secret_access_key = uZF0y/l5X....
Within the IMDS.go source code, replace the accessKey
and secretAccessKey
variable’s with the aws_access_key_id
and aws_secret_access_key
values given to you by CanaryTokens.
Compile IMDS.go. IMDS will now return the honey tokens when the IMDS is queried.
Wait for an attacker to attempt to use the credentials
Email alert from Canary Token
Running IMDS spoof at startup can be done easily by create a systemd service and enabling the service.
sudo vim /etc/systemd/system/IMDS.service
(You can name this something else more stealthy if you wish but the following systemctl
commands expect the service to be named IMDS.service
)IMDS.service
file just created[Unit]
# Change this to something else if you wish
Description=IMDSPOOF
# After dependencies are available
After=multi-user.target
[Service]
# Type of service
Type=simple
# Command to execute the service program
ExecStart=/bin/IMDS
# User to run the service as
User=root
# Restart if the service crashes
Restart=always
# Restart delay in seconds
RestartSec=10
[Install]
# Enable the service at boot
WantedBy=multi-user.target
/bin/
directory: sudo mv IMDS /bin/
sudo systemctl enable IMDS
sudo systemctl start IMDS
sudo systemctl status IMDS
Yes! Because of the way IMDSpoof manipulates the iptables on the ec2 instance, it doesn’t matter where the traffic is coming from. This means that in addition to this working via the curl utilitiy on the EC2 instance, IMDSpoof also works if an SSRF vulnerability is found through a web application hosted on the EC2 instance. Using the following vulnerable application from AlexanderHose’s blog on IMDS pentesting, we can exploit the SSRF vulnerability which will also return the fake credentials from IMDSpoof
sudo systemctl stop IMDS
sudo systemctl disable IMDS
iptables -t nat -D OUTPUT -p tcp -d 169.254.169.254 --dport 80 -j DNAT --to-destination 127.0.0.1:54321
shadow-rs is a Windows kernel rootkit written in Rust, demonstrating advanced techniques for kernel manipulation…
Extract and execute a PE embedded within a PNG file using an LNK file. The…
Embark on the journey of becoming a certified Red Team professional with our definitive guide.…
This repository contains proof of concept exploits for CVE-2024-5836 and CVE-2024-6778, which are vulnerabilities within…
This took me like 4 days (+2 days for an update), but I got it…
MaLDAPtive is a framework for LDAP SearchFilter parsing, obfuscation, deobfuscation and detection. Its foundation is…