Enumerating SMB and LDAP
On most internal networks the richest services are not the web servers but the Windows file shares (SMB) and the directory (LDAP on the domain controllers). A file share may hand an anonymous client a list of shares, and an authenticated test account may read far more than its owner realises. The directory knows every user, group, computer and policy, and by design any authenticated user can read most of it. Enumerating these two services is how an internal test learns the organisation's real structure, and many of the most serious internal findings start here.
The protocols are described in SMB, NFS and RDP and LDAP and Kerberos on the Wire; Active Directory itself is the subject of Windows & Active Directory Security. The sandbox runs neither service, so this lesson shows lab transcripts and analyses enumeration output in Python.
SMB: what to ask
| Question | Lab tool | Weakness it reveals |
|---|---|---|
| Is message signing required? | nmap --script smb2-security-mode |
without required signing, relay attacks against the host are possible (a concept for the AD course) |
| Can an anonymous or guest client list shares? | smbclient -L //host -N |
null sessions and guest access expose share names and sometimes contents |
| What can the test account read and write? | smbclient, smbmap, NetExec's --shares |
over-broad share permissions ("Everyone: Full control") |
| Which SMB dialects? | smb-protocols script |
SMBv1 still enabled |
Lab session, authorised internal test, scope 10.10.0.0/24 minus exclusions, from 10.10.0.99, inside the window; the test account lab\pt-user was provided by the client:
tester@lab:~$ nmap -sT -p 445 --script smb2-security-mode,smb-protocols 10.10.0.11,21
Nmap scan report for dc01.lab.test (10.10.0.11)
PORT STATE SERVICE
445/tcp open microsoft-ds
Host script results:
| smb2-security-mode:
| 3.1.1:
|_ Message signing enabled and required
| smb-protocols:
| dialects:
| 2.0.2
| 2.1
| 3.0
| 3.0.2
|_ 3.1.1
Nmap scan report for files01.lab.test (10.10.0.21)
PORT STATE SERVICE
445/tcp open microsoft-ds
Host script results:
| smb2-security-mode:
| 3.1.1:
|_ Message signing enabled but not required
| smb-protocols:
| dialects:
| NT LM 0.12 (SMBv1) [dangerous, but default]
| 2.0.2
| 2.1
| 3.0
| 3.0.2
|_ 3.1.1
tester@lab:~$ smbclient -L //10.10.0.21 -N
Sharename Type Comment
--------- ---- -------
ADMIN$ Disk Remote Admin
C$ Disk Default share
IPC$ IPC Remote IPC
Public Disk Shared documents
Scans Disk Scanner output
SMB1 disabled -- no workgroup available
tester@lab:~$ smbclient //10.10.0.21/Scans -U 'lab\pt-user' -c 'ls' | head -4
. D 0 Tue Dec 1 08:12:40 2026
.. D 0 Tue Dec 1 08:12:40 2026
2026-11-30_payroll_scan.pdf A 418211 Mon Nov 30 16:02:11 2026
2026-11-30_passport_copy.pdf A 201544 Mon Nov 30 16:05:37 2026Three findings and a stop:
files01doesn't require SMB signing and still offers SMBv1 (the domain controller requires signing, which is the Windows default for DCs).- Anonymous share listing works on
files01: share names are visible without credentials. - The
Scansshare is readable by an ordinary account and holds scanned payroll and identity documents. The listing proves it; the tester does not open the files, notes names, sizes and times, and follows the RoE's sensitive-data procedure: notify the contact now (see Test Windows, Stop Conditions and Data Handling).
Detection and fixes for SMB
- Detection: Windows event 5140 (a network share was accessed) and 5145 (detailed file-share access, if auditing is on) show who listed and read what; anonymous logons appear as event 4624 with the
ANONYMOUS LOGONaccount; IDS signatures flag SMBv1 negotiation. - Fixes: require signing on all servers and clients (Group Policy "Microsoft network server: Digitally sign communications (always)"), disable SMBv1, restrict anonymous enumeration (
RestrictAnonymous,RestrictNullSessAccess), and review share and NTFS permissions so that sensitive shares are limited to the groups that need them. Scanned documents belong in a system with access control and retention, not a share.
LDAP: what to ask
Every domain controller answers an anonymous query for the rootDSE, a small entry describing the directory (its naming contexts, functional level, host name). That is by design. Beyond the rootDSE, modern Active Directory refuses anonymous reads, but any authenticated user can read most of the directory: users, groups, computers, descriptions, and attributes such as userAccountControl and servicePrincipalName.
tester@lab:~$ ldapsearch -x -H ldap://10.10.0.11 -s base -b "" defaultNamingContext dnsHostName domainFunctionality
dn:
defaultNamingContext: DC=lab,DC=test
dnsHostName: dc01.lab.test
domainFunctionality: 7(7 is the Windows Server 2016 domain functional level.) With the test account, the tester exports users with a handful of attributes. The analysis below runs on a synthetic export in that shape and flags the account settings that matter. The flags are bits of userAccountControl: 0x2 disabled, 0x10000 password never expires, 0x400000 Kerberos pre-authentication not required.
users = [ # synthetic LDAP export: sAMAccountName, userAccountControl, adminCount, SPNs, description
("administrator", 0x10200, 1, [], "Built-in account for administering the domain"),
("j.pham", 0x200, 0, [], "Finance"),
("svc-backup", 0x10200, 1, ["backup/files01.lab.test"], "Backup service"),
("svc-web", 0x10200, 0, ["HTTP/www.lab.test"], "IIS app pool - pw Summer2024!"),
("t.vo", 0x400200, 0, [], "Contractor"),
("old.admin", 0x202, 1, [], "Left 2023"),
("pt-user", 0x200, 0, [], "Pentest account (expires 2026-12-12)"),
]
DISABLED, NO_EXPIRE, NO_PREAUTH = 0x2, 0x10000, 0x400000
findings = {}
for name, uac, admin, spns, desc in users:
issues = []
if uac & DISABLED:
if admin:
issues.append("disabled but still marked privileged (adminCount=1): clean up group memberships")
findings[name] = issues
continue
if uac & NO_EXPIRE and admin:
issues.append("privileged, password never expires")
if spns:
issues.append(f"user account with SPN {spns[0]}: its password can be attacked offline (Kerberoasting concept)")
if uac & NO_PREAUTH:
issues.append("pre-authentication not required: offline-attackable (AS-REP roasting concept)")
if any(w in desc.lower() for w in ("pw", "pass", "pwd")):
issues.append("possible password in description: report, don't use")
findings[name] = issues
for name, issues in findings.items():
for i in issues:
print(f"{name:<14} {i}")
print(f"\n{sum(1 for v in findings.values() if v)} of {len(users)} accounts need attention")administrator privileged, password never expires
svc-backup privileged, password never expires
svc-backup user account with SPN backup/files01.lab.test: its password can be attacked offline (Kerberoasting concept)
svc-web user account with SPN HTTP/www.lab.test: its password can be attacked offline (Kerberoasting concept)
svc-web possible password in description: report, don't use
t.vo pre-authentication not required: offline-attackable (AS-REP roasting concept)
old.admin disabled but still marked privileged (adminCount=1): clean up group memberships
5 of 7 accounts need attention
These are configuration findings, found by reading what the directory shows to any employee. The attacks that some of them enable (requesting service tickets to guess a service account's password offline, or AS-REP roasting) are taught as concepts with their detection and hardening in the Windows and AD course. In this engagement the finding is the configuration itself, and the evidence is the attribute values.
Detection and fixes for LDAP findings
- Detection: LDAP queries are normal traffic, so directory enumeration is hard to spot by volume alone; defenders watch for one account issuing wide queries for sensitive attributes (
servicePrincipalName=*,userAccountControlbit filters), and Windows event 4662 (operation on an object, with auditing) or LDAP diagnostic logging (event 1644) records expensive queries. Ticket requests for service accounts appear as event 4769. - Fixes: long random passwords or group Managed Service Accounts (gMSA) for service accounts with SPNs; remove "pre-authentication not required" except where a documented legacy need exists; no passwords in descriptions (rotate the exposed one now); privileged accounts with expiring passwords or, better, phishing-resistant MFA; remove disabled accounts from privileged groups; and an LDAP signing and channel-binding policy on the DCs.
Pitfalls
- Opening sensitive files to "prove" access. The listing with names, sizes and times is the proof; opening is over-collection.
- Using a password found in a description. It is a finding to report immediately, unless the RoE explicitly allows using credentials found during the test.
- Account lockouts. Guessing passwords over SMB or LDAP against a domain locks real users out; never without written agreement on attempts per account and the lockout policy.
- Testing the domain controllers like any server. DCs are the most critical systems in the network; enumerate gently and keep intrusive checks off them unless agreed.
Practice
svc-backuphasadminCount=1, a never-expiring password and an SPN. Why is that combination the most urgent item on the list?- Write the evidence line for the
Scansshare finding without disclosing any personal data.
Answers
- A service ticket for its SPN can be requested by any domain user and attacked offline; if the password is weak and never changes, the attacker obtains a privileged account. Fix: convert it to a gMSA (long, automatically rotated password) or set a 30+ character random password, and review why it needs privileged group membership.
- For example: "
\\files01.lab.test\Scanslisted with test accountlab\pt-useron 2026-12-02 10:14 UTC: 214 files, names indicate payroll and identity-document scans (examples redacted:2026-11-30_<type>_scan.pdf), sizes 0.1-0.6 MB. Files not opened. Client contact notified 10:20 UTC."
Test yourself
Which SMB setting allows relay attacks against a server?
- SMB 3.1.1 enabled
- Message signing enabled but not required
- Message signing required
- Port 445 closed
What can an anonymous client usually read from a modern Active Directory domain controller over LDAP?
- All users and groups
- Only the rootDSE (naming contexts, host name, functional level)
- Password hashes
- Nothing at all
The Scans share lists payroll and passport scans. What proves the finding?
- Opening several files
- The listing (names, sizes, times) with the account and time used; files not opened
- Copying the files to the report
- A screenshot of a passport
Which userAccountControl bit means Kerberos pre-authentication is not required?
- 0x2
- 0x200
- 0x10000
- 0x400000