Automate EC2 Forensics via VPC Flow Logs
Build an event-driven AWS forensic pipeline that detects a live SSH brute-force attack and snapshots the victim automatically
Overview
NxTrade Corp runs a trade-processing engine called TradeEngine-Alpha on an EC2 instance inside a production VPC. SSH is reachable from the entire internal range and relies on password authentication, and a compromised internal host is brute-forcing it right now.
You work as a junior incident responder with console access and deliberately limited IAM permissions. You investigate the live attack from the network and the host, preserve evidence to S3 with chain-of-custody metadata, build an event-driven pipeline that snapshots the victim's disk and alerts the team automatically, prove it fires end to end against live attack traffic, and contain both machines.
Objectives
Investigate a live SSH brute-force attack, preserve forensic evidence to an S3 evidence bucket, build an automated detection-and-response pipeline with VPC Flow Logs, a CloudWatch subscription filter, Lambda and EBS snapshots, prove it fires end to end, and contain both hosts.
Prerequisites
- Basic familiarity with the AWS Management Console, navigating between services and reading resource details
- Understanding of VPC networking concepts including subnets, security groups, and private IP addressing
- Ability to read and interpret VPC Flow Log fields such as source IP, destination IP, port, and action
- Basic Linux command-line proficiency over SSH
- Familiarity with AWS IAM roles, policies, and the principle of least privilege
- Basic understanding of AWS Lambda functions and event-driven architecture
- Awareness of EBS snapshots as a forensic preservation mechanism
- Understanding of SSH brute-force attack patterns and how they appear in system and network logs
Learning outcomes
- Identify a brute-force SSH attack by correlating repeated port-22 connections in VPC Flow Logs with failed authentication entries in the system journal
- Perform forensic evidence preservation by capturing host logs and uploading them to a dedicated S3 evidence bucket with chain-of-custody metadata
- Leverage IAM role attachment to grant time-scoped, least-privilege permissions to an EC2 instance for evidence export
- Use AWS Lambda to build an automated forensic-capture pipeline triggered by a CloudWatch Logs subscription filter
- Enumerate the environment variables and IAM inline policies required to wire a Lambda function to EC2 snapshot creation and SNS alerting
- Prove the detection-to-response chain fires end to end by driving a live attack event through the pipeline
- Understand how an IAM permissions boundary constrains a broad inline policy written by an operator
- Perform network containment by swapping security groups on both the victim and attacker instances to isolate them from the VPC
Real-world context
Internal lateral movement following an initial compromise is one of the most common patterns in cloud breaches. Attackers who gain a foothold on a low-value host immediately scan the internal network for services with password-based authentication, and SSH on port 22 is the first target because it is almost always present on Linux instances. Organizations that leave security groups open to the full VPC range and rely on password authentication create an environment where a single compromised host can reach every SSH listener in the network.
The compounding factor is time. Without automated detection and response, the window between initial brute-force activity and successful credential guessing can be minutes, and expecting a human analyst to be watching a dashboard at that speed outside business hours is unrealistic. Building event-driven forensic pipelines that fire on specific log patterns, preserve disk state before it can be tampered with, and alert the security team at the same time is the operational model that reduces mean-time-to-respond from hours to seconds.