How blechschmidt/massdns works
Project Type and Purpose
• MassDNS is an open-source, command-line DNS stub resolver optimized for high throughput (millions of queries).
• It comprises a C-based core engine (src/ → bin/massdns), assorted helper scripts (scripts/), wordlists/resolver lists (lists/), and automated tests.
File Structure Analysis
• Top-level:
• .github/, Makefile, CMakeLists.txt, Dockerfile: CI/build.
• src/: core C modules (networking, DNS, concurrency, hashing, I/O).
• scripts/: Python/SH scripts driving MassDNS for PTR, recon, subdomain brute force, extracting resolvers.
• lists/: input data (resolvers.txt, names.txt).
• tests/: end-to-end test scenarios with expected outputs.
• doc/: manual page.
• Pattern: modular C library + single executable + pluggable scripting layer + external data + CI/CD.
Key README Insights
• Core features: single-threaded event-driven (epoll or busy-poll), multi-process via --processes, custom malloc-free DNS parser, hash map for concurrency control (-s), flexible output formats.
• Integration points: scripts pipe domain names into massdns, pipe output into further processing.
Components
a. Main components:
1. CLI Parser (cmd.h + main.c)
2. Core Resolver Engine
• Concurrency Manager (hashmap.h, auto_concurrency.h)
• Event Loop (net.h, flow.h)
• DNS Packet Builder/Parser (dns.h, buffers.h, security.h)
3. Output Formatter (string.h, cmd.h)
4. Script Layer
• Pre-processors: subbrute.py, ct.py, ptr.py, recon.py
• Post-processors: any shell pipelines consuming ndjson/text/binary output
5. Data Stores
• Resolver list (lists/resolvers.txt)
• Wordlists (lists/names.txt, names_small.txt)
6. Test Harness (tests/ directory, run-tests.sh)
7. Build & CI (Makefile, CMakeLists.txt, Dockerfile, GitHub workflows)
b. Relationships and Data Flows
• User invokes CLI → CLI Parser loads configs and lists → Engine spins up processes → Event Loop sends DNS queries over UDP/TCP to External Resolvers or Authoritative Name Servers → Responses fed back into Packet Parser → Concurrency Manager tracks in-flight queries → Output Formatter writes to STDOUT or file → downstream scripts or user tools consume output.
• Scripts feed domain names into MassDNS via STDIN or file arguments; MassDNS outputs JSON/text to STDOUT, which scripts or other tools can ingest.
c. Architectural Patterns and Principles
• Modular C library layering: separation of CLI, concurrency, networking, packet parsing, I/O.
• Event-driven, non-blocking I/O.
• Forked multi-processing for scale.
• Pluggable scripts for extensibility.
• Single-responsibility modules (hash map, randomization, security).
d. Technologies/Frameworks
• Language: C (gcc), Python/SH for scripts.
• Build: Make, CMake, Docker.
• CI: GitHub Actions.
• Runtime: Linux (epoll, raw sockets), Cygwin support on Windows.