Skip to content

Add An Existing Role To A New Ec2 Instance (aws)

PlatformAuthorLast Update
awsNick Jones2024-12-02

An adversary may attach an existing role to a new EC2 instance to which they have access

MITRE IDs

Required Permissions

  • iam:PassRole
  • ec2:RunInstances

Required Parameters

NameTypeDescriptionExample Value
image_idstrAMI to create instance fromami-a4dc46db
instance_typestrType of instance to createt2.micro
iam_instance_profile_namestrEC2 instance profile to assignec2-instance-profile
key_namestrName of SSH key to assign to instancemy-ssh-key
security_group_idstrID of a security group to apply to the instancesg-123456

Attacker Action

Terminal window
aws ec2 run-instances –image-id image_id –instance-type instance_type –iam-instance-profile Name=iam_instance_profile_name –key-name key_name –security-group-ids security_group_ids

Detection Case

ELK query

When logs are ingested into ELK, the following Lucene query can be used to identify relevant events.

eventName:RunInstances AND eventSource:ec2.amazonaws.com

Sigma Definition

---
title: Add an existing role to a new EC2 instance
id: 899eb2b1-6e96-4203-bd38-9cddf970a50a
status: experimental
author: Nick Jones
date: 2024-12-02
description: An adversary may attach an existing role to a new EC2 instance to which they have access
logsource:
service: cloudtrail
detection:
selection_source:
- eventSource: "ec2.amazonaws.com"
events:
- eventName: "RunInstances"
condition: selection_source and events
level: low
tags:
- attack.T1098
falsepositives:
- Developers making legitimate changes to the environment. Verify whether the user identity, user agent, and/or hostname should be making changes in your environment.