4.3.29 · HinglishComputer Networks

Firewalls — stateless vs stateful packet filtering

2,226 words10 min readRead in English

4.3.29 · Coding › Computer Networks


Firewalls exist kyun karte hain?

Header fields jo ek filter typically padhta hai:

Layer Field Example use
IP (L3) Source / Dest IP ek bad subnet block karo
IP (L3) Protocol (TCP/UDP/ICMP) sirf TCP allow karo
TCP/UDP (L4) Source / Dest port dst 443 (HTTPS) allow karo
TCP (L4) Flags (SYN, ACK, FIN, RST) connection starts spot karo

Difference kya hai? Stateless vs Stateful

Figure — Firewalls — stateless vs stateful packet filtering

Stateless filter return traffic handle kaise karta hai? (mushkil wala part)

Classic stateless trick: inbound TCP packets sirf tab allow karo jab unka ACK bit set ho.

Example stateless ruleset (internal hosts ko web servers tak jaane do, nayi inbound connections block karo):

# Dir Proto Src Dst Dst Port Flag Action
1 out TCP 10.0.0.0/24 any 80,443 ALLOW
2 in TCP any 10.0.0.0/24 >1023 ACK=1 ALLOW
3 * * any any any DENY

Stateful filter kaise kaam karta hai? (step by step)


Worked examples


Trade-offs summary

Aspect Stateless Stateful
Connections ki memory None Connection/state table
Return traffic flag tricks (ACK) table ke through automatic
Spoofed packets ke against security weak strong
Memory / CPU cost bahut kam zyada (per-flow state)
Speed per packet constant, simple established par fast, table lookup
DoS via state exhaustion vulnerable nahi vulnerable (SYN flood table fill karta hai)
Dynamic protocols (FTP/SIP) poor good (ALGs)

Recall Feynman: ek 12-saal ke bacche ko explain karo

Ek party mein doorman imagine karo. Ek bhulakkad doorman (stateless) har baar har aadmi ka ticket check karta hai lekin kisi ko yaad nahi rakhta — toh ek chalaak baccha jo kehta hai "main pehle hi andar aaya tha, main sirf wapas ja raha hoon" usse fool kar sakta hai agar usne sahi badge pehna ho. Ek samajhdar doorman (stateful) ek guest list rakhta hai jinhe usne andar aane diya tha. Jab koi wapas andar aana chahta hai, woh list check karta hai. Agar aapka naam wahan nahi hai, aap andar nahi ja sakte — chahe koi bhi badge wave karo. Samajhdar doorman safe hai, lekin agar ek badi bheed fake names lekar aati hai, uski notebook bhar jaati hai aur woh overwhelm ho jaata hai.


Active recall

Firewall state table mein ek single connection ko kya identify karta hai?
5-tuple: srcIP, dstIP, srcPort, dstPort, protocol
Stateless aur stateful filtering mein key difference kya hai?
Stateless har packet ko akele judge karta hai bina memory ke; stateful ek connection state table maintain karta hai aur check karta hai ki packet kisi approved connection se belong karta hai ya nahi.
Stateless filter return traffic allow karne ke liye kaunsi header trick use karta hai?
Inbound TCP sirf tab allow karo jab ACK bit set ho (ACK=1), kyunki nayi connections SYN se start hoti hain (ACK=0).
ACK trick insecure kyun hai?
Ek attacker ACK=1 wala packet forge kar sakta hai jo kisi real connection se belong nahi karta; stateless use andar aane deta hai, stateful drop kar deta hai (koi matching table entry nahi).
Nayi TCP connection ka pehla packet distinguish karne wala flag kaunsa hai?
SYN with ACK=0.
Jab stateful firewall mein outbound SYN allow hota hai toh kya hota hai?
Yeh ek state-table entry create karta hai (5-tuple, state SYN_SENT) taaki reply automatically permit ho jaaye.
Kaunsa attack specifically stateful firewalls ko exploit karta hai lekin stateless ko nahi?
SYN flood / state-table exhaustion — bahut saari half-open connections finite state table fill kar deti hain (DoS).
Active-mode FTP ko stateful firewall kyun chahiye?
Yeh dynamically negotiated port par ek doosri data connection open karta hai; ek ALG control channel padhta hai aur exactly woh port temporarily open karta hai.
Achhe se configure kiye firewall ki default policy kya hoti hai?
Deny-by-default: jo explicitly allowed nahi hai woh sab drop karo.
State entry kab remove hoti hai?
TCP FIN/RST teardown par ya idle timeout ke baad.

Connections

  • TCP Three-Way Handshake — SYN/SYN-ACK/ACK hi wajah hai ki ACK trick aur state tracking kaam karti hai.
  • TCP Flags (SYN ACK FIN RST) — wo bits jo ek filter padhta hai.
  • Network Address Translation (NAT) — yeh bhi ek per-flow table maintain karta hai, conceptually stateful.
  • Access Control Lists (ACLs) — router ACLs classic stateless implementation hain.
  • Denial of Service Attacks — SYN flood vs state exhaustion.
  • OSI Model — Layers 3 and 4 — kaun se headers kahan rehte hain.
  • Application Layer Gateways / Proxies — headers se pare deeper inspection.

Concept Map

enforces via

default is

reduces

implemented as

implemented as

judges each packet, no memory

solved leakily by

remembers using

one row per

checks membership of

cleanly handles

Firewall = security guard

Packet filtering on headers

Deny-by-default policy

Stateless filter

Stateful filter

5-tuple fingerprint

Connection state table

ACK-bit trick

Return traffic problem

Reduced attack surface