AWS Security & Encryption
1ļøā£ Why Encryption?
Encryption is the process of converting data into a coded form to prevent unauthorized access.
In AWS, encryption ensures data confidentiality, integrity, and compliance with regulations such as GDPR, HIPAA, and PCI-DSS.
Key Reasons to Encrypt Data:
- š Data Protection: Prevents unauthorized access to sensitive information.
- š Compliance Requirements: Many industries require encrypted data storage and transfer.
- š Secure Communication: Ensures safe data transfer between services or over the internet.
- š¾ Data at Rest & In Transit: Protects both stored and moving data.
2ļøā£ Types of Encryption in AWS
AWS supports two primary types of encryption:
Server-Side Encryption (SSE)
- AWS handles encryption and decryption.
- Used in S3, EBS, RDS, DynamoDB.
- Types:
- SSE-S3 (Managed by S3)
- SSE-KMS (Managed via KMS keys)
- SSE-C (Customer-provided keys)
Client-Side Encryption (CSE)
- You encrypt data before sending to AWS and decrypt it after retrieval.
- Keys are managed entirely by you.
3ļøā£ AWS KMS (Key Management Service)
AWS KMS is a fully managed service that creates and controls cryptographic keys used to encrypt your data.
Features:
- ā Centralized key management
- ā Integration with many AWS services (S3, EBS, RDS)
- ā Automatic key rotation
- ā Audit logs via CloudTrail
- ā Supports symmetric and asymmetric encryption
4ļøā£ KMS Multi-Region Keys
- These are cryptographic keys replicated across AWS Regions.
- Enables data encryption in multiple Regions with the same key material.
- Ideal for multi-Region disaster recovery, data replication, and global applications.
5ļøā£ AWS Systems Manager (SSM) Parameter Store
-
Securely stores configuration data and secrets such as:
-
- Database connection strings
- API keys
- Passwords
-
- Supports:
- Plaintext parameters
- Encrypted parameters using AWS KMS
- Reduces the risk of hardcoding sensitive data in applications.
6ļøā£ AWS Secrets Manager
-
Purpose-built for managing secrets, such as:
- Database credentials
- API keys
- OAuth tokens
- Features:
- Automatic secret rotation
- Encrypted storage using KMS
- Fine-grained IAM policies
- Eliminates manual rotation of secrets
7ļøā£ AWS Certificate Manager (ACM)
- Simplifies provisioning, management, and deployment of SSL/TLS certificates.
- Used to secure:
- Websites
- Load balancers
- API endpoints
-
ACM Benefits:
- Automatic renewal
- Free public SSL/TLS certificates
- Integration with services like CloudFront and ELB
8ļøā£ AWS WAF (Web Application Firewall)
- Protects web applications from common web exploits, such as:
- SQL Injection
- Cross-Site Scripting (XSS)
- Malicious IP requests
-
Key features:
- Customizable rules
- Bot control
- Integration with CloudFront, ALB, and API Gateway
9ļøā£ AWS Shield
- A managed Distributed Denial of Service (DDoS) protection service.
-
Types:
- Shield Standard: Free, automatic protection against common network DDoS attacks.
- Shield Advanced: Paid service with enhanced protection, real-time metrics, and 24/7 DDoS response team support.
š AWS Firewall Manager
- A centralized security management service for:
- AWS WAF rules
- Shield Advanced protections
- Security groups
- Helps enforce security policies across multiple AWS accounts and resources in an organization.
1ļøā£1ļøā£ WAF vs. Firewall Manager vs. Shield
Feature | AWS WAF | AWS Firewall Manager | AWS Shield |
---|---|---|---|
Purpose | Protects web apps from exploits | Manages and deploys firewall policies globally | Protects against DDoS attacks |
Scope | Application-level security | Multi-account and resource-level management | Network-level DDoS resilience |
Use Case | Block malicious requests | Apply consistent security rules org-wide | Prevent downtime from volumetric attacks |
1ļøā£2ļøā£ AWS Best Practices for DDoS Resiliency
- Use AWS Shield Advanced for critical applications.
- Deploy CloudFront to absorb traffic.
- Enable AWS WAF for application-layer attack prevention.
- Use Auto Scaling to handle sudden traffic spikes.
- Configure Route 53 health checks and failover routing.
- Apply rate-based rules in WAF to block abusive traffic.
1ļøā£3ļøā£ Amazon GuardDuty
-
Intelligent threat detection service that monitors:
- AWS account activity
- VPC Flow logs
- CloudTrail events
- Detects:
- Suspicious API calls
- Compromised instances
- Unusual network traffic patterns
- Sends findings to Security Hub or CloudWatch for action.
1ļøā£4ļøā£ Amazon Inspector
-
Automated security assessment service for:
- EC2 instances
- Container images (ECR)
- Lambda functions
- Identifies:
- Vulnerabilities
- Deviations from security best practices
- Unpatched software
1ļøā£5ļøā£ AWS Macie
-
Data security and privacy service using machine learning to:
- Discover and classify sensitive data (like PII)
- Detect unauthorized access or data leaks
- Works primarily with Amazon S3 buckets.
- Helps with compliance requirements (GDPR, HIPAA).
šØ What is Distributed Denial of Service (DDoS)?
A Distributed Denial of Service (DDoS) attack is a malicious attempt to disrupt the normal traffic of a targeted server, service, or network by overwhelming it with a flood of traffic from multiple compromised systems (often part of a botnet).
Unlike a simple DoS attack (from one source), a DDoS attack uses multiple sources to make mitigation more difficult.
ā ļø How a DDoS Attack Works
-
Botnet Creation
- The attacker infects many devices (computers, IoT, servers) with malware, making them "bots" or "zombies."
-
Command & Control (C&C)
- The attacker remotely controls these bots to target a victim's server.
-
Traffic Flooding
- Massive amounts of traffic (requests, packets) are sent simultaneously to the target.
-
Impact on Target
- Server resources get exhausted.
- Legitimate users cannot access the service (denial of service).
š§ Types of DDoS Attacks
1ļøā£ Volume-Based Attacks
- Objective: Exhaust the bandwidth of the target.
- Examples:
-
- UDP Flood
- ICMP Flood
- Spoofed-packet Flood
-
- Measured in bits per second (bps).
2ļøā£ Protocol Attacks
- Objective: Exploit weaknesses in network protocols or server resources.
- Examples:
- SYN Flood
- Ping of Death
- Smurf attack
- Measured in packets per second (pps).
3ļøā£ Application Layer Attacks
- Objective: Target specific application functions (e.g., HTTP requests).
- Examples:
- HTTP GET/POST floods
- Slowloris
- Measured in requests per second (rps).
š”ļø How to Protect Against DDoS Attacks
1ļøā£ AWS-Specific Protections
- AWS Shield (Standard & Advanced): Network-level DDoS protection.
- AWS WAF: Blocks malicious HTTP requests at the application layer.
- Amazon CloudFront: CDN that absorbs and filters traffic.
- Route 53: Provides DNS failover and load balancing.
- Auto Scaling: Automatically adds capacity to handle traffic spikes.
2ļøā£ General Best Practices
- Use rate-limiting and throttling.
- Enable firewalls and intrusion prevention systems.
- Use CDNs to distribute traffic globally.
- Keep software and servers updated.
- Have a DDoS response plan ready.
ā Example of a DDoS Scenario
- A gaming server is targeted by 100,000 infected IoT devices sending 500,000 HTTP requests per second.
- The server slows down or crashes, making the game unavailable for real players.
- AWS Shield Advanced could absorb this traffic before it reaches the server.
ā Summary
AWS offers a multi-layered security approach:
- Encryption: Protects data (KMS, ACM, SSM, Secrets Manager)
- Network Protection: WAF, Shield, Firewall Manager
- Threat Detection: GuardDuty, Inspector, Macie
- Best Practices: DDoS resiliency, secure access policies
š What is SQL Injection?
SQL Injection (SQLi) is a web security vulnerability that allows an attacker to interfere with the queries that an application makes to its database.
This often results in:
- Unauthorized viewing of data
- Data modification or deletion
- Full compromise of the database server
ā ļø How SQL Injection Works
An application fails to properly validate user input and directly incorporates it into an SQL query.
Attackers inject malicious SQL code into an input field to manipulate the query.
Example of Vulnerable Code
String username = request.getParameter("username");
String query = "SELECT * FROM users WHERE username = '" + username + "'";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);
If an attacker enters:
' OR '1'='1
The query becomes:
SELECT * FROM users WHERE username = '' OR '1'='1';
This returns all users, bypassing authentication.
š§ Types of SQL Injection
1ļøā£ Classic SQL Injection ā Injecting malicious code into input fields.
2ļøā£ Blind SQL Injection ā Data is not directly visible, but attackers infer info through responses (true/false).
3ļøā£ Union-Based SQL Injection ā Combining multiple SELECT queries to extract more data.
4ļøā£ Error-Based SQL Injection ā Triggering database errors to reveal schema info.
5ļøā£ Time-Based Blind Injection ā Using WAITFOR
or SLEEP()
to guess query results based on response time.
š How to Prevent SQL Injection
ā 1. Use Prepared Statements (Parameterized Queries)
String sql = "SELECT * FROM users WHERE username = ?";
PreparedStatement ps = connection.prepareStatement(sql);
ps.setString(1, username);
ResultSet rs = ps.executeQuery();
-
Ensures data and SQL commands are separated.
ā 2. Use Stored Procedures
- Encapsulate SQL logic inside database procedures.
ā 3. Input Validation
-
Reject suspicious input containing
'
,;
,--
,/*
, etc.
ā 4. Least Privilege Principle
-
The database user should not have admin rights.
ā 5. Web Application Firewall (WAF)
-
AWS WAF can detect and block common SQL injection patterns.
šØ Real-World Example
- 2019: A SQL injection attack on an Indian airline website exposed personal data of millions of customers.
- Many data breaches worldwide exploit this vulnerability.
ā Summary
Aspect | Details |
---|---|
Vulnerability | User input directly appended to SQL query |
Impact | Data theft, modification, full compromise |
Prevention | Prepared statements, input validation, WAF |