Bug 16123 - remove_dc uses unescaped dnsHostName from directory data in DNS service-account LDAP filter
Summary: remove_dc uses unescaped dnsHostName from directory data in DNS service-accou...
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Python (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Douglas Bagnall
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks: 16182
  Show dependency tree / graph
 
Reported: 2026-06-14 23:14 UTC by Douglas Bagnall
Modified: 2026-09-22 10:02 UTC (History)
1 user (show)

See Also:


Attachments
patch that escapes bad values in the dNSHostName (1.20 KB, patch)
2026-07-16 23:00 UTC, Douglas Bagnall
abartlet: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Douglas Bagnall 2026-06-14 23:14:48 UTC
Tridge writes:

Directory-controlled dnsHostName reaches a privileged remove_dc LDAP filter without escaping; a crafted value can redirect the single-result DNS service-account deletion during DC cleanup.

- python/samba/remove_dc.py:234-249
- python/samba/remove_dc.py:278-286
- python/samba/remove_dc.py:382-405
- python/samba/netcmd/domain/demote.py:53-82
- python/samba/netcmd/domain/backup.py:659-667

Remaining uncertainty: No live AD schema/write-constraint test was run; validation assumes a malicious or compromised directory object can carry LDAP filter metacharacters in dnsHostName or equivalent replicated data.

#### Dataflow

- Attacker role: Delegated directory administrator, compromised DC, or replicated directory state able to place LDAP filter metacharacters in the target server object dnsHostName.
- Entrypoint: Administrative DC-removal flows: samba-tool domain demote --remove-other-dead-server and domain backup restore cleanup call remove_dc().
- Trust boundary: Directory-stored server attributes cross into a privileged SamDB cleanup search that can delete an account.


Attacker outcome: Directory-controlled dnsHostName reaches a privileged remove_dc LDAP filter without escaping; a crafted value can redirect the single-result DNS service-account deletion during DC cleanup.

#### Remediation

Escape dnsHostName with ldb.binary_encode() before filter construction, validate hostnames against expected DNS syntax, and prefer DN/object identity checks before deletion. Add regression coverage that exercises the attacker-controlled input at the listed entry point and asserts the validation, authorization, containment, or size check occurs before the dangerous sink.


| Severity | medium |
| Confidence | high |
Comment 1 Andrew Bartlett 2026-06-15 08:26:36 UTC
I agree we shouldn't trust LDAP in general, but DC objects are privileged and as written this is not a plausible attack.  

However when fixing these we might find an actually plausible issue not so far raised.
Comment 2 Douglas Bagnall 2026-07-16 23:00:58 UTC
Created attachment 19114 [details]
patch that escapes bad values in the dNSHostName

> I agree we shouldn't trust LDAP in general, but DC objects are privileged and
as written this is not a plausible attack.

Agreed. I think we can escape the dns host name and close this as a non-security bug.
Comment 3 Andrew Bartlett 2026-09-22 10:02:45 UTC
Removing embargo so reviewed patch can be submitted upstream.