# Creating an Active Directory Lab Environment in Azure for Penetration Testing

![](https://cdn-images-1.medium.com/max/800/1*FSvc6NqJnZAGihdQhUVWvA.png)

## Introduction <a href="#eacb" id="eacb"></a>

Active Directory is one of the most commonly used technologies in a corporate environment with 95% of fortune 1000 companies utilizing it. I was always intimidated by Active Directory because I didn’t know how to learn about it without potentially breaking it. I decided to do some research on how to create a lab so that I could have absolute freedom to break and troubleshoot it in any way I want.

Another reason for creating this lab was to gain more experience with Azure. I am fairly comfortable working in AWS since I use it for my own personal projects, however, I have not given Microsoft Azure the same amount of attention.

## Step 1: Creating a resource group <a href="#d44f" id="d44f"></a>

The first step we need to take is creating an Azure resource group. A resource group is a container that holds related resources for our Azure lab.

To create a resource group click on the ‘resource group’ tab and fill in the details relevant to your location and lab

![](https://cdn-images-1.medium.com/max/800/1*2wbxN4Xq3b4-6iBHdNfX1A.png)

## Step 2: Creating a virtual network <a href="#c714" id="c714"></a>

Creating a virtual network within Azure is important because it will allow all our machines to sit on the same network and communicate with each other.

Creating a virtual network in Azure is trivial. Simply click the ‘Virtual Network’ tab and create a new one. Ensure you place your virtual network in the resource group you created in step one.

![](https://cdn-images-1.medium.com/max/800/1*_rVlVCTNw-blRYZE--iavw.png)

## Step 3: Creating and configuring the domain controller <a href="#e8f5" id="e8f5"></a>

A domain controller (DC) is the brain of an Active Directory environment. The domain controller handles authentication, stores user account information, and enforces security policies on a Windows domain.

To create the domain controller I created a virtual machine in Azure running Windows Server 2019 Datacenter-Gen1. I decided to run this on a Standard B1ms virtual machine (One of the cheapest machines Azure offers) because this lab is just for testing and I don’t need a high end machine for simple testing purposes. For the sake of brevity I am just showing the review tab.

![](https://cdn-images-1.medium.com/max/800/1*N26zZgDpGE-ebkbdk--cjg.png)

Once the machine is done being created, download the RDP file and connect to the machine. (I have found the best RDP program on Linux is Remmina). From here the windows server manager should pop up. Click **Add roles and features**

![](https://cdn-images-1.medium.com/max/800/1*pds7YmMUcVJxdRCk7rZSWQ.png)

Next, Click through the add roles and features wizard until you get to the **Server Roles** tab. From here check the **Active Directory Domain Services** role

![](https://cdn-images-1.medium.com/max/800/1*JFRRt5UCbvtUzyFoGo36Qw.png)

Next, Click through to the end of the install wizard and then click install.

![](https://cdn-images-1.medium.com/max/800/1*kqeFY_9Bv6KYz-oiFIHpxA.png)

When Windows is done installing the new role, you will get a notification flag in the upper right of your server manager window. Click it and click **Promote this server to a domain controller.**

![](https://cdn-images-1.medium.com/max/800/1*KFrFsnC6_JnjWPo59hYTTQ.png)

Next we need to add the domain controller to a new forest. One AD instance can contain multiple domains. A forest is the highest level container and contains all the domains.

![](https://cdn-images-1.medium.com/max/800/1*8qc8Sn6gotKyThhttGePWQ.png)

Click **Add a new forest** and type your root domain name. It is best practice to add .local to the end of your root domain.

![](https://cdn-images-1.medium.com/max/800/1*1LCss3fiza07lRToYYoBXQ.png)

Next, **Create a password for directory services restore mode** then Click through the the rest of the pages and install the AD domain services and restart your virtual machine

![](https://cdn-images-1.medium.com/max/800/1*TYkfAZPMqNDhpKhCHeFQhw.png)

After your machine has rebooted, open the server manager again and click add roles and features. Click through to the Server Roles tab and click **Active Directory Certificate services** then click through to the end of the wizard and install the features.

![](https://cdn-images-1.medium.com/max/800/1*nLBWroVYjb36cm93B5daUg.png)

## Step 4: Adding users and computers <a href="#id-68e0" id="id-68e0"></a>

To add users and computers go

![](https://cdn-images-1.medium.com/max/800/1*VdILRg3SSaL4Yc8N8eY0uA.png)

From there adding a new user is simple. Right click the Users folder and select User.

![](https://cdn-images-1.medium.com/max/800/1*jSuzoTErYZPu_N1j3VMJ5Q.png)

## Step 5: Creating virtual machines for users to log in to <a href="#e955" id="e955"></a>

Adding a virtual machine that we will later connect to the domain will allow each user to login to their own machine. This simulates having a single physical computer for each employee in an office environment.

In Azure create another virtual machine, ensuring it is in the ADLab resource group. Again, I have chosen a standard B1ms virtual machine as performance is not really a concern for testing purposes.

![](https://cdn-images-1.medium.com/max/800/1*kUzwwqIiHU14Dy6DJNKgFw.png)

You can create as many machines as you want but for my purposes I chose to only create two users so I will only be adding two workstations.

## Step 6: Connecting virtual machines to the domain controller <a href="#id-7aa5" id="id-7aa5"></a>

Connecting the virtual machines to the domain will allow our machines to be managed by the domain controller.

The first step is to change the virtual machine’s DNS server to the domain controller.

![](https://cdn-images-1.medium.com/max/800/1*DQ6v6Q7EEmNhEBrIbRBOLg.png)

After rebooting, go to the Access work or school settings in windows, click Add and then click **Join this device to a local active directory domain**

![](https://cdn-images-1.medium.com/max/800/1*oxTYsqkaxcyAKIpONmc06g.png)

Next, type the name of your domain and login using the administrator account.

![](https://cdn-images-1.medium.com/max/800/1*_ofwQ1id8Oo2rDwPhtB6Tw.png)

Finally enter the credentials of the user that will be using the computer. In this case it will be the user Olfrid Battle-Born. Now restart the computer

![](https://cdn-images-1.medium.com/max/800/1*eFrGmR6BA3-ocd_OS4ncmg.png)

To verify the user was successfully added to the domain we can check the domain controller and see the Computer Olfrids-Desktop appears in our computers tab.

![](https://cdn-images-1.medium.com/max/800/1*W2l8MkumS-jM8Kt4el7EPA.png)

## Bonus Step: Adding a Kali Linux machine to the network to practice pentesting active directory <a href="#bddc" id="bddc"></a>

The main goal of this lab was to understand how Active Directory works but we can take this one step further by adding a new Kali Linux machine to the network for pentesting.

To add a Kali machine to the network simply create a new virtual machine in the ADLabNet virtual network and put it in the same resource group as the AD network.

![](https://cdn-images-1.medium.com/max/800/1*tBkoTb1tD1gPiGQtEIiwUA.png)

Once we create this machine we can SSH into it from our local Linux machine and run an nmap scan on the active hosts

![](https://cdn-images-1.medium.com/max/800/1*mJC3vGJiza49sKbGuAu9pg.png)

## Conclusion <a href="#id-8f6d" id="id-8f6d"></a>

After spending many hours creating and playing around in this lab I can say that creating this lab was a fantastic way for me to learn how Active Directory and Azure works. Not only did I learn a lot but the experience gained from physically setting up the environment is invaluable. Overall this entire experiment only cost a total of $.43 which is nearly unbelievableTotal Cost of Lab

![](https://cdn-images-1.medium.com/max/800/1*QP9ggkvhvhwDHQkrQNiL3A.png)

Here are some of the resources I used to help me set up this lab

<https://www.youtube.com/watch?v=hZ2QiiHyTnU>

<https://www.dnsstuff.com/active-directory-best-practices>

<https://www.youtube.com/watch?v=xftEuVQ7kY0>

[https://medium.com/@kamran.bilgrami/ethical-hacking-lessons-building-free-active-directory-lab-in-azure-6c67a7eddd7F](https://medium.com/@kamran.bilgrami/ethical-hacking-lessons-building-free-active-directory-lab-in-azure-6c67a7eddd7f)

<https://www.comparitech.com/net-admin/active-directory-step-by-step-tutorial/>
