clong / DetectionLab

Automate the creation of a lab environment complete with security tooling and logging best practices
MIT License
4.64k stars 987 forks source link

Add vsphere-iso Packer builder support #810

Closed Phat3 closed 2 years ago

Phat3 commented 2 years ago

Hi!

I added the support for creating images on vSphere environments using Packer.

The existing build chain for ESXi uses the vmware-iso Packer builder which is not fully compatible with vCenter. Specifically, I encountered the following bugs while deploying:

To solve those issues I ported the Packer build configuration to the Packer builder vsphere-iso which is fully compatible with vCenter (Tested on the latest version of vCenter).

This PR contains the following new files:

The command that needs to be used to run Packer is the same as the one used when building the images for ESXi but changing the paths to the new configuration files (e.g., PACKER_CACHE_DIR=../../Packer/packer_cache packer build -var-file variables_vsphere.json ubuntu2004_vsphere.json)

Signed-off-by: Sebastiano Mariani smariani@vmware.com

Phat3 commented 2 years ago

Hi @clong!

I had to add the 2 additional answer files because when deploying a Windows VM on vCenter the VMware Tools are not installed by default. Without VMware tools installed, the IP address of the VM is not correctly exposed through the APIs, and therefore Packet won't be able to get the IP and connect back to that VM and execute post-installation scripts.

In the 2 new answer files, I added the part to automatically install those tools. Specifically, those files are identical to DetectionLab//Packer/answer_files/10 and DetectionLab//Packer/answer_files/2016 respectively, except for the following part:

        <component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <RunSynchronous>
                <RunSynchronousCommand wcm:action="add">
                    <Order>1</Order>
                    <!-- Install VMware Tools from windows.iso -->
                    <Path>a:\vmtools.cmd</Path>
                    <WillReboot>Always</WillReboot>
                </RunSynchronousCommand>
            </RunSynchronous>
        </component>

This part executes a custom script I wrote to install the VMware tools (which is mounted at boot time as a floppy_file in the Packer config)

clong commented 2 years ago

Makes sense -- PR looks good, thank you!

clong commented 2 years ago

Makes sense -- PR looks good, thank you!