PacketGuard Logo PacketGuard • Academic Report
πŸ“½οΈ Presentation Slides πŸ–₯️ Live Simulation
Computer Networks • Mini Project Technical Report

PacketGuard: Multi-Client Stateful Packet-Filtering Firewall & Real-Time Security Engine

Layer 3/4 5-Tuple Inspection, Stateful Connection Tracking, and Layer 7 Domain Deflection

Course: Computer Networks (CN) Academic Year: 2026 Status: Validated (21/21 Tests Passed)
Abstract

PacketGuard is a comprehensive stateful packet-filtering firewall and real-time security engine designed to protect enterprise networks through multi-layered protocol inspection, connection state tracking, and domain-based access control. This project implements a production-grade firewall system capable of simultaneously serving multiple administrative, developer, and untrusted client tiers while enforcing granular security policies across OSI Layers 3, 4, and 7. The system demonstrates advanced network security principles including stateful connection tracking (SYN, ESTABLISHED, FIN states), live website interception, domain filtering with demonstrable blocking capabilities (e.g. intercepting google.com vs allowing example.com), and real-time threat response. Implemented in a unified high-performance event loop with 21 automated test assertions, PacketGuard achieves sub-millisecond packet processing latency while maintaining 100% rule accuracy in an enterprise multi-node topology.

1. Introduction & Problem Statement

Modern enterprise networks face unprecedented security threats requiring sophisticated, multi-layered defense mechanisms. Traditional stateless firewalls operating solely at Layer 3 (IP) and Layer 4 (TCP/UDP) lack the contextual awareness necessary to detect sophisticated attacks, enforce fine-grained policies, or respond to application-level threats. Furthermore, managing firewall policies across multiple client tiersβ€”from administrative systems to development environments to rogue/untrusted clientsβ€”introduces complexity in enforcement, audit trails, and real-time threat response.

Key Engineering Challenges Addressed:

2. OSI Layer 3/4 & Layer 7 Architecture

PacketGuard implements a defense-in-depth security model operating across three critical layers of the OSI stack:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Layer 7 (Application Layer Policy)                      β”‚
β”‚ β€’ Domain & FQDN Interception (e.g. Block google.com)    β”‚
β”‚ β€’ HTTP Host Header Inspection & URL Path Matching       β”‚
β”‚ β€’ Client-Side Browser Deflection (403 Forbidden Screen) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Layer 4 (Transport Layer Stateful Tracking)             β”‚
β”‚ β€’ TCP 3-Way Handshake (SYN → SYN-ACK → ESTABLISHED)     β”‚
β”‚ β€’ Bidirectional Session Hash Table (conntrack)          β”‚
β”‚ β€’ Port Filtering (Web :80/443, SSH :22, MySQL :3306)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Layer 3 (Network Layer Packet Filtering)                β”‚
β”‚ β€’ IPv4 32-bit Dotted Octet Representation               β”‚
β”‚ β€’ Bitwise Subnet Masking (CIDR /24, /16, /8 math)       β”‚
β”‚ β€’ Transport Protocol Classifier (TCP, UDP, ICMP)        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      

The 5-Tuple Packet Structure

Every network packet evaluated within the engine consists of the standard 5-tuple:

Field Type Description & Example
Source IP IPv4 (32-bit) Originating client host address (e.g. 192.168.1.50)
Destination IP / Host IPv4 / FQDN Target server or domain (e.g. 10.0.0.10 or google.com)
Source Port 16-bit Integer Ephemeral client port (e.g. 52140 in range 49152–65535)
Destination Port 16-bit Integer Target service port (e.g. 80 HTTP, 443 HTTPS, 22 SSH)
Protocol String Enum Transport protocol: TCP, UDP, or ICMP

3. Enterprise Multi-Client & Multi-Server Topology

PacketGuard models a real enterprise perimeter architecture with distinct trust zones:

                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚  Internet Cloud  β”‚ (8.8.8.8 / Live Web)
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚  Gateway Router  β”‚ (203.0.113.1)
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚     Firewall     β”‚ (192.168.1.1) ──► [BLOCKED Deflection]
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚   Core Switch    β”‚ (192.168.1.2)
                      β””β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”˜
                          β”‚          β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”      β”Œβ”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚   CLIENT TIER    β”‚      β”‚   SERVER TIER    β”‚
         β”‚ β€’ Admin (.50)    β”‚      β”‚ β€’ Web (10.0.0.10)β”‚
         β”‚ β€’ Dev   (.51)    β”‚      β”‚ β€’ DB  (10.0.0.20)β”‚
         β”‚ β€’ Rogue (.99)    β”‚      β”‚ β€’ SSH (10.0.0.30)β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      

Client Role Specifications:

4. Stateful Connection Tracking (conntrack Engine)

PacketGuard maintains an active connection hash table (connectionTable) that records bidirectional session keys:

Forward Key: srcIp:srcPort -> dstIp:dstPort:proto
Reverse Key: dstIp:dstPort -> srcIp:srcPort:proto
      

When an outbound request (such as 192.168.1.50:51234 → 10.0.0.10:80) is permitted by Rule #6, the session is registered in the state table. When the Web Server responds with HTTP 200 OK (10.0.0.10:80 → 192.168.1.50:51234), the firewall automatically matches Rule #1 (Allow established connections). This guarantees full bidirectional connectivity without opening dangerous, permanent inbound ports.

5. Live Website Interception & Domain Blocking

A core requirement of modern enterprise firewalls is domain-level content filtering. PacketGuard implements both backend proxy inspection (via Python server.py) and frontend client-side interception:

Demonstrable Blocking: google.com vs example.com

6. Test Suite & Validation Results

The firewall engine was rigorously verified using an automated test runner (test_suite.js) evaluating 21 comprehensive test assertions across Layer 3, Layer 4, and Layer 7:

# Test Description Target Expected Verdict Status
1Web HTTP Port 8010.0.0.10:80ALLOWED (Rule #6)PASS
2Stateful Return Packet (200 OK)192.168.1.50:51234ALLOWED (Rule #1 conntrack)PASS
3SSH Port 22 Block10.0.0.10:22BLOCKED (Rule #4)PASS
4HTTPS Port 44310.0.0.10:443ALLOWED (Rule #7)PASS
5DNS Query Port 53 UDP8.8.8.8:53ALLOWED (Rule #8)PASS
6Database Query Port 330610.0.0.10:3306BLOCKED (Rule #10 Default Deny)PASS
7Telnet Attack Port 2310.0.0.10:23BLOCKED (Rule #9)PASS
8CIDR /24 internal match192.168.1.50MATCHPASS
9CIDR /24 external exclusion192.168.2.50EXCLUDEPASS
10CIDR /8 subnet match10.0.5.22MATCHPASS
11Port list matches 80Port 80MATCHPASS
12Port list matches 443Port 443MATCHPASS
13Port list rejects 8080Port 8080REJECTPASS
14Port range matches 5000Port 5000MATCHPASS
15Port range rejects privileged 80Port 80REJECTPASS
16Disabled Rule skippedRule #4 DisabledSKIPPASS
17Custom Rule allows SSHCustom Rule #2ALLOWEDPASS
18Domain google.com blockedgoogle.com:443BLOCKED (Rule #2 Domain)PASS
19Domain example.com allowedexample.com:80ALLOWED (Rule #6)PASS
20Rogue Client C blocked from DB192.168.1.99 → 10.0.0.20BLOCKED (Rule #3 Rogue DB)PASS
21Client B allowed to Web Server192.168.1.51 → 10.0.0.10ALLOWED (Rule #6)PASS

7. Conclusion & Future Scope

The PacketGuard project successfully bridges the gap between theoretical networking concepts (RFC 791, RFC 793, RFC 768) and practical cybersecurity software architecture. By combining multi-client isolation, stateful session tracking, live website domain filtering, and vector trajectory visualization, the project provides an intuitive and rigorous educational platform.

Future Research & Enhancements:

8. References

  1. Postel, J. (1981). Internet Protocol. RFC 791, DARPA Internet Program Protocol Specification.
  2. Postel, J. (1981). Transmission Control Protocol. RFC 793, Information Sciences Institute.
  3. Mockapetris, P. (1987). Domain Names - Concepts and Facilities. RFC 1034, USC/ISI.
  4. Russell, R. (2002). Linux netfilter Hacking HOWTO. The Netfilter Core Team.
  5. Cheswick, W. R., Bellovin, S. M., & Rubin, A. D. (2003). Firewalls and Internet Security: Repelling the Wily Hacker. Addison-Wesley Professional.