$ show projectdiscovery/alterx
AlterX is a Go CLI tool and library for generating subdomain wordlists using a DSL (Domain-Specific Language) for patterns and an optional pattern mining mode. It ingests a list of known subdomains, extracts variables (sub, suffix, root, etc.), and applies user-defined or automatically discovered patterns to produce permutations. The architecture is modular: a Mutator engine orchestrates either default pattern-based generation (using ClusterBomb cartesian product) or pattern mining (via edit-distance clustering, n-gram analysis, and DFA-based regex generation). Key entry points are the CLI (`cmd/alterx/main.go`) and the library API (`mutator.go`). External dependencies include `fasttemplate` for variable replacement, `publicsuffix` for domain parsing, and `projectdiscovery/utils` for deduplication and other utilities. The pattern mining subsystem (ported from Regulator) uses a three-phase clustering algorithm and Brzozowski's DFA minimization to generate subdomains from observed patterns. The tool supports three modes: default (user patterns), discover (mined patterns only), and both (combined).
The LLM identified 4 files worth highlighting for reuse:
Implements the Nth-order ClusterBomb algorithm for generating all combinations of payload values across multiple variables. Uses a recursive vector construction with an IndexMap for deterministic ordering. This is a self-contained, reusable pattern for generating cartesian products of variable-length arrays, applicable to any combinatorial generation problem beyond subdomain enumeration.
A complete DFA (Deterministic Finite Automaton) engine implementing Brzozowski's algorithm for DFA minimization. It constructs a Thompson NFA from a regex, converts to DFA via subset construction, then applies reverse-determinize-reverse-determinize minimization. Supports fixed-length string generation and counting. This is a non-trivial, well-crafted automata library that could be extracted for use in other regex-based generation or validation tasks.
Parses subdomain URLs into structured variables (sub, suffix, root, TLD, eTLD, multi-level subdomains) using the publicsuffix library. Provides a clean `Input` struct and `GetMap()` method for template variable substitution. This component is self-contained and reusable for any application that needs to decompose domain names into their constituent parts.
A custom io.Writer wrapper that performs transparent, asynchronous deduplication using a channel-based pipeline and the projectdiscovery/utils/dedupe library. It supports a blacklist/seed, skips empty lines and lines starting with '-', and provides a Count() method. Although not currently used in the main execution path, it demonstrates a clean, reusable pattern for adding deduplication to any io.Writer stream.