Skip to main content
XsiSec.com
HomeReposBlogProjectsPortfolio
© 2026 XsiSec.com
Security rules |security.txt
Updated 2026-08-15 · v1.0.0+2026-08-14.82f92cb · 82f92cb
← Back to overview
Security article

HTB Academy - LDAP

HTB Academy - LDAP: Keep a clear, ops-ready explainer of LDAP and MSRPC in AD: what they are, how they’re used, how to query/troubleshoot them, and what to lock down. Short, copy‑pasteable, and practical. • HTB Academy • htb-academy, ldap

2022-09-303 tags
Tags

🎯 Objective

Keep a clear, ops-ready explainer of LDAP and MSRPC in AD: what they are, how they’re used, how to query/troubleshoot them, and what to lock down. Short, copy‑pasteable, and practical.


🧩 What I’m covering

  • LDAP v3 (RFC 4511) in AD: ports, binds (Simple vs SASL/Kerberos), why LDAPS matters.
  • How apps “speak” to AD using LDAP (the protocol) vs AD (the directory service).
  • MSRPC: core interfaces you’ll actually see (LSARPC, NETLOGON, SAMR, DRSUAPI) and why they matter to red/blue.
  • Quick commands + troubleshooting + defense notes.

LDAP in AD (quick view)

  • Protocol: LDAP v3 (open standard; cross‑platform).
  • Ports: 389/tcp,udp (LDAP), 636/tcp (LDAPS).
  • Role: Directory queries/updates (users, groups, computers, OUs), and authentication via bind.
  • Who listens: Domain Controllers (Directory System Agent).

LDAP/AD

Analogy: AD : LDAP :: Apache : HTTP. AD is the directory service; LDAP is the protocol apps use to talk to it. You may also encounter non‑AD LDAP (e.g., OpenLDAP).


🔐 LDAP Authentication (BIND)

Two main flavors:

  • Simple Authentication
    Anonymous, unauthenticated (rare), or username/password. With Simple binds on 389, creds are cleartext unless you wrap with TLS/StartTLS or use LDAPS (636).

  • SASL Authentication
    SASL hands off auth to mechanisms like Kerberos (GSSAPI). LDAP transports the negotiation; Kerberos does the proving. This separates the app protocol from the auth method and can add integrity/confidentiality depending on mech/flags.

Use LDAPS or StartTLS to protect Simple binds. Many orgs require LDAP signing and channel binding to prevent downgrade/relay issues.


MSRPC in AD

Microsoft RPC underpins a ton of Windows/AD management. Clients hit the Endpoint Mapper on 135/tcp, then negotiate a dynamic high port (or use SMB named pipes). Four interfaces you’ll keep seeing:

InterfaceWhat it talks toWhy it matters
lsarpcLocal Security Authority (LSA)Query/set security policy, SID/Name lookups, trust info. Policy admin footprints; enumeration primitives.
netlogonNETLOGON serviceSecure channel for machine/user auth; DC locator; logon processes. Weaknesses show up in relay/hardening gaps.
samrSecurity Accounts Manager (SAM)Manage/read users/groups/computers. By default any authenticated user can query a lot (attack path recon). Lock this down.
drsuapiDirectory Replication Service (DRS)DC replication calls. Abused for DCSync/NTDS extraction (hashes) via tools like secretsdump.py.

RPC often rides SMB named pipes (\PIPE\samr, \PIPE\lsarpc, …). Firewalls must allow 135/tcp + a constrained dynamic range for management to work reliably.


📎 Copy‑paste crib

LDAP — quick checks

bash
# Linux/Mac: base naming contexts (what DC advertises)
ldapsearch -x -H ldap://dc01.inlanefreight.local -s base -b "" namingcontexts

# Query a DN (anonymous or explicit bind)
ldapsearch -x -H ldap://dc01.inlanefreight.local -D 'INLANEFREIGHT\wiener' -W -b 'DC=INLANEFREIGHT,DC=LOCAL' '(sAMAccountName=carlos)' cn memberOf

# LDAPS test (cert must be trusted on the client)
ldapsearch -x -H ldaps://dc01.inlanefreight.local -b '' -s base supportedSASLMechanisms
powershell
# Windows PowerShell: DNS SRV records for DCs
Resolve-DnsName _ldap._tcp.dc._msdcs.INLANEFREIGHT.LOCAL -Type SRV

# Show current Kerberos tickets (useful if SASL/GSSAPI in play)
klist

MSRPC — discovery & abuse (lab/assessment context)

bash
# Enumerate RPC endpoints (Impacket)
rpcdump.py dc01.inlanefreight.local

# SAMR over SMB named pipe (null/guest will usually fail; use a domain user)
rpcclient -U 'INLANEFREIGHT\wiener%peter' dc01.inlanefreight.local -c 'enumdomusers; enumdomgroups'

# DRSUAPI / DCSync (requires rights like Replicate Directory Changes)
secretsdump.py 'INLANEFREIGHT/wiener:peter@dc01.inlanefreight.local' -just-dc

DNS — DC discovery sanity

powershell
nslookup
> set type=SRV
> _ldap._tcp.dc._msdcs.INLANEFREIGHT.LOCAL
> _kerberos._tcp.INLANEFREIGHT.LOCAL

🧪 Troubleshooting

LDAP

  • Simple binds over 389 are cleartext; use StartTLS/LDAPS.
  • If LDAPS fails, check DC certificate (EKU for server auth), CRL reachability, and client trust.
  • Enforce LDAP signing and channel binding; confirm clients support it.
  • Bind DN/UPN mistakes are common (user@domain vs DOMAIN\user).

MSRPC

  • Firewalls: allow 135/tcp and a constrained dynamic RPC range or named pipes over SMB.
  • If ADUC/RSAT tools hang, suspect RPC path or name resolution.
  • Restrict SAMR remote queries (NetCease‑style hardening) to cut authenticated recon noise.
  • For DCSync misuse, audit Replicate Directory Changes rights and service accounts.

🔒 Defense (blue‑team notes)

  • Prefer Kerberos/SASL binds; require LDAPS.
  • Enable LDAP signing/channel binding and monitor Simple Bind usage.
  • Harden SAMR access (limit to admins), and monitor for unusual RPC calls.
  • Constrain RPC dynamic ports; document firewall rules between admin hosts and DCs.
  • Audit and alert on DCSync‑like activity and anomalous replication traffic.

✅ Takeaways

  • LDAP is the language; AD is the directory. Use LDAPS (or StartTLS) and SASL/Kerberos where possible.
  • MSRPC is everywhere in Windows management—know lsarpc/netlogon/samr/drsuapi and what exposure each brings.
  • The copy‑paste blocks above cover 80% of what I tend to do when validating or debugging these paths.
Navigate

In this post

  1. 01🎯 Objective
  2. 02🧩 What I’m covering
  3. 03LDAP in AD (quick view)
  4. 04🔐 LDAP Authentication (BIND)
  5. 05MSRPC in AD
  6. 06📎 Copy‑paste crib
  7. 07LDAP — quick checks
  8. 08MSRPC — discovery & abuse (lab/assessment context)
  9. 09DNS — DC discovery sanity
  10. 10🧪 Troubleshooting
  11. 11🔒 Defense (blue‑team notes)
  12. 12✅ Takeaways
Search
Explore

Popular tags

Browse all 30 tags

Comments

0 comments

No comments yet — be the first to comment.