A comprehensive AWS-based cybersecurity training environment that simulates real-world attack and defense scenarios using Terraform Infrastructure as Code.
This project creates an isolated AWS environment where Red Team members can practice penetration testing while Blue Team members learn to detect, monitor, and respond to security threats. The infrastructure includes intentionally vulnerable applications, comprehensive monitoring, and realistic network segmentation.
- AWS CLI v2 - Command line interface for AWS
- Terraform >= 1.0 - Infrastructure as Code tool
- SSH Key Pair - For secure access (though we'll use Session Manager primarily)
# Download and install AWS CLI v2
msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi# Using Homebrew
brew install awscli
# Or download installer
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install-
Create AWS Credentials File
mkdir -p ~/.aws -
Configure Credentials (
~/.aws/credentials):[terraform] aws_access_key_id = YOUR_ACCESS_KEY_HERE aws_secret_access_key = YOUR_SECRET_KEY_HERE region = us-east-1
-
Verify Configuration:
aws sts get-caller-identity --profile terraform
red-blue-team-lab/
โโโ ๐ README.md # This file
โโโ ๐ .gitignore # Git ignore rules
โโโ ๐ main.tf # Main Terraform configuration
โโโ ๐ variables.tf # Input variables
โโโ ๐ outputs.tf # Output values
โโโ ๐ terraform.tfvars # Your variable values (create this)
โโโ ๐ scripts/ # Initialization scripts
โโโ ๐ app_server_init.sh # Vulnerable web app setup
โโโ ๐ kali_init.sh # Red team tools setup
โโโ ๐ db_server_init.sh # Database server setup
โโโ ๐ blue-team-policy.json # Blue team IAM policy
โโโ ๐ red-team-policy.json # Red team IAM policy
git clone <repository-url>
cd red-blue-team-lab# Generate SSH key pair if you don't have one
ssh-keygen -t rsa -b 4096 -f ~/.ssh/red_blue_lab_keyCreate a terraform.tfvars file in the project root:
# AWS Configuration
region = "us-east-1"
my_ip = "YOUR_IP_HERE/32" # Get with: curl ifconfig.me
alert_email = "admin@yourcompany.com"
# SSH Key Configuration
public_key_path = "~/.ssh/red_blue_lab_key.pub"
# Project Configuration
project_name = "cybersec-lab"
environment = "lab"
# Instance Types (Free Tier)
kali_instance_type = "t3.micro"
app_instance_type = "t3.micro"
db_instance_type = "t3.micro"
# Network Configuration (Optional - uses dynamic CIDR by default)
# vpc_cidr = "10.0.0.0/16"
# public_subnet_cidr = "10.0.1.0/24"
# private_app_subnet_cidr = "10.0.2.0/24"
# private_db_subnet_cidr = "10.0.3.0/24"# Find your public IP address
curl ifconfig.me
# Add /32 to the end for CIDR format
# Example: 203.0.113.45/32# Initialize Terraform
terraform init
# Review the deployment plan
terraform plan
# Deploy infrastructure (type 'yes' when prompted)
terraform apply
# Save outputs to file
terraform output -json > lab_outputs.jsonThis lab utilizes the following AWS services:
- ๐ VPC - Virtual Private Cloud for network isolation
- ๐ EC2 - Virtual machines for Red/Blue team infrastructure
- ๐ก๏ธ Security Groups - Network-level firewall rules
- ๐ช Internet Gateway - Internet access for public subnet
- ๐ NAT Gateway - Outbound internet for private subnets
- ๐ CloudWatch - Logging, monitoring, and alerting
- ๐ง SNS - Email notifications for security alerts
- ๐ IAM - Identity and Access Management for team members
- ๐ VPC Flow Logs - Network traffic analysis
- ๐ฅ๏ธ Systems Manager - Secure instance access via Session Manager
- ๐ EC2 Key Pairs - SSH key management
This lab uses AWS Systems Manager Session Manager for secure access to instances. This eliminates the need for SSH connections, bastion hosts, or exposing SSH ports to the internet.
- Navigate to EC2 Console
- Select your instance
- Click "Connect"
- Choose "Session Manager" tab
- Click "Connect"
# Access Kali Linux (Red Team)
aws ssm start-session --target i-1234567890abcdef0 --profile terraform
# Access Application Server
aws ssm start-session --target i-abcdef1234567890 --profile terraform
# Access Database Server
aws ssm start-session --target i-567890abcdef1234 --profile terraform# View all connection information
terraform output connection_info
# Get specific instance ID
terraform output -raw connection_info | jq '.kali_id'- โ No SSH keys to manage
- โ No bastion hosts required
- โ All sessions logged in CloudTrail
- โ IAM-based access control
- โ No inbound ports needed
After deployment, team member credentials are generated and can be accessed securely:
# View all team credentials (sensitive output)
terraform output team_credentials
# Save credentials to JSON file
terraform output -json team_credentials > team_credentials.json{
"red_team": {
"cybersec-lab-red-member-1": {
"username": "cybersec-lab-red-member-1",
"password": "RandomSecurePassword123!"
},
"cybersec-lab-red-member-2": {
"username": "cybersec-lab-red-member-2",
"password": "AnotherRandomPassword456!"
}
},
"blue_team": {
"cybersec-lab-blue-member-1": {
"username": "cybersec-lab-blue-member-1",
"password": "BlueTeamPassword789!"
},
"cybersec-lab-blue-member-2": {
"username": "cybersec-lab-blue-member-2",
"password": "MonitoringPassword012!"
}
}
}# Get Kali instance ID
KALI_ID=$(terraform output -raw connection_info | jq -r '.kali_id')
# Connect via Session Manager
aws ssm start-session --target $KALI_ID --profile terraform- Web Application: Access via private IP from Kali instance
- Database Server: Network reachable from application subnet
-
SQL Injection
- Target:
/login.php - Payload:
admin' OR '1'='1' -- - Flag:
FLAG{SQL_INJECTION_SUCCESS}
- Target:
-
Command Injection
- Target:
/admin.php?auth=admin123 - Payload:
127.0.0.1; whoami - Flag:
FLAG{COMMAND_INJECTION_ACCESS}
- Target:
-
Directory Traversal
- Target:
/files.php?file= - Payload:
../../../etc/passwd - Flag:
FLAG{DIRECTORY_TRAVERSAL_READY}
- Target:
-
Network Reconnaissance
# Port scanning nmap -sS [target-subnet] # Service enumeration nmap -sV -p- [target-ip] # Database probing nmap -p 3306 --script mysql-enum [db-ip]
# Get security dashboard URL
terraform output security_monitoring- Port Scan Detection - Automated alerts for >10 rejected connections
- SSH Brute Force Monitoring - Alerts for >20 SSH attempts
- Database Access Monitoring - Suspicious database connection alerts
- Web Application Attack Detection - HTTP log analysis for attack patterns
- Monitor CloudWatch Dashboard for real-time threat visualization
- Analyze VPC Flow Logs for attack pattern identification
- Investigate Security Alerts from SNS notifications
- Practice Incident Response procedures
Access your CloudWatch security dashboard:
terraform output security_monitoring | jq -r '.security_dashboard_url'- VPC Flow Logs:
/aws/vpc/flowlogs/[project-name] - Application Logs: Via Session Manager to app server โ
/var/log/httpd/access_log - Attack Monitoring: Via Session Manager to app server โ
/var/log/red_team_activity.log
- Email alerts sent to configured email address
- Real-time notifications for security events
- Threshold-based alerting for anomalous behavior
- Instance Types: t3.micro (free tier eligible)
- Storage: Minimal EBS volumes
- Monitoring: 7-day log retention
- Estimated Cost: $0-5/month within free tier limits
# Destroy all resources when done
terraform destroy
# Confirm destruction by typing 'yes' when prompted# Verify AWS profile
aws sts get-caller-identity --profile terraform
# If profile doesn't exist, reconfigure
aws configure --profile terraform# Check if key exists
ls -la ~/.ssh/red_blue_lab_key*
# Create new key if needed
ssh-keygen -t rsa -b 4096 -f ~/.ssh/red_blue_lab_key# Update your current IP
curl ifconfig.me
# Update terraform.tfvars with new IP/32
terraform apply# Install/update Session Manager plugin
# macOS
brew install --cask session-manager-plugin
# Windows - Download from AWS documentation
# Linux
curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/linux_64bit/session-manager-plugin.rpm" -o "session-manager-plugin.rpm"
sudo yum install -y session-manager-plugin.rpm- Network Reconnaissance: Discovery and enumeration techniques
- Web Application Security: OWASP Top 10 vulnerability exploitation
- Network Penetration: Lateral movement and privilege escalation
- Tool Proficiency: nmap, hydra, sqlmap, nikto, metasploit
- Security Monitoring: Log analysis and pattern recognition
- Incident Detection: Alert triage and investigation
- Threat Hunting: Proactive security analysis
- Response Procedures: Containment and remediation strategies
- Segmented Architecture: Three-tier network design
- Least Privilege: Role-based access controls
- Monitoring: Comprehensive logging and alerting
- Secure Access: Session Manager instead of SSH
- Credential Management: Randomly generated passwords
- Access Logging: All activities tracked in CloudTrail
- Resource Tagging: Organized resource management
- Cost Controls: Free tier optimization
# View all outputs
terraform output
# Get connection info
terraform output connection_info
# Access specific instance
aws ssm start-session --target $(terraform output -raw connection_info | jq -r '.kali_id') --profile terraform
# View team credentials
terraform output team_credentials
# Clean up everything
terraform destroy- Team Credentials:
team_credentials.json(after running terraform output) - Lab Outputs:
lab_outputs.json(after running terraform output) - Terraform State:
terraform.tfstate(managed by Terraform)
๐ฏ Educational Purpose: Designed for cybersecurity training, incident response practice, and security tool evaluation in a controlled environment.