Objective:
Understand how overly permissive security groups and network ACLs expose cloud resources to unauthorized access. Simulate an attack that exploits open ports or services and learn how to secure network controls with strict inbound and outbound rules.
Scenario:
An organization deploys an EC2 instance with security groups and network ACLs configured to allow excessive access, such as open SSH or database ports to the public internet. Attackers exploit these open network controls to gain unauthorized access to cloud resources. Your goal is to simulate this attack and recommend strategies for securing network configurations.
Lab Setup:
Prerequisites:
- Access to a cloud platform:
- AWS or Google Cloud.
- Installed tools:
- aws-cli (Installation Guide).
- Nmap (Download).
Steps to Set Up the Lab:
- Launch an EC2 Instance:
- Navigate to AWS EC2 > Launch Instance.
- Configure the instance:
- AMI: Amazon Linux 2 or Ubuntu.
- Instance Type: t2.micro.
- Key Pair: Select or create a key pair for SSH access.
- Security Group: Create a new security group with the following settings:
- Inbound Rules:
- Allow SSH (port 22) from
0.0.0.0/0
. - Allow HTTP (port 80) from
0.0.0.0/0
. - Allow MySQL (port 3306) from
0.0.0.0/0
.
- Allow SSH (port 22) from
- Outbound Rules:
- Allow all traffic by default.
- Inbound Rules:
- Launch the instance and note its public IP.
- Modify the Network ACL:
- Navigate to VPC > Network ACLs.
- Create a new network ACL and associate it with the instance’s subnet.
- Configure overly permissive rules:
- Inbound Rules:
- Allow all traffic from
0.0.0.0/0
(source IP).
- Allow all traffic from
- Outbound Rules:
- Allow all traffic to
0.0.0.0/0
(destination IP).
- Allow all traffic to
- Inbound Rules:
- Install Vulnerable Services:
- Connect to the instance using SSH:bashCopyEdit
ssh -i <key-file>.pem ec2-user@<public-ip>
- Install a web server (Apache) and database server (MySQL):bashCopyEdit
sudo yum install httpd mysql-server -y sudo systemctl start httpd sudo systemctl start mysqld
- Create a test webpage:bashCopyEdit
echo "Test Webpage - Security Misconfiguration" | sudo tee /var/www/html/index.html
- Connect to the instance using SSH:bashCopyEdit
Exercise: Exploiting the Misconfigured Network Controls
Objective:
Simulate an attacker exploiting the open network controls to gain unauthorized access to the cloud resource.
- Scan for Open Ports:
- Use Nmap to enumerate open ports on the EC2 instance:bashCopyEdit
nmap -Pn -p 22,80,3306 <public-ip>
- Verify that ports for SSH (22), HTTP (80), and MySQL (3306) are open.
- Use Nmap to enumerate open ports on the EC2 instance:bashCopyEdit
- Exploit Open Services:
- Access the test webpage using a browser:vbnetCopyEdit
http://<public-ip>
- Attempt to connect to the MySQL server using default credentials:bashCopyEdit
mysql -h <public-ip> -u root -p
- If no password is set, log in to the database and enumerate tables.
- Access the test webpage using a browser:vbnetCopyEdit
- Simulate Unauthorized SSH Access:
- Attempt to brute-force SSH access using a tool like Hydra (optional):bashCopyEdit
hydra -l ec2-user -P /usr/share/wordlists/rockyou.txt ssh://<public-ip>
- Attempt to brute-force SSH access using a tool like Hydra (optional):bashCopyEdit
- Analyze the Impact:
- Show how an attacker can enumerate open ports, access services, and potentially exfiltrate data.
Tools Required:
- AWS EC2: For deploying the instance.
- Nmap: For port scanning and service enumeration.
- aws-cli: For managing the cloud environment.
- Hydra (optional): For brute-forcing SSH credentials.
Deliverables:
- Exploit Report:
- Evidence of open ports and services being accessed.
- Logs or screenshots demonstrating unauthorized access to SSH, HTTP, or MySQL.
- Recommendations for Securing Security Groups and Network ACLs:
- Steps to harden inbound and outbound rules and monitor network activity.
Solution:
- Identified Vulnerabilities:
- Open Ports: SSH, HTTP, and MySQL ports were accessible to the public internet.
- Overly Permissive Network ACLs: Allowed unrestricted inbound and outbound traffic.
- No Access Monitoring: No alerts or logs were configured to detect unauthorized access.
- Consequences:
- Unauthorized Access: Attackers could access open ports and exploit vulnerable services.
- Data Breach: Sensitive data in the database could be exfiltrated.
- Service Disruption: Unauthorized access could lead to resource misuse or denial of service.
- Prevention Techniques:
- Harden Security Group Rules:
- Restrict inbound access to specific IP ranges:jsonCopyEdit
{ "Type": "SSH", "Protocol": "TCP", "PortRange": "22", "Source": "192.168.1.0/24" }
- Restrict inbound access to specific IP ranges:jsonCopyEdit
- Configure Network ACLs:
- Allow specific traffic only, such as:
- Inbound:
- Allow HTTP (port 80) from trusted IPs.
- Allow SSH (port 22) from a specific management network.
- Outbound:
- Allow only required traffic for the instance’s operation.
- Inbound:
- Allow specific traffic only, such as:
- Enable Monitoring and Alerts:
- Use AWS CloudWatch or GuardDuty to monitor for suspicious network activity.
- Regularly Audit Rules:
- Use AWS Config to detect overly permissive rules and recommend remediation.
- Limit Exposure:
- Deploy bastion hosts for SSH access and restrict database access to the internal network.
- Harden Security Group Rules:
Conclusion:
This exercise demonstrates how misconfigured security groups and network ACLs expose cloud resources to unauthorized access. By hardening network controls, monitoring activity, and following the principle of least privilege, organizations can mitigate these risks and protect their cloud environments.
0 Comments