Penetration Basics - Obtaining Domain User Password Policies

Onedaysec
6 min read
0 views
docx image 1770019807633 0 7c652fe763

0x00 Preface

---

In domain penetration, we need to obtain the password policies of domain users before password brute-forcing to avoid locking out users during the attack.

From a defensive perspective, it is necessary to identify password brute-forcing attacks and implement defensive measures.

This article will introduce common methods for obtaining domain user password policies, along with detection methods for domain user password brute-forcing attacks.

0x01 Introduction

---

This article will cover the following topics:

  • Methods for modifying domain user password policies
  • Methods for obtaining domain user password policies from outside the domain
  • Methods for obtaining domain user password policies from within the domain
  • Detection methods

0x02 Basics

---

We need to focus on the following password policies:

  • Maximum password age, indicating the expiration time of passwords, default is 42
  • Minimum password length, indicating the minimum length of passwords, default is 7
  • Account lockout duration, indicating the number of minutes a locked account remains locked before being automatically unlocked, default is 30
  • Account lockout threshold, indicating the number of failed login attempts that cause a user account to be locked, default is 5
  • Reset account lockout counter after, indicating the number of minutes that must elapse after a failed login attempt before the failed login attempt counter is reset to 0, default is 30

0x03 Method to modify domain user password policy

---

The domain user password policy is by default stored in the Default Domain Policy within the domain, with GUID {31B2F340-016D-11D2-945F-00C04FB984F9}

Open Group Policy Management on the domain controller, locate the current domain, select Default Domain Policy, right-click and choose Edit, as shown in the figure below

0x03 Method to modify domain user password policy — technical illustration 1

Navigate sequentially through Computer Configuration->Policies->Windows Settings->Security Settings->Account Policies, as shown in the figure below

0x03 Method to modify domain user password policy — technical illustration 2

Modify the corresponding options as prompted

After modification, you can choose to update the group policy immediately to make it effective, enter the command line:

gpupdate

0x04 Methods for Obtaining Domain User Password Policies from Outside the Domain

---

1. Using ldapsearch on Kali System to Obtain Domain User Password Policies

Test environment as shown below

1. Using ldapsearch on Kali System to Obtain Domain User Password Policies — technical illustration 3

Prerequisite: We can access port 389 of the Domain Controller (DC) and have obtained the password of at least one ordinary domain user

In this test environment, we have obtained the password for the ordinary domain user testa: DomainUser123!

Connection command as follows:

ldapsearch -x -H ldap://192.168.1.1:389 -D "CN=testa,CN=Users,DC=test,DC=com" -w DomainUser123! -b "DC=test,DC=com" | grep replUpToDateVector -A 13

Parameter description:

-x Perform simple authentication

-H Server address

-D DN used to bind to the server

-w Password for binding DN

-b specifies the root node to query

Use the grep command to filter the output results; grep replUpToDateVector -A 13 is to display only items related to password policy

The output result is shown in the figure below

1. Using ldapsearch on Kali System to Obtain Domain User Password Policies — technical illustration 4

Includes the following required information:

  • maxPwdAge: -36288000000000
  • minPwdLength: 10
  • lockoutDuration: -18600000000
  • lockoutThreshold: 15
  • lockOutObservationWindow: -18600000000

To convert to seconds, divide by 10000000

For example:

(1) maxPwdAge: -36288000000000

36288000000000/10000000=3628800s

3628800/86400=42d

maxPwdAge=42d

(2)lockoutDuration: -18600000000

-18600000000/10000000=1860s

1860/60=31m

lockoutDuration=31m

2. Retrieving Domain User Password Policy via PowerShell on Windows System

Test environment is shown in the figure below

2. Retrieving Domain User Password Policy via PowerShell on Windows System — technical illustration 5

Prerequisite: We can access port 389 of the domain controller (DC), and we have obtained at least one regular domain user's password

In this test environment, we obtained the password for the regular domain user testa as DomainUser123!

The PowerShell module Active Directory is required here

There is no need to specifically install the PowerShell module Active Directory; it can be resolved by calling Microsoft.ActiveDirectory.Management.dll

Microsoft.ActiveDirectory.Management.dll is generated after installing the PowerShell module Active Directory. I have extracted it and uploaded it to GitHub:

An open-source project

Additionally, credential information is required, so the complete PowerShell command is as follows:

$uname="testa"
$pwd=ConvertTo-SecureString "DomainUser123!" -AsPlainText –Force
$cred=New-Object System.Management.Automation.PSCredential($uname,$pwd)
import-module .\Microsoft.ActiveDirectory.Management.dll
Get-ADDefaultDomainPasswordPolicy -Server 192.168.1.1 -Credential $cred -Verbose

The output result is as shown in the figure below

2. Retrieving Domain User Password Policy via PowerShell on Windows System — technical illustration 6

3. Windows system obtains domain user password policy via domain shared files

The test environment is the same as above

The domain user's password policy is stored in the default domain policy (Default Domain Policy) within the domain, with the guid {31B2F340-016D-11D2-945F-00C04FB984F9}

It can be viewed by accessing the domain shared folder \\SYSVOL

Prerequisite: Domain user credentials need to be provided

In this test environment, we obtained the password for the domain ordinary user testa as DomainUser123!

The general location is: \\\SYSVOL\\Policies\{31B2F340-016D-11D2-945F-00C04FB984F9}\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf

The location in the test environment is: \\192.168.1.1\SYSVOL\test.com\Policies\{31B2F340-016D-11D2-945F-00C04FB984F9}\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf

The output result is as shown in the figure below

3. Windows system obtains domain user password policy via domain shared files — technical illustration 7

0x05 Methods for Obtaining Domain User Password Policies within a Domain

---

Prerequisite: Access to a host within the domain has been obtained

The test environment is as shown in the figure below

0x05 Methods for Obtaining Domain User Password Policies within a Domain — technical illustration 8

1. Obtaining Domain User Password Policies via PowerShell

import-module .\Microsoft.ActiveDirectory.Management.dll
Get-ADDefaultDomainPasswordPolicy

2. Obtaining Domain User Password Policies via C++

Using the API NetUserModalsGet to retrieve domain user password policies

Structure USER_MODALS_INFO_0 stores global password information

Structure USER_MODALS_INFO_3 stores lockout information

Reference materials:

https://docs.microsoft.com/en-us/windows/win32/api/lmaccess/nf-lmaccess-netusermodalsget?redirectedfrom=MSDN

Based on the code in the reference materials, added functionality to query user lockout information. The code has been uploaded to GitHub at the following address:

An open-source project

The code uses the structures USER_MODALS_INFO_0 and USER_MODALS_INFO_3 respectively to query user password policies

The output result is shown in the figure below

2. Obtaining Domain User Password Policies via C++ — technical illustration 9

3. Obtain domain user password policies through domain shared files

The general location is: \\\SYSVOL\\Policies\{31B2F340-016D-11D2-945F-00C04FB984F9}\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf

The test environment location is: \\test.com\SYSVOL\test.com\Policies\{31B2F340-016D-11D2-945F-00C04FB984F9}\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf

0x06 Detection Methods

---

Domain user attributes include two useful pieces of information:

  • badPwdCount, which records the number of incorrect password attempts for the user
  • lastbadpasswordattempt, which records the last login time when an incorrect password was entered

During detection, we can query these two attributes to identify whether a password brute-force attack has occurred. The specific method is as follows:

1. Query directly on the domain controller

Powershell code is as follows:

Get-ADUser -Filter * -Properties *| select name,lastbadpasswordattempt,badpwdcount|fl

The output result is shown in the figure below

1. Query directly on the domain controller — technical illustration 10

2. On a host logged in by a regular domain user

(1) Using powerview

Get-NetUser | select name,badpasswordtime,badpwdcount

The output result is shown in the figure below

(1) Using powerview — technical illustration 11

(2) Using C++

An open-source project

The output result is shown in the figure below

(2) Using C++ — technical illustration 12

3. On a Kali system outside the domain

(1) Using ldapsearch

ldapsearch -x -H ldap://192.168.1.1:389 -D "CN=testa,CN=Users,DC=test,DC=com" -w DomainUser123! -b "DC=test,DC=com" -b "DC=test,DC=com" "(&(objectClass=user)(objectCategory=person))"|grep -E "cn:|badPwdCount|badPasswordTime"

The output result is shown in the figure below

(1) Using ldapsearch — technical illustration 13

Note:

If the password is entered correctly, then badPwdCount will be cleared

0x07 Summary

---

This article lists common methods for obtaining domain user password policies and describes how to identify password brute-force behavior in various environments.

Related Questions & Answers

What detection methods can defenders use to identify password brute-force attacks on domain users?

Query the user attributes `badPwdCount` (number of bad password attempts) and `lastbadpasswordattempt` (time of last failed login). On a domain controller, use PowerShell: `Get-ADUser -Filter * -Properties * | select name,lastbadpasswordattempt,badpwdcount`. On a domain-joined host, use PowerView's `Get-NetUser | select name,badpasswordtime,badpwdcount` or a custom C++ tool using the NetUserGetInfo API. For more detection approaches, see the detection section in [Penetration Basics - Obtaining Domain User Password Policies](/news/penetration-basics-obtaining-domain-user-password-policies) and [Penetration Basics - Bypassing SSH Logs](/news/penetration-basics-bypassing-ssh-logs) for log evasion techniques.

How can an attacker outside the domain obtain the domain password policy using LDAP and valid domain credentials?

If port 389 (LDAP) on the domain controller is accessible, use a tool like ldapsearch on Kali with a known domain user's credentials. The command is: `ldapsearch -x -H ldap://DC_IP:389 -D "CN=username,CN=Users,DC=domain,DC=com" -w password -b "DC=domain,DC=com" | grep replUpToDateVector -A 13`. The output contains the raw password policy values (e.g., maxPwdAge, lockoutDuration) which you then convert. This method is covered in detail in [Penetration Basics - Obtaining Domain User Password Policies](/news/penetration-basics-obtaining-domain-user-password-policies).

What are the key password policy attributes obtained from Active Directory, and how are their raw values converted to human-readable time?

Key attributes include maxPwdAge (maximum password age), minPwdLength (minimum password length), lockoutDuration (account lockout duration), lockoutThreshold (failed attempts before lockout), and lockOutObservationWindow (reset counter time). The raw values are in 100-nanosecond intervals; to convert to seconds, divide by 10,000,000. For example, maxPwdAge of -36288000000000 equals 3628800 seconds, or 42 days. Full conversion details are in the article [Penetration Basics - Obtaining Domain User Password Policies](/news/penetration-basics-obtaining-domain-user-password-policies).

Why is it important to obtain the domain user password policy before performing a password brute-force attack?

To avoid locking out user accounts during the attack, you must first know the account lockout threshold and lockout duration. If you brute-force without this knowledge, you could exceed the threshold and lock accounts, which not only fails the attack but also alerts defenders. For more details, see [Penetration Basics - Obtaining Domain User Password Policies](/news/penetration-basics-obtaining-domain-user-password-policies) and the follow-up [Penetration Basics - Brute-Forcing Domain User Passwords via LDAP Protocol](/news/penetration-basics-brute-forcing-domain-user-passwords-via-ldap-protocol).

Continue Reading