Add offline ldap2json import (#11)#21
Open
p0dalirius wants to merge 1 commit into
Open
Conversation
Add --ldap2json FILE flag that loads an ldap2json JSON export,
flattens the hierarchical tree back into {dn: {attr: value, ...}}, and
serves queries from memory via a new OfflineLDAPSearcher. Includes a
small recursive-descent parser for the common subset of RFC 4515
filters (equality, presence, substring wildcards, AND, OR, NOT) so the
existing query/presetquery/export commands work offline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Closes #11
Motivation
Issue #11 asks for the ability to load an ldap2json export and run queries against it without a live LDAP server (useful for post-engagement triage, sharing datasets, or writing queries without access to the DC). This PR wires the JSON loader and a filter-aware in-memory searcher into the existing console, so the existing `query`, `presetquery`, `diff`, and `export` commands work against an offline dataset.
What Changed
Design Notes
The offline searcher is intentionally independent of ldap3's server/connection objects — it only needs the flattened dict and the list of NCs. The parser is small (~60 lines) and correct for the filter shapes that appear in `PresetQueries` and typical user queries; more exotic filter grammar (octet escape sequences, extensible matching rules) is documented as unsupported rather than half-implemented.
Acceptance Criteria Check
How Verified
Runtime: with a representative ldap2json sample (users in `CN=Users`, a computer in `CN=Computers`, a `krbtgt` entry with an SPN):
Test Coverage
None — the repository has no test suite. The behaviors above were exercised via a one-off smoke script against a synthetic ldap2json sample.
Scope of Change
Risk and Rollout
Behavior on the live-LDAP path is unchanged — the offline branch is only taken when `--ldap2json` is supplied. Safe to merge without staged rollout.
Notes
The supported filter grammar is documented inline on `parse_ldap_filter`. Extensible matching rules and `~=` are not implemented; filters that rely on them will either raise or silently ignore the modifier (extensible prefix on the attribute name is stripped).