Skip to content

Domain and Port Filtering with Network Firewall

0

Hi, I want to set up a rule/policy on Network Firewall that allows communication only for: domain1 on ports 5671 and 5672 domain2 on port 443 domain3 on port 587

Using Suricata rules I've defined this, however if I add a drop rule to the end of the allow rules (in order to block all other traffic), everything gets blocked, even the explicitly allowed. The only way I've found is to open particular ports explicitly with Suricata but I can find no way to restrict it to the domains I want. Otherwise, simply adding the drop rule at the end blocks all traffic. I've also changed it to pass tcp instead of pass tls but it's the same. I have already restricted DNS resolution using DNS firewall so that part is covered.

These are my rules below:

Allow

pass tls $HOME_NET any -> any 5671-5672 (msg:"Allow domain1.com"; tls.sni; content:"domain1.com"; nocase; flow:to_server; sid:1001; rev:1;) pass tls $HOME_NET any -> any 443 (msg:"Allow domain2.com"; tls.sni; content:"domain2.com"; nocase; flow:to_server; sid:1002; rev:1;) pass tls $HOME_NET any -> any 587 (msg:"Allow domain2.com"; tls.sni; content:"domain2.com"; nocase; flow:to_server; sid:1003; rev:1;)

Allow RDP from trusted IP

pass tcp 1.1.1.1 any -> $HOME_NET 3389 (msg:"Allow RDP"; flow:to_server; sid:1004; rev:1;)

Block all other outbound

drop ip $HOME_NET any -> $EXTERNAL_NET any (msg:"Block unauthorized"; flow:to_server; sid:1100; rev:1;)

Any help is mightily appreciated

4 Answers
4

Seems your drop rule wins your allow rules and cause the unexpected result, please use alert instead for your debug:

alert ip $HOME_NET any -> $EXTERNAL_NET any (msg:"Debug unauthorized traffic"; flow:to_server; sid:1100; rev:1;)

More specify on outbound unwanted traffic like below:

drop ip $HOME_NET any -> !$ALLOWED_DOMAINS any (msg:"Block unauthorized"; flow:to_server; sid:1100; rev:1;)
EXPERT

answered a year ago

EXPERT

reviewed a year ago

1

Making a few assumptions here (i.e. that your firewall configuration is set to use "strict rule ordering") - The issue is that once you add in that drop rule, you don't have anything in your rule configuration that will allow the TCP handshake to complete. I'd take a look at the sample rule set in the best practise guide below to get an idea of how to build this out: https://aws.github.io/aws-security-services-best-practices/guides/network-firewall/

AWS

answered a year ago

EXPERT

reviewed a year ago

0

IP protocol is evaluated first because it's a low level protocol ( compared to TCP and TLS ). Therefore, regardless of the configured "Strict Order," IP drop rule will be evaluated first.

Looking on DOC previously shared ( https://aws.github.io/aws-security-services-best-practices/guides/network-firewall/ ) you have lots of rules examples. I validated the following rules in my lab ( with google domain ) and they worked:

pass tls $HOME_NET any -> any 443 (msg:"Allow google.com"; tls.sni; content:"google.com"; nocase; flow:to_server; sid:1002; rev:1;)

reject tls $HOME_NET any -> any any (msg:"Default Egress HTTPS Reject"; ssl_state:client_hello; flowbits:set,blocked; flow:to_server; sid:999991;) alert tls $HOME_NET any -> any any (msg:"X25519Kyber768"; flowbits:isnotset,blocked; flowbits:set,X25519Kyber768; noalert; flow:to_server; sid:999993;)

reject http $HOME_NET any -> any any (msg:"Default Egress HTTP Reject"; flowbits:set,blocked; flow:to_server; sid:999992;) reject tcp $HOME_NET any -> any any (msg:"Default Egress TCP Reject"; app-layer-protocol:!tls; flowbits:isnotset,blocked; flowbits:isnotset,X25519Kyber768; flow:to_server; sid:999994;) drop udp $HOME_NET any -> any any (msg:"Default Egress UDP Drop"; flow:to_server; sid:999995;) drop icmp $HOME_NET any -> any any (msg:"Default Egress ICMP Drop"; flow:to_server; sid:999996;)

drop ip $HOME_NET any -> any any (msg:"Default Egress IP Drop"; ip_proto:!TCP; ip_proto:!UDP; ip_proto:!ICMP; flow:to_server; sid:999997;)

Note that TCP protocol evaluation comes before TLS protocol evaluation. This is why I added "app-layer-protocol:!tls" to the TCP Reject Rule.

AWS

answered a year ago

0

Strong assumption that you're not experiencing asymmetric routing - that would be a drop to the traffic! Routing must perform symmetrically.

I'd be curious to see what your default rules are. You have the flow:to_server option in all of the rules, which allows suricata to evaluate all rules at essentially the same level until the communication flow is setup.

I like the above approach where an alert rule is put in first to examine the logs - see where the rule is being triggered, but again - you have the flow:to_server (I like to add the ;established).

If your policy is strict order - great! If it's "action order," not good and need to re-configure that. The default rule should be "drop established" vs "drop all." '

One thing to try - un-associate your R53 resolver DNS fw rules first, then try the traffic again, I've had conflicting issues there where I'm blocking all DNS resolution as well. I think this is a simple troubleshooting exercise.

Look at your FW policy action order vs strict order? Default rule at the end, drop established vs drop all? DNS fw?

Take a look at those things, see what you find. I'll follow this post and receive the updates. Thanks!

AWS

answered a year 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.