How datasoft/honeyd works
Project Type and Purpose
• Honeyd is a network honeypot daemon written in C with optional Python extensions.
• Purpose: create and emulate multiple “virtual hosts” on a LAN, simulate TCP/IP stacks and arbitrary services, or proxy connections to real services.
File Structure
Top‐level components:
• Core daemon (honeyd.c, network.c/h, arp.c/h, tcp.c/h, udp.c/h, parse.c/y, config.c, condition.c)
• Subsystems folder (subsystems/smtp, subsystems/proxy, etc.): service‐specific simulation modules, each with a _main entry and message definitions.
• Plugin support (plugins.c/h, plugins_config.c/h) for dynamic loading of protocol handlers.
• Packet libraries:
– pcap capture/injection: pypcap/, dpkt/
– packet creation: libdnet via compat/libdnet
– event loop: libevent
– regex: libpcre (optional)
• CLI/control tools: honeydctl.c, hsniff.c, honeydstats.c
• Web UI: webserver/ (server.py, support.py, htmltmpl.py, static templates & CSS)
• Regression/tests: regress/
• Scripts & sample configurations: scripts/, sample-config/
Insights from README
• Relies on raw sockets (packet sniffing/injection) and event‐based dispatch (libevent).
• Configuration file drives which virtual hosts exist, which services they expose, OS personalities.
• Can drop privileges and run chrooted.
• Optional Python modules for scripting, testing, web UI.
Main Components & Relationships
a. Packet I/O Layer
• OS Kernel interfaces → libpcap & libdnet → packet capture/injection
b. Event Dispatcher
• libevent-based loop schedules read/write events on raw sockets
c. Core Engine
• Packet parser (parse.c/y) decodes Ethernet/IP/TCP/UDP
• Configuration manager (config.c, condition.c) matches packets to virtual host definitions
• Personality engine adapts TCP/IP responses to mimic OS behavior
d. Subsystem Manager
• Loads each subsystem (SMTP, Proxy, etc.) via plugins.c → calls subsystem_main for connection handling
• Plugins return crafted payloads or forward traffic to real backend
e. Logging & Stats
• log.c collects events, honeydstats aggregates, rrdtool.c optionally generates graphs
f. Control & Management
• honeydctl CLI for runtime commands (start/stop hosts, stats)
• hsniff for live packet dumps
g. Web Interface
• Python-based simple HTTP server (webserver/server.py)
• Serves dynamic pages (status, graphs) using templates
h. Test & Regression Framework
• Python scripts under regress/ drive automated consistency tests
Architectural Patterns & Principles
• Modular design with clear separation: network I/O, parsing, configuration, subsystems, logging, UI.
• Plugin/subsystem architecture: new protocols or behaviors can be added without touching core.
• Event-driven loop decouples packet arrival from business logic.
• Multi-language: core C for performance, Python for extensibility/UI/testing.