Skip to main content

Crate ntlm_relay

Crate ntlm_relay 

Source
Expand description

ntlm-relay — NTLM relay-chain primitives, focused on the HTTP-side of the ESC8 / ESC11 AD CS relay.

§What this crate is

The reusable building blocks a Rust NTLM-relay driver needs on the target side of the chain — the CA / LDAP / HTTP server the victim’s captured NTLM will be forwarded to. The victim-listener side (SMB server, LDAP server, HTTP server) is a matter for the transport crates (e.g. smb2-client exposes a server::RelayConn); this crate provides the outbound pieces that turn a Type1 → Type3 opaque forward into an issued certificate.

§Included primitives

  • HttpsClient — minimal keep-alive HTTP/1.1 over rustls, insecure flag for the ubiquitous self-signed AD CS Web Enrollment endpoint.
  • parse_ntlm_challenge — extract the Type-2 blob out of WWW-Authenticate: NTLM <b64>.
  • cert_request_form — build the Mode=newreq&CertRequest=…&CertAttrib=… body the /certsrv/certfnsh.asp handler expects.
  • parse_request_id — scrape the ReqID=<n> the CA emits after certfnsh.asp returns.
  • base64_encode / base64_decode — the base64 subset needed by the ESC8 flow, so the crate depends on rustls and tokio only.

§ESC8 flow, end-to-end

victim SMB ──Type1──▶ your listener ──Type1──▶ HttpsClient.send("POST /certsrv/certfnsh.asp",
                                                               Authorization: NTLM Type1)
                                            ◀── 401 WWW-Authenticate: NTLM Type2
victim SMB ◀─Type2── your listener ◀─Type2──┘
victim SMB ──Type3──▶ your listener ──Type3──▶ HttpsClient.send("POST /certsrv/certfnsh.asp",
                                                               Authorization: NTLM Type3,
                                                               Body: cert_request_form(csr, tmpl))
                                            ◀── 200 OK, body contains ReqID=<n>
attacker ─────────────────────────────────────▶ HttpsClient.send("GET /certsrv/certnew.cer?ReqID=<n>")

ESC11 (MS-ICPR over ncacn_ip_tcp) uses the same Type1/Type2/Type3 shape but on a DCE/RPC bind, not HTTP — see the dcerpc crate’s icpr module and its bind_relay_start / bind_relay_finish methods for the outbound side of that variant.

§What this crate is not

Not a batteries-included relay driver — no SMB victim listener, no LDAP msDS-KeyCredentialLink writer, no argument parsing, no target-selection auto-pilot. The full driver lives in ADhammer, composing this crate with smb2-client, dcerpc, ntlmssp, windows-sddl, and ms-pac-forge. If you’re building your own relay driver, wire these primitives to your listener of choice.

Re-exports§

pub use certsrv::Esc8Step1;
pub use certsrv::EscCertsrvChain;
pub use ldap_rbcd::build_rbcd_clear;
pub use ldap_rbcd::build_rbcd_write;
pub use ldap_rbcd::ModifyOp;
pub use ldap_rbcd::RbcdWrite;
pub use ldap_rbcd::ATTR_ALLOWED_TO_ACT_ON_BEHALF;

Modules§

certsrv
ESC8 — AD CS Web Enrollment relay chain.
ldap_rbcd
RBCD-write payload primitives for an LDAP-relay backend.

Structs§

HttpResponse
HttpsClient

Functions§

base64_decode
base64_encode
cert_request_form
Build the form-encoded body AD CS Web Enrollment expects. csr_pem is the PEM-armored PKCS#10.
parse_ntlm_challenge
Extract the NTLM Type-2 (base64) from a single WWW-Authenticate header value.
parse_ntlm_challenge_all
Extract the NTLM Type-2 from any of the given WWW-Authenticate header values (in the order the server sent them). Use this over parse_ntlm_challenge when the response may split schemes across multiple header lines (IIS does).
parse_request_id
Extract the certificate Request ID from the ASP response HTML. AD CS emits ReqID=<n> in a location.href="certnew.cer?ReqID=..." line or similar.