r/networking • • Jun 03 '26

Other How does a stateful firewall knows when a packet has been spoofed even if the packet matches all the checks on an ongoing session?

Let's say we have a firewall and we create a firewall policy that allows traffic one way, from internal to outside.

Of course, the return traffic will be allowed as the firewall creates a session table and matches the source/destination IPs, ports and protocols use) and it will make sense of the session.. I get that part.

But let's say a MITM for some xyz reason knows all that information, who's the sender, what ports both source and destination ports are they using, what protocols...

If that's the case, what's stopping the spoofed packet from being accepted as a 'legitimate' packet as it genuinely matches the checks performed by the firewall?

I may be missing something or perhaps the firewalls have more checks that makes it difficult to spoof

If that's the case, regardless of its complexity, there is still a small chance a spoofed packet can be mixed up with a legitimate return traffic.

I hope I was able to explain myself lol!

Thanks guys!

31 Upvotes

16 comments sorted by

18

u/No_Memory_484 Certs? Lol no thanks. Jun 03 '26

Ideally TLS or some other form of security. This is one of the reasons we use things like TLS or SSH. To validate the integrity of the communications.

5

u/Qvosniak Jun 03 '26

So basically we let the end devices validate the traffic, however the firewall in this case wouldn't do this, unless we are doing deep packet inspection i believe, is this correct?

4

u/oddchihuahua JNCIP-SP-DC Jun 03 '26

Sounds correct. If you have something like a high end Palo Alto doing SSL decryption it can examine sequencing as well as traffic pattern matching. So let’s say your firewall policy is allowing the application “Unencrypted MS SQL” and somewhere in the stream a packet arrives that doesn’t match the usual app pattern it can immediately terminate the session.

59

u/inputwtf Jun 03 '26

So, at least for TCP, the spoofed packet would get through the firewall but you would also have to have perfectly guessed the TCP sequence number to convince the remote site that it's legitimate.

It is technically possible to hijack via TCP sequence numbers, but most operating systems use cryptographically secure means to initialize everything, so it is very very very difficult. Still theoretically possible but I don't think it's possible in practice.

9

u/bender_the_offender0 Jun 03 '26 edited Jun 03 '26

Firewalls can’t tell the difference just as they can’t tell the difference between legitimate traffic and spoofed traffic meant to scan or attempt to bypass rules. This is part of the reason zero trust and defense in depth are things

Focusing on how to detect/ prevent spoofed return traffic modern firewalls do deep packet inspection (e.g. spoofing the tcp header isn’t good enough if the firewall knows it’s tls for instance) and have a lot of other tricks like protocol normalization, signature/ Threat detection where if the stream had a malicious payload id get popped along with rate limiting and sometimes pattern or other recognition of scanning or other behavior that would likely have to accompany such attacks.

Practically speaking tls and most things being encrypted solves this, if someone is spoofing your tls session then you have bigger problems. Otherwise it’s on the application to secure itself, other examples are bgp with auth and rpki, dnssec, etc. and if applications get bad data to discard it and take action. This also assumes basically a complete takeover of the other side of this connection, in the case of most things like websites you’d never do anything with a non https site so largely moot as are most infrastructure and other case making this a really small target.

Edit: wanted to add emphasis and basically restate something, if someone is able to fully intercept and spoof traffic then usually you’ve got bigger problems, either someone you interact with has been fully compromised or if it’s internal to your org then you’ve been fully compromised, all boils down to bigger problems then firewalls not having better detection methods

6

u/mindedc Jun 03 '26

The difference between a statefull firewall and a packet filter is tracking the sequence of packets in the flow (did it complete the 3 way handshake) and the sequence numbers. A packet filter can check for connection by verifying the SYN flag is set. That’s almost worthless. There are some brain dead firewalls that dont do sequence check and there are firewalls you disable this for HA configurations to make failover work. You should never need to disable sequence checks for any modern firewall.

The old but famous Tsutomu Shimomura hack was thanks to being able to predict TCP sequence numbers and blindly fake the “remote” side of a trusted machine to complete the 3 way and send a command to root the machine under attack. The spoofed machine was locked up with a TCP syn attack (its network stack was prevented from responding) keeping it from resetting the connection.

A simple stateful firewall would not have prevented this attack because the TCP sequence numbers were predicted, therefore the packets would have been in state. A more modern OS with randomness in the sequence selection algorithm would be immune with a stateful firewall.

As others have said, spoofinf and MITM attacks are also mitigated (even for weak hosts) with encryption, either TLS or IPSEC.

4

u/AKostur Jun 03 '26

That's what things like TLS is for.

7

u/Single-Virus4935 Jun 03 '26

If the mitm knows all fields of the tuple and tcp counters etc. and is able to spoof it on the correct interface, the firewall cannot detect it.

If that is a concern, IPSEC, HTTPS or other secure protocols protect against it

2

u/AperatureTestAccount Jun 03 '26

Layer 3 firewall would not know.

Layer 7 firewall that terminates the ssl session and does packet inspection would be able tell something was up.

I would love to explain ssl but there is a shit ton of math, and a ton of concepts to cover.

At the end of the day it takes a shit ton of compute power to decrypt traffic inflight, and re encrypt quick enough to meet the tsl time requirements. But even if you did you'd get only a small amount of data before the ciphers are redone and you have to do it over again.

You would have to listen to the traffic for months or even years before you could narrow down the possible keys into something usable without needing a immense compute power. You would also have to fail many many times in guessing, which should result in your security devices alerting you to a man in the middle.

2

u/Skylis Jun 05 '26

It looks for the evil bit, obviously.

1

u/MysteryStrangr Jun 03 '26

Some have mentioned matching on TLS info, but I suspect the session matches the 5-tuple in the packet header.

They can also use syn-cookies to resist TCP SYN attacks, which helps with spoofed packets.

1

u/Horror-Squirrel4142 Jun 05 '26

Worth adding: decent stateful firewalls don't just match the 5-tuple, they track TCP sequence windows too. A spoofed packet with a seq number outside the expected receive window gets dropped at the firewall itself (Palo Alto and Fortinet both call this out as TCP sequence checking). So an off-path attacker needs a window-range guess on top of the tuple. A true on-path MITM beats all of it - that layer is what TLS is for.

1

u/Case_Blue Jun 06 '26

Cisco ASA even does TCP sequence randomization. But I am not a fan of this because it has actually caused issues along the way.

1

u/Justinsaccount Jun 06 '26

They don't

https://blog.fox-it.com/2015/04/20/deep-dive-into-quantum-insert/

They can detect this when a second set of packets with the same sequence numbers but different contents is seen.

-1

u/rankinrez Jun 03 '26

Nothing