AWS and IP spoofing

0

Hey everyone, I use Cloudflare as my WAF, and host my server on AWS and I was wondering, and I want to only whitelist IPs relating to Cloudflare, but I have a problem... how does AWS handle IP spoofing? what if someone changed their X-Forwarded-For header to one of Cloudflare's IP addresses. how does AWS handle it? does it allow it to enter? is there any documentation how AWS secures this properly?

3 Answers
2

AWS does not directly handle IP spoofing or verify the accuracy of the X-Forwarded-For header. It's important to understand that the X-Forwarded-For header can be manipulated by clients, including malicious actors, and should not be solely relied upon for security measures. However, AWS provides several features and best practices to enhance security:

Security Groups: AWS Security Groups act as a virtual firewall for your EC2 instances to control inbound and outbound traffic. You can restrict access to your instances based on IP addresses, protocols, and ports. Ensure that your Security Groups only allow traffic from trusted sources, such as Cloudflare IP ranges.

Network Access Control Lists (NACLs): NACLs are an additional layer of security that act as a firewall for controlling traffic in and out of one or more subnets. You can use NACLs to deny traffic from suspicious or unauthorized IP addresses.

AWS WAF: AWS Web Application Firewall (WAF) helps protect your web applications from common web exploits. You can create rules to allow, block, or monitor web requests based on conditions that you define. While AWS WAF can be integrated with Cloudflare, it's important to properly configure your WAF rules to mitigate potential threats. Could you check this if this will be useful :- https://aws.amazon.com/it/blogs/security/automatically-block-suspicious-traffic-with-aws-network-firewall-and-amazon-guardduty/

Hope it clarifies and if does I would appreciate answer to be accepted so that community can benefit for clarity, thanks ;)

profile picture
EXPERT
answered 2 months ago
2

As Adeleke mentioned,X-Forwarded-For can be spoofed.

However, X-Forwarded-For does not contain Cloudflare IP, only original visitor IP. As per Cloudflare documentation

For example, if the original visitor IP address is 203.0.113.1 and the request sent to Cloudflare does not contain an X-Forwarded-For header, then Cloudflare will send X-Forwarded-For: 203.0.113.1 to the origin.

To restrict EC2 access to Cloudflare only, you can modify your EC2 SG (security group) HTTP/HTTPS inbound to Cloudflare IP only.

Refer to 3 ways AWS is helping to make the internet more secure note about IP spoofing,

One common technique that DDoS actors use is “IP spoofing”, sending messages as part of an attack while disguising the source to make it hard to stop the activity. Historically, IP spoofing has been a challenge for security teams to deal with because it’s so hard to identify the true source. (Imagine if you simultaneously received a thousand calls on your phone from a thousand different numbers. You would need to trace back step-by-step to find each message’s originating network.) Because AWS runs a large global network footprint, interconnecting with thousands of unique networks, we can directly engage with our peer networks to trace an attack back to the source and shut it down. We work with a variety of network operators to engage in trace-back exercises to shut down the infrastructure used for these kinds of attacks.

AWS
EXPERT
Mike_L
answered 2 months ago
1

As discussed above you can add CloudFlare IP ranges to a security group to restrict access to CloudFlare.

While the HTTP 'X-Forwarded-For' header can be spoofed, if you are able to verify that the requests came from CloudFlare, then you should be able to trust at least the right-most 'X-Forwarded-For' (assuming you have not instructed CloudFlare not to add the true client IP. Don't trust any of the addresses except the rightmost as all of these could have been manipulated upstream.

AWS
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions