Automate Active Directory(Installation(Packer)+Provisioning(Vagrant))

Hi Readers, Here we will be looking into automation of ad deployment. This challenge is part of Auror Project initiative by Zscaler’s Sudarshan Pisupati 🙏

Prerequisites:

  1. Packer
  2. Vagrant
  3. Virtualbox/Vmware Workstation(i have used VirtualBox for demonstration)
  4. Curiosity/Laziness

The Challenge/Goal:

Let’s create two machines, Machine A and Machine B.

Machine A (Domain controller)-

  1. Machine A is the domain controller
  2. Domain Name is “auror.local”
  3. Has DNS role
  4. Create a user “Adam” with password “Pass@123”

Machine B-

  1. Machine B is the machine to join to domain auror.local
  2. Machine B should have Chrome installed
  3. User Adam is configured as an administrator
  4. Firewall should be off
  5. Machine A and Machine B must be in the same subnet.

For example:

Machine A : 10.0.0.9, Machine B: 10.0.0.19

Test Cases

  • RDP into Machine B with user “Adam” should be successful
  • From Machine B as user Adam, the command “net use \\auror.local” should result in command completed successfully
  • Run script Powerview.ps1 function “Get-DomainUser” from Machine B should show Adam as a user
  • Chrome should be installed on Machine B

Let’s Start….

Brief introduction about packer(HCL2 format templates) and vagrant. Official definition-

Packer is an open source tool that enables you to create identical machine images for multiple platforms from a single source template. A common use case is creating “golden images” that teams across an organization can use in cloud infrastructure. in short it is similar to create docker images which can be uploaded to repositories, packer creates .box image files which is supported by different virtualization tools like vmware, vagrant etc.

Core components-

a) Source defines the initial image to use to create your customized image. Any defined source is reusable within build blocks.

b) Builders are responsible for creating machines from the base image, customizing the image as defined, and then creating a resulting image.

c) Provisioners use built-in and third-party integrations to install packages and configure the machine image.

  • Default one’s are file(The file Packer provisioner uploads files to machines built by Packer) and shell(as name suggests allows you to run os commands)
  • 3rd party- ansible ,chef, powershell, puppet

d) Post Processors- Post-processors run after the image is built by the builder and provisioned by the provisioner(s). These are optional, and they can be used to upload artifacts, re-package, or more. They are also defined in build block.

In our case our post processor block is -

e) Variables(as the name suggests)

Some commands-

Vagrant is a Virtual machine orchestration tool. It supports various vurtualization tools like vmware workstation, vmware esxi, virtualbox, Mictrosoft hyper-V etc. It supports different pulgins for these.

Refer to its docs for more-https://www.vagrantup.com/docs

Some commands-

Now let’s solve our challenge-

Step 1- Creating a vagrant box using packer

note- Make sure to clone this repo before proceeding(https://github.com/pswalia2u/TheAurorProject)

Your directory tree should look like this

Make sure you have these files before running packer build-

Windows_SERVER_2022_EVAL_x64FRE_en-us.iso or any other windows server (≥server 2016) iso

Autounattend.xml

vagrantfile-windows_2016.template

scripts

Now for next step we configure this .box file in vagrant config file.

Step 2- Provisioning using vagrant

Make sure you have these files before running packer build-

Vagrantfile(https://raw.githubusercontent.com/pswalia2u/TheAurorProject/main/Challenge_1/vagrant_project/Vagrantfile)

Wait for vagrant to provision both machines…

Finally we have 2 auto configured windows machines.

Running Testcases-

  • RDP into Machine B with user “Adam” should be successful
  • From Machine B as user Adam, the command “net use \\auror.local” should result in command completed successfully
  • Run script Powerview.ps1 function “Get-DomainUser” from Machine B should show Adam as a user
  • Chrome should be installed on Machine B

Whole challenge is pushed to https://github.com/pswalia2u/TheAurorProject/

References-

https://www.vagrantup.com/docs

https://www.packer.io/docs

https://github.com/StefanScherer/packer-windows

https://github.com/pswalia2u/TheAurorProject

Thanks for reading!!!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
n00🔑

n00🔑

135 Followers

Tries to understand computers. I know little bit of most things. Definitely not an expert. Usually plays HTB (ID-23862). https://www.linkedin.com/in/pswalia2u/