bloodhound_export/lib.rs
1//! **bloodhound-export** — write SharpHound-compatible BloodHound JSON from a Rust in-memory
2//! representation of an AD collection.
3//!
4//! Extracted from [ADhammer](https://github.com/icedracon/adhammer) so any tool that
5//! collects AD data in Rust — an LDAP scraper, an NTDS.dit walker, a live-RPC enumerator —
6//! can emit BloodHound-ingestible JSON without pulling the whole ADhammer stack.
7//!
8//! # Model
9//!
10//! Build up a [`Snapshot`]:
11//!
12//! ```ignore
13//! use bloodhound_export::{Snapshot, DomainInfo, AdObject, export_zip};
14//! use std::collections::HashMap;
15//! use std::path::Path;
16//!
17//! let mut u = AdObject::default();
18//! u.dn = "CN=alice,CN=Users,DC=corp,DC=local".into();
19//! u.attrs.insert("sAMAccountName".into(), vec!["alice".into()]);
20//! u.attrs.insert("objectClass".into(), vec!["user".into()]);
21//! u.attrs.insert("userAccountControl".into(), vec!["66048".into()]);
22//! // (populate .bin with objectSid + nTSecurityDescriptor as raw bytes)
23//!
24//! let snap = Snapshot::new(
25//! DomainInfo {
26//! domain_dn: "DC=corp,DC=local".into(),
27//! netbios: Some("CORP".into()),
28//! ..Default::default()
29//! },
30//! vec![u],
31//! );
32//!
33//! export_zip(&snap, Path::new("bloodhound.zip")).unwrap();
34//! ```
35//!
36//! # Output
37//!
38//! [`export_files`] returns the 4 JSON files SharpHound produces:
39//! `<domain>_users.json`, `<domain>_computers.json`, `<domain>_groups.json`,
40//! `<domain>_domains.json` (+ MetaTag / Version header per BH ingestion protocol v5).
41//!
42//! [`export_zip`] wraps those into a single zip that BloodHound's UI ingests directly.
43//!
44//! # Compatibility
45//!
46//! Targets BloodHound Community Edition ingest format v5 / SharpHound v2.x JSON. Emits `Meta`
47//! + `Nodes` shape; ACE edges are computed from `nTSecurityDescriptor` if present in the
48//! per-object `.bin` map, using [`windows_sddl`] for SD parsing.
49
50mod exporter;
51mod model;
52
53pub use exporter::{export_files, export_zip};
54pub use model::{uac, AdObject, DomainInfo, Snapshot};
55
56/// Re-export the SID/GUID types so callers don't need a separate `windows-sddl` dep.
57pub use windows_sddl::{Guid, Sid};
58
59/// Well-known RIDs used inside the exporter.
60pub mod rid {
61 pub const ADMINISTRATOR: u32 = 500;
62 pub const GUEST: u32 = 501;
63 pub const KRBTGT: u32 = 502;
64 pub const DOMAIN_ADMINS: u32 = 512;
65 pub const DOMAIN_CONTROLLERS: u32 = 516;
66 pub const SCHEMA_ADMINS: u32 = 518;
67 pub const ENTERPRISE_ADMINS: u32 = 519;
68 pub const ADMINISTRATORS_BUILTIN: u32 = 544;
69}