# Modified External Notes

## Module 1: Introduction to Bastion Hosts

Bastion Host →  “Jump Box” from the public to the private subnet.

User needs to have access for jump box and the private instance.

Private keys should never be hosted on this server

**SSH Agent forwarding** **- research**

## Module 2: Virtual Private Networks

VPN enables you to route traffic from yourself towards destination through itself.

Something similar to Proxy.

In Corporate environments, VPN is used to connect to instances in Private Subnet.

VPN Server resides in the Public Subnet and you route your traffic via VPN server to instances in Public Subnet.

![vpn (1).png](https://lh4.googleusercontent.com/WUY5DocISzf-7R-akjXVOSD85xwom_DxjlJCj85QiXMOYmCzEUwDLK--qSVM5WfQZeih03_bg4QjkBdGTMEZIfXcpxbdvdB0YrDaE9yYVEJyuFDqXO93V6Oh3kBkFwiPiAn9FX0J)

## Module 3: Site to Site VPN Tunnels

A Site to Site (S2S) VPN allows two networking domains to communicate securely between each other over an untrusted network like the Internet.

The two sites can be AWS and on-premise data-center or even two different VPC’s

CGW is just a termination point, FW, Router, whatever

![](https://lh4.googleusercontent.com/cHVw_G4dOgMDRy0GU3ra8nn2EXF5-J_u506o4endwuNmNd6GrpPx6L8zxP1YZW_uV27FmGp0hSzU3fasCMu2EK9mR5jvEV0ZDy72iZc6II9U4T3YzxYpg4sk3PMc2a4oHHY8qbHU)

A Virtual Private Gateway (VGW) has built-in high-availability for VPN connection.

AWS automatically creates 2 HA endpoints, each in a different AZ. HA managed by AWS.

![](https://lh6.googleusercontent.com/Oo0QDKwBYM1OlV8w0joZNCNKGqKT8NaYcMRCGut2bf9MvOFA8-BA_-XR-duG_ivl_EPoqP-HhOzTlX7z242BakGsPB_IVwL9PgQ_5wuIg3xRYzi_u6eLYy6aY47rdaYDrG8d1tAm)

### Must add routing in the route table to be able to reach on prem!!

## Module 4: VPC Peering

VPC peering is a network connection between two VPC that enables the communication between instances of both the VPC.

VPC Peering is now possible between regions.

![](https://lh6.googleusercontent.com/oBA9yKXbElJKhRMwLAXgLGknxMwg1KmxtJlBRSJHT_2W_cbGLX9EqviEPSM6LCLKSNeN_Z3udvSoPASbgQAffg_fPKQJZ5TYOtI9j9kl6SJKvOFQbMIBRDC4MEBEajnTuVgHVqd3)

Unsupported VPC Peering Configurations - 1

You cannot create a VPC peering connection between VPCs with matching or overlapping IPv4 CIDR blocks.

![](https://lh4.googleusercontent.com/qXsCrc1-KvDm7D3IT9F84OpdcI1_U57ORppGXnSjdgJ9dMp8-96pwnVdpckkb93AUglWIQFsgAX2kDNkhCgtxYtsPN1wiACLLGw-dhHZ-L-X_A1rFXgpcWo8h8oagXJtNVrzKvfs)

Unsupported VPC Peering Configurations - 2

You have a VPC peering connection between VPC A and VPC B (pcx-aaaabbbb), and between VPC A and VPC C (pcx-aaaacccc).

There is no VPC peering connection between VPC B and VPC C. You cannot route packets directly from VPC B to VPC C through VPC A.

![](https://lh4.googleusercontent.com/IXOaWCTbcUUfnvKml1zrr61-qiLHRH6EcZI-LwJRThjiaR0XJnZEubhhS_-pzeJFe1BjzOlaKILFnpOLayhtRiCyzSWBpDSW-CDA46UWLG8EECkcq-RJBRyj8OGlou85Zr8DT2n9)

## Module 5: VPC Endpoints

Earlier for EC2 instances to be able to access public resources like S3, the traffic needed to be pass via Internet Gateway or even via NAT.

Simplifying this approach, AWS introduced a feature called “VPC Endpoints” are secure and highly reliable connection that provides a secure connection to services like S3.

This EC2 instance within private VPC can now connect to such services without any need of NAT gateway or even Private Gateways.

![](https://lh5.googleusercontent.com/sTDrDvC1TEEMhlaIFokO7jvRGumg8fxD3ospT3ug1CU_HwcUfQlNmlvMigBo0bP3Qpr7VSxOANCvZUfxDsE6iM-WVMZYlwpBwu6m3DtGCLRSxG51zzIx5IEKiEm1Ynlmu0Q1jvm5)

EC2 to DynamoDB Communication via VPC Endpoint

![](https://lh4.googleusercontent.com/xHIg-Az5LMnihldX_WpbGWQzc8L3L4bvksezdSpULKxmxHjUoH8Brph1qNeRuYAFwpuw_uumciIskGOccpfcIHlHUbG7Yd1YzeX8VRgBxF3Rf5-v4rjiNhSgpy3jRHb8HSzg2N5Y)

Gateway VPC Endpoints

In the Gateway endpoints approach, the VPC endpoint was created outside your VPC and traffic was routed via route table.

Thus, it was not possible to use it directly from VPN’s or Direct connects.

Access policy was controlled through IAM like the JSON document,

![](https://lh6.googleusercontent.com/VoSTCGU0orxyC0FobW8mtIW8DGqHPXqPSvNEKltiHZt_DXiAklgGWAe59PcLFuKx4hEw2Hq0uiher2SaheIXqm0XahmP0h5syUOVFZD3vP7iB4K52FFpSyE96yeFrzWPMrBmpXOR)

VPC Endpoints are not accessible via VPN or DX cause it needs EC2 route table

AWS S3 endpoint **ls** will show ALL worldwide buckets, without specifying region

But actually **lsing** the inside of a bucket in another region will not work

**Interface VPC Endpoint**

* Interface VPC Endpoints are next-generation VPC endpoints.
* VPC endpoints are created inside your VPC.
* They have an ENI and Private IP associated.
* Access control through security groups.

![](https://lh4.googleusercontent.com/5qnjsVjeI6qS8zTIJXr5HT-YpBBeAUSguAUR3ukIDzwvqCLcB7S67HG4o72yXkZdO6uIGrtt3gr9wV5L2VhIWhhZLOCUwfEs5PSF0H1_5St9B4Ppddm1ZpACqcc0p52Dcfk_zBQ2)

### Gateway Endpoints are only S3 and DDB

## Module 6: Network ACL

* Network ACL are stateless in nature.
* They operate at the subnet level instead of instance-level like Security Groups.
* All subnets in VPC must be associated with NACL.
* By default, Network ACL contains full allow in INBOUND and OUTBOUND.
* Can block one IP via ACL unlike SG which can't!! For specific attacks etc
* Can be associated with subnets
* Lower the rule number, the higher the priority it has! (100, 200, 205, etc)
* Matches the first rule applicable, after is ignored
* If you create a custom NACL the default is all DENY, as opposed to default NACL which is ALLOW

![](https://lh5.googleusercontent.com/VzA9nITFzPajOPexIE2CKWDC2ifMQCdYlx9ZLiiS1Gws_tO9x5rk6f9pAUeYTVa4NmOt7hbcTrRlhY03XDSvKj3k3USPDFEn5t5mPVCnng-GZNiyIfScZOnZWjs86t1eqOtHvmYN)

## Firewalls

* Client that initiates request chooses the ephemeral return port
* 0-1023 = Well Known or Reserved
* Range varies on OS
  * Many Linux use 32768-61000
  * Request originating from ELB uses 1024-65535
  * Windows XP uses 1025-5000

## Module 7: IPTABLES and Instance Meta Data

Instance Meta-Data can provide a lot of sensitive information that includes temporary credentials like AWS Access Key / Secret Key and Session Token

To view all categories of instance metadata from within a running instance, use the following URI.

<http://169.254.169.254/latest/meta-data/>

Any user who has access to the server will be able to fetch that information. This can lead to a security risk.

With IPTABLES, you can block access to the instance meta-data for the common users within servers.

iptables -A OUTPUT -m owner ! --uid-owner root -d 169.254.169.254 -j DROP

## Module 8: IDS/IPS

Firewall:-

It keeps everyone out who tries to sneak in via basement windows, backside doors, etc BUT if someone enters through the official door, the entry is given.

IDS / IPS:-

It can search the people to check if they are carrying weapons with them.

Have your private key on IDS so it can inspect encrypted traffic

!\[Screen Shot 2020-10-11 at 9.38.50 AM.png]\(../../../../\_resources/Screen Shot 2020-10-11 at 9.38.50 AM.png)

The architecture of IDS/IPS in AWS:

![ids\_and\_ips.png](https://lh6.googleusercontent.com/ZZpVh9_V4CSnB_WDZiYE1y1iqn-PFfH-5_lKH_fXJSUXLPK_TB4_YV8BSvDpx-ihFStfYF1p6heflL7mTvGdeEjMp3WJhzgVq1sFqNiizcuxQDsIh-GTyNmCBVV0eUpbyKxaqOuR)

You have an IDS / IPS  agents installed in the EC2 instance which will communicate to the central IDS / IPS appliance.

## Module 9: EBS Security

* **Use EBS Encryption for in-flight to disks themselves, and at rest**

i) Before terminating an instance, customers can wipe the data in EBS.

ii) AWS also wipes the data immediately before the EBS is made for re-use.

iii) When the storage device has reached its end of use, they are decommissioned via detailed steps mentioned in NIST 800-88 or DoD 5220.22-M

## Module 10: CloudFront Origin Access Identity

CloudFront Origin Access Identity allows users to only access the contents of an S3 bucket via the CloudFront distribution.

When OAI is enabled, CloudFront will add a bucket policy to the S3 bucket which will allow access only via the CloudFront distribution.

![](https://lh6.googleusercontent.com/-nF3vU_aHoDpmWoidzy29cPLcs9Nwi8zsNcDJQN5sClJcSKOKowTQz00G2SjYWqUZ9YMKuDdxAfWWUr50fYmsS5l2R0a-_JD1LrxVWg3Qa9p7-nuSXszXORL7xRxJtw_s8q7FVd7)

## SNI in TLS

**Research, STUDY**

* Multiple websites running in same server (IP), each needs own cert
* Now client sends server name it wants (wireshark)
  * Client Hello
  * Extension: server\_name
* Prior to SNI a website needed to have a dedicated IP address in order to have a SSL certificate installed
* With SNI multiple websites can share a single UP each with their own cert
* Some legacy clients do not support SNI, breaks sites
*

## Module 11: CloudFront Signed URLs

CloudFront Signed URLs mandates users to provide signed URLs or signed cookies to access the private content.

CloudFront signed URLs can be generated by the trusted signers assigned in your AWS account, in CloudFront distribution creation. With a special access key pair (ID and .pem), generated in root account in CloudFront Keypairs in My Account

![](https://lh5.googleusercontent.com/1ao7ug-DTMx9nYItWgAP4g79z477xJ-kuXulzvNpSeCRQTTuj2NZgEPLJ0lUbo0PSZEc2v5vVq8DvqGM9QJx8WRuXjmxj8DjmhDuuC5RAQJ9wH3Uln4zQOiwXE-UjNL1_U0rrjEX)

## Module 12: AWS Shield

AWS Shield is a managed Distributed Denial of Service (DDoS) service that safeguards the workloads running on AWS against DDoS attacks.

There are two tiers of AWS Shield:

* Shield Standard
* Shield Advanced

AWS Shield standard provides basic level protection against most common network and transport layer DDoS attacks.

For a higher level of protection, we can subscribe to the Shield Advanced. Shield Advanced protects against large and sophisticated DDoS attacks with near-real-time visibility into the attacks that might be occurring.

AWS Shield Advanced also gives customers 24x7 access to the AWS DDoS Response Team (DRT) during ongoing attacks.

12.1 AWS Shield Costs and Credits

AWS Shield Advanced costs 3000$ per organization and requires Business or Enterprise Support. Reimburses ELB, CloudFront, Cloudfront

One interesting part about AWS Shield Advanced is that during the attack, if your infrastructure has scaled, AWS will return you the amount that occurred during scaling in the form of credits. This is also referred to as Cost protection.

![](https://lh4.googleusercontent.com/NpGFbNt2u7T5eyzb8DnnkD5ztdDiHLcWApLm5o4OZLIAIhhyQSOXtmHmBieezQbiNxtgdqA8w7749TEYAscqua3cfNPJ0aSut3Eb-WbZwRknULBL0abBRYQtzD2nodwNGkH34eJB)

## Module 13: Mitigating DDoS

There are four major pointers that need to be remembered

1. Be ready to scale as traffic surges.
2. Minimize the attack surface area.
3. Know what is normal and abnormal.
4. Create a Plan for Attacks.
5. Be Ready to Scale

Your infrastructure should be designed to scale when the traffic increases.

It not only helps in Business but also during DDOS Attacks.

Example :

Whenever CPU load is more than 70% in Application servers, automatically add one more Application server to meet the needs.

AWS Services: ELB, Auto Scaling

2\. Minimize the attack surface area.

Decouple your infrastructure.

Example :

Application and Database should not be on the same server.

AWS Services:  SQS, Elastic BeanStalk

3\. Know what is normal and abnormal

Key metrics need to be defined to understand the behavior.

Example :

Website getting a huge surge in traffic in the middle of the night at 3 AM

AWS Services:-  CloudWatch, SNS.

4\. Create a Plan for Attacks.

For example :

* Check whether the Source IP Address is the same.
* Check from which country the increased traffic is coming from.
* Nature of the attack ( SYN Flood, Application Level )
* Can it be blocked with NACL or Security Group level

It is recommended to have AWS Support. At-least Business Support.

AWS Services for DDoS Mitigation:

Following are some of the key AWS services involved in DDoS attack mitigation

* AWS Shield
* Amazon CloudFront
* Amazon Route53
* AWS WAF
* Elastic Load Balancing
* VPC & Security Groups

## API

!\[Screen Shot 2020-10-17 at 1.30.07 PM.png]\(../../../../\_resources/Screen Shot 2020-10-17 at 1.30.07 PM.png)

You can enable API caching in Amazon API Gateway to cache your endpoint's responses. With caching, you can reduce the number of calls made to your endpoint and also improve the latency of requests to your API.

When you enable caching for a stage, API Gateway caches responses from your endpoint for a specified time-to-live (TTL) period, in seconds. API Gateway then responds to the request by looking up the endpoint response from the cache instead of making a request to your endpoint. The default TTL value for API caching is 300 seconds.

## Module 14: EC2 Key Pair Troubleshooting

Whenever we create an EC2 instance, we generally specify the associated key-pair

There is two specific troubleshooting scenario that we should be aware of:

i) Deleting the key-pair from the console will not delete the associated key from the EC2 instance.

![](https://lh4.googleusercontent.com/5w_EdPqcs05dOEeVOqRr72a-IMMbgIk9XLWXh7ccEbVCWEdGxurcB48WyUAOF_J3M3JUxNWPC4eJG-Ae2cD65ZotmPTVQ2dYBSVki-x8Pqeib8DnMkBcg2GooIzVWcdAmmx0Gogy)

ii) If we create a new instance from AMI of older instance, the public key specified while AMI creation will be appended to the authorized\_keys. **Good way to keep same istance if you lose the original keypair!**

![](https://lh6.googleusercontent.com/pqmYCTOzAc3MlidwqR4iEJca4cqIZn8QnkOIbEfJ8_qewMytjjeDHgp0daQEUGdzorKeg0IqqsOdeZX0ixEDURSKwzQUid_gck5z73_9-xr8VoMsiPQarXEqqjptrEUoCGEuSBDF)

## Module 15: EC2 Tenancy Attribute

Every EC2 instance that we launch in the VPC has a specific tenancy attribute associated with it. There are three tenancy attributes which are available:

![](https://lh4.googleusercontent.com/t3xHG19DThF2l0mTeAcBflN_WVOx4s4Cdh88UOLtxR9AxEf1fLDllIXiluI2WecOgq1OvGX8naubIpj6ZH_fuMn-eet_HpTBWC1wTTr-OdIcEXHSWBlQ23zIGT-J8-Qly-YdCZoc)

i) Shared Tenancy

In this approach, your EC2 instance is launched on the shared hardware where EC2 instances of other customers also run.

![](https://lh6.googleusercontent.com/toJ2wZSpDwWjQPokQRL90WN5dXSxPjlKfM-5imSltYXAaomT9Gduf0ahoCItHq2UELxV6scF6mg4mISs922Jh9l-08VQBZK6cWBLsQfBQ4fmfMv0Gmhbvp_XNa84GrUINbbR_U1m)

ii) Dedicated Instance

Dedicated Instances are EC2 instances that run on the hardware which is dedicated to a single customer.

Dedicated instances may share the hardware with other EC2 instances that belong to the same AWS accounts.

![](https://lh5.googleusercontent.com/hrZNNucXy4UMZtDoBi2FFVuH8LC2C0dFXxnEqJQQpMX7D6obFBK6M7SlNc97rPyzRjJ9D7DEQVvUZonVZSCnS-0xzCWrPKwuZ3iwQ0wyOENUNd-LmFTUOxBT5gEk_BWI_4yLjQVA)

iii) Dedicated Hosts

Dedicated Host is a physical server that allows us to use our existing per-socket, per-core or even per-VM based software licenses which includes Windows Server, SUSE, and various others.

With dedicated hosts, we can use the same physical server over time, even if the instance is stopped and started.

## Module 16: AWS Artifact

The AWS Artifact portal provides on-demand access to AWS' security and compliance documents, also known as audit artifacts.

Lots of AWS services are compliant against various compliance like PCI DSS, HIPAA and others.

If the organization is using certain AWS services, then the auditor will ask the organization to show a certificate that the service is compliant.

## Module 17: Lambda\@Edge

Lambda\@Edge lets you run Lambda functions to customize content that CloudFront delivers.

You can use Lambda functions to change CloudFront requests and responses at the following points:

* After CloudFront receives a request from a viewer (viewer request)
  * Executed on every request before CloudFront cache is checked
  * ex: Modify urls, cookie query strings, perform authentication and auth checks
* Before CloudFront forwards the request to the origin (origin request)
  * Executed on a cache miss, before forward to origin
  * ex: dynamically select origin basedo n request headers
* After CloudFront receives the response from the origin (origin response)
  * Executed on a cache miss, after a response is received from origin
  * ex: modify response headers, intercept and replace 4xx and 5xx errors from the origin
* Before CloudFront forwards the response to the viewer (viewer response)
  * Executed on all the responses received from either the origin or the cache
  * ex: modify the response headers before caching of response happens, so it doesn't get cached

![](https://lh3.googleusercontent.com/XLbQXXfXpxtU_BX_At1KGnWiO7Qdpl0l5J48VQlLVMy-pc1iomP7WSlyd73kxHEq1dvTTjYK-RT2X2Qofyn6ZVN19TagBbLsSJ7Uv3vW5QW6vJzBpSBt2z89fwdHXrWCx0pGX9R-)

## Module 18: AWS SES

AWS SES is a highly scalable platform that AWS offers for sending and receiving emails.

Many organization has generic emails like <noreply@example.com> which is used to send emails to users upon registration or others.

We need a mail server for that. This can be installed in EC2 instance as well, however by default AWS will throttle email traffic over port 25.

To remove the throttle, we can make use of non-default ports or fill out the form to remove email sending limitations.

To access the AWS SES interface, we need to have an SES SMTP username and password.

SMTP works on port number 25, 465 or 587.

SMTP credentials should be used when we connect to the AWS SES SMTP endpoint.

![](https://lh5.googleusercontent.com/wYMlnnBCmjQNdzGBYUJn9Y9Xf8SEHwT5rOcA-aADRC95--ORrzzIZZxPvOTIiDbuwf8dydMTNtKu_QuGM-EY0q7gxLEB3q3oMIuMvsazOCAWodq6LNrYwU2qIoNvUfcoFUdo1esY)

## Module 19: DNS Support in VPC

There are two important attributes in VPC that determines DNS related aspects;

![](https://lh3.googleusercontent.com/JnOS6gaKsVRcoEeTUVS4ZH77BDOI22uzE8BdLrir1uz9Ml4MkMRrgmEGVsQN8UlIIWlbtrahhkOuXmZprlHkzfClKdnnlvamurFOKQfP7nwX6B30DUcM5-Ql4Adb2_fMG6HfEVgy)

Two cases to understand it in a better way:

If both attributes are set to TRUE, the following occurs:

Instances with a public IP address receive corresponding public DNS hostnames.

The Amazon-provided DNS server can resolve Amazon-provided private DNS hostnames.

If both attributes are set to FALSE, the following occurs:

Instances with a public IP address do not receive corresponding public DNS hostnames.

The Amazon-provided DNS server cannot resolve Amazon-provided private DNS hostnames.
