The attacker runs code on an EC2 instance, often through an exploited internet-facing service, and sometimes through a stolen SSH key or a Systems Manager session. A typical run installs a miner or a backdoor, reads the instance role credentials from the metadata service, and moves on to the AWS API. Capture memory and disks before you cut the network.
Look here
Log
Search for
GuardDuty Runtime Monitoring (agent on the instance)
Process-level findings from the agent: Execution:Runtime/ReverseShell, Execution:Runtime/SuspiciousCommand, Persistence:Runtime/SuspiciousCommand, PrivilegeEscalation:Runtime/ElevationToRoot, DefenseEvasion:Runtime/KernelModuleLoaded, Impact:Runtime/CryptoMinerExecuted
GuardDuty EC2 and Malware Protection
Findings for command and control, brute force, mining and malware: Backdoor:EC2/C&CActivity.B, UnauthorizedAccess:EC2/SSHBruteForce, CryptoCurrency:EC2/BitcoinTool.B, Trojan:EC2/DNSDataExfiltration, Execution:EC2/MaliciousFile
AWS WAF logs and Application Load Balancer (ALB) access logs, both off by default
Requests to the exposed service before the first finding. Read WAF uri, args, clientIp, action and terminatingRuleId, and ALB request lines and status codes by client. WAF does not log request bodies
Amazon Inspector (EC2 scanning must be active)
Vulnerabilities in the instance image: aws inspector2 list-findings --filter-criteria '{"ec2InstanceImageId":[{"comparison":"EQUALS","value":"<ami>"}],"findingStatus":[{"comparison":"EQUALS","value":"ACTIVE"}]}'
VPC Flow Logs
Inbound SSH or RDP from unknown sources and outbound connections to unknown hosts, if a flow log exists for the VPC or interface
Boot and kernel messages from the instance: aws ec2 get-console-output --instance-id <id> --latest
Contain
#
Item
1
Save the instance record and console output above. See Evidence
2
Read the web ACL and its lock token before you add a rule for the vulnerable path: aws wafv2 get-web-acl --name <acl> --scope REGIONAL --id <id>
3
Block the exploit path while the patch is prepared. The call replaces the whole web ACL, so send every existing rule plus the new one, with the returned lock token: aws wafv2 update-web-acl --name <acl> --scope REGIONAL --id <id> --default-action Allow={} --visibility-config file://visibility.json --rules file://rules.json --lock-token <token>
4
Without a WAF, remove the security group rule that exposes the service: aws ec2 revoke-security-group-ingress --group-id <sg> --security-group-rule-ids <sgr>
5
Turn on termination protection: aws ec2 modify-instance-attribute --instance-id <id> --disable-api-termination
6
Set OS shutdown to stop the instance: aws ec2 modify-instance-attribute --instance-id <id> --instance-initiated-shutdown-behavior Value=stop
7
Detach the instance from its Auto Scaling group, which also deregisters it from the group's load balancers: aws autoscaling detach-instances --instance-ids <id> --auto-scaling-group-name <asg> --should-decrement-desired-capacity
8
Capture memory while the agent still reaches Systems Manager. Run your acquisition tool through Run Command (AWS-RunShellScript) and write to an attached evidence volume
9
Snapshot every volume and tag the snapshots with the case: aws ec2 create-snapshots --instance-specification InstanceId=<id> --copy-tags-from-source volume --tag-specifications 'ResourceType=snapshot,Tags=[{Key=case,Value=<case>}]'
10
Require IMDSv2 on the instance: aws ec2 modify-instance-metadata-options --instance-id <id> --http-tokens required --http-endpoint enabled
11
Revoke the instance role's older sessions: aws iam put-role-policy --role-name <role> --policy-name AWSRevokeOlderSessions --policy-document file://revoke.json
12
Move each network interface to a quarantine security group with no rules: aws ec2 modify-network-interface-attribute --network-interface-id <eni> --groups <sg-quarantine>
13
Stop the instance destructive to memory and instance store, only after capture: aws ec2 stop-instances --instance-ids <id>
Eradicate and recover
#
Item
1
Create volumes from the snapshots and attach them to a forensic instance in an isolated account
2
Scan the instance for malware. Wait one hour between scans of one instance: aws guardduty start-malware-scan --resource-arn arn:aws:ec2:<region>:<account>:instance/<id>
3
Close the entry point: the open port, the vulnerable service or the stolen key
4
Rebuild from a known-good Amazon Machine Image (AMI), and rotate every secret and SSH key that was on the host
5
Find every instance launched from the same image, then patch or rebuild each one and update the launch template or AMI behind each Auto Scaling group: aws ec2 describe-instances --filters Name=image-id,Values=<ami>
6
Delete key pairs and security group rules the attacker added, and set IMDSv2 as the account default
7
Turn on GuardDuty Runtime Monitoring for EC2 before return to service
Watch out
A security group change leaves tracked connections open until they time out. A network ACL deny on the subnet breaks them at once.
Stop, hibernate and terminate erase instance store volumes. Hibernation saves RAM to the root EBS volume only when it was enabled at launch.
Termination protection does not stop Auto Scaling from terminating an unhealthy instance, or an OS shutdown when shutdown behavior is terminate. Detach and change the behavior first.
A quarantine group with no outbound rules also cuts the SSM Agent. Finish Run Command work before step 12.
AWS documentation: Security Incident Response Guide, infrastructure domain; EC2 termination protection, hibernation, instance store lifetime, security group connection tracking and CloudTrail logging; CLI modify-instance-attribute and create-snapshots; Auto Scaling detach and health checks; GuardDuty finding types, Runtime Monitoring findings and on-demand malware scan; AWS WAF logging and log fields; ALB access logs; CLI inspector2 list-findings, wafv2 get-web-acl and update-web-acl, ec2 revoke-security-group-ingress and describe-instances. GuardDuty finding types and on-demand malware scan checked October 2026; other topics checked September 2026.