A Python-based rogue DHCP server detection tool for network security monitoring.
- DHCP Message Validation: Validates DHCP messages and filters out invalid communications
- Rogue Server Detection: Identifies unauthorized DHCP servers on the network
- Real-time Alerts: Provides immediate notifications with IP and MAC addresses of suspicious devices
- Whitelist Support: Maintains a list of authorized DHCP servers for comparison
- Multi-interface Scanning: Monitors all network interfaces except loopback
DHCP (Dynamic Host Configuration Protocol) operates on the application layer using UDP ports 67 (server) and 68 (client). The protocol involves an 8-message exchange process:
- DHCP Discover - Client broadcasts to find available DHCP servers
- DHCP Offer - Server responds with available IP and configuration
- DHCP Request - Client requests specific IP address
- DHCP Acknowledgment - Server confirms IP assignment
- DHCP Negative Acknowledgment - Server denies request (pool exhausted)
- DHCP Decline - Client rejects invalid configuration
- DHCP Release - Client releases IP address
- DHCP Inform - Client requests configuration without IP assignment
The tool works by:
- Creating DHCP Discover packets for each network interface
- Broadcasting these packets to detect responding DHCP servers
- Comparing discovered servers against a whitelist of authorized servers
- Alerting on any unauthorized DHCP responses
- Python 3.6+
- Scapy library
- Root/administrator privileges for network packet manipulation
- Network access to interfaces being monitored
sudo pip3 install scapysudo python3 dhcp_snooper.pyCreate a dhcp_whitelist.txt file with authorized DHCP server IP addresses (one per line):
192.168.1.1
10.0.0.1
- Interface Discovery: Identifies available network interfaces
- Packet Crafting: Creates properly formatted DHCP Discover packets
- Response Analysis: Processes DHCP Offer responses
- Whitelist Validation: Compares discovered servers against authorized list
- Alert System: Notifies users of rogue server detection
get_network_interfaces(): Lists all available network interfacescreate_dhcp_discover(): Constructs DHCP discovery packetssend_discovery(): Broadcasts discovery packets and collects responsesvalidate_servers(): Compares responses against whitelistgenerate_alerts(): Creates notifications for rogue servers
- Requires elevated privileges for packet manipulation
- Should be run in controlled network environments
- May generate network traffic that could be detected by IDS systems
- Ensure proper authorization before scanning networks
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is for educational and authorized security testing purposes only.
- saurabhsharma56. (2018). DHCP Protocol Overview
- Kumar. (2020). Python subprocess module
- nikhilaggarwal3 & rkbhola5. (2022). Regular expressions in Python
- Scapy Documentation. (n.d.). Network packet manipulation