Describe the bug
Two vulnerabilities exist in the current implementation of the Pre2k module, and when combined they can be used to achieve RCE.
The code implicitly trusts the domain (when -d parameter is not specified) and samAccountName returned within the LDAP response without sanitization. It uses the supplied domain when forming the path to write the output files. If the user supplies a string in place of the domain with ../ included, they will be able to write the precreated_computers.txt file anywhere on the nxc user's system. As the sameAccountName string isn't validated and directly written as the entire file contents, the malicious LDAP server is able to write any amount of arbitrary text to this file.
|
domain_dir = os.path.join(f"{NXC_PATH}/modules/pre2k", connection.domain) |
|
output_file_pre2k = os.path.join(domain_dir, "precreated_computers.txt") |
|
output_file_non_pre2k = os.path.join(domain_dir, "non_precreated_computers.txt") |
|
|
|
# Create directories if they do not exist |
|
os.makedirs(domain_dir, exist_ok=True) |
|
|
|
with open(output_file_pre2k, "w") as pre2k_file, open(output_file_non_pre2k, "w") as non_pre2k_file: |
|
for computer, uac in computers.items(): |
|
if int(uac) == 4128: |
|
pre2k_file.write(f"{computer}\n") |
|
else: |
|
non_pre2k_file.write(f"{computer}\n") |
These two vulnerabilities, when combined, allow RCE on the nxc user's system simply by probing a malicious LDAP server with the pre2k module. A working PoC for this is available upon request.
To Reproduce
netexec ldap 10.10.10.10 -u username -p password -M pre2k
With an LDAP server that will respond with the following attributes:
defaultNamingContext = "DC=test,DC=local/../../../../../../../../../<any dir path>"
sAMAccountName = "<any file contents>"
Expected behavior
The domain supplied by the target system must be properly sanitized to ensure directory traversal is not possible.
The samAccountName must be validated against the Microsoft documentation found here.
NetExec info
- OS: Kali
- Version of nxc: 1.5.1 - Yippie-Ki-Yay - Kali Linux -
- Installed from: source
NOTE
A CVE has been filed with MITRE for this issue.
Describe the bug
Two vulnerabilities exist in the current implementation of the Pre2k module, and when combined they can be used to achieve RCE.
The code implicitly trusts the domain (when
-dparameter is not specified) and samAccountName returned within the LDAP response without sanitization. It uses the supplied domain when forming the path to write the output files. If the user supplies a string in place of the domain with../included, they will be able to write theprecreated_computers.txtfile anywhere on the nxc user's system. As the sameAccountName string isn't validated and directly written as the entire file contents, the malicious LDAP server is able to write any amount of arbitrary text to this file.NetExec/nxc/modules/pre2k.py
Lines 57 to 69 in b7c0f65
These two vulnerabilities, when combined, allow RCE on the nxc user's system simply by probing a malicious LDAP server with the pre2k module. A working PoC for this is available upon request.
To Reproduce
With an LDAP server that will respond with the following attributes:
Expected behavior
The domain supplied by the target system must be properly sanitized to ensure directory traversal is not possible.
The samAccountName must be validated against the Microsoft documentation found here.
NetExec info
NOTE
A CVE has been filed with MITRE for this issue.