March 24, 2016
Part 5: Create a Complete Virtual Environment for Penetration Testing
March 24, 2016
Welcome back to the fifth part of the tutorial series. Today, we're going to learn how to compact a VDI into less disk space. I'm going to compact Windows Server VDI and then Sysprep it for ready-to-go imaging or future cloning.Tutorial Requirements:
Windows Server R 2012 machine (PART-2)
sDelete : https://technet.microsoft.com/en-us/sysinternals/sdelete.aspx
Defragmenting the VDI
Cleaning up the VDI
Compacting the VDI using sDelete
Sysprep Windows Server (Optional)
Step 1: Defragmentation of the VDI
- Open up Windows Server virtual machine and go to your C drive
- Right click on it and choose properties
- Go to the Tools tab and click on Optimization
- Choose C drive; click on optimize
NOTE: Defragmentation might take sometime. (Grab cup of coffee and WAITT)
When the defragmentation is done, click close
Step 2: Cleaning up the VDI
For this step, we're going to do some cleaning that will save us some space. First, we'll delete the Windows update file (unnecessary files), and second, we're going to use sDelete for more efficient cleaning.
1- Delete the Windows update files:
Open cmd or PowerShell as administrator and run services.msc
- When the Services window opens, go to Windows Updates services; right-click and choose Stop. If the service is already stopped, do not start it at this point.
- Now that the service is stopped, go to the C drive and navigate to Windows Folder >>>>
- Go to Software Distribution folder and delete it. The Software Distribution file is responsible for the Windows Updates.
Note: If the Windows Update service is running you won’t be able to delete it. So, that’s why we stopped the Windows Update service first.
- Click Yes
2- Download sDelete for addition cleaning:
NOTE: When you're trying to download the zip file, Internet Explorer will flash up a warning sign as below. The warning is resulting from the file format (zip). Zip files can be embedded with viruses or Trojans. However, this one is clean.
- In order to continue with the download of the program you have to add the site (https://download.sysinternals.com) to the trusted sites in Internet Explorer .
- Go to menu bar and click on Tools.
Switch to Security tab and choose Trusted Sites >>>> click on Sites.
Add the website URL to the trusted sites list. Once you're done, you'll able to download it.
Once you add the site to the trusted websites list, close the window and refresh the page. Then, try downloading the zip file.
Click on Save.
Now that you downloaded it, extract it using unzip or 7-zip compression utilities.
Right-click on the zip file and choose Extract all.
At this point, go back to the command line (cmd) and run the sDelete.exe. Use the commands below:
.sDelete -z c: (to run the exe file)
Click Agree to continue
The process of cleaning will start and it would take few minutes.
When it's done, the driver will be shown as a zapped drive.
- After finishing the above process, shut down the Windows system.
Step 3: Compacting the VDI
Once the machine is powered off, go to the host command line (your computer CMD or PowerShell) and navigate to virtualbox folder.
- When you get to the VirtualBox folder like the above picture, run the the compact command
Run : .virtualbox.exe modifyvdi (path of the vdi) -compact
C:Program FilesOracleVirtualBox>.VirtualBox.exe modifyvdi C:UsersZ33MAXVirtualBox VMsNew groupWindows Server R 2012 -compact
To find path of your VDI check (PART- 4)
If you run the above command and you did not get any errors, it means the compact was successful.
Step 4 : Sysprep Windows Server 2012 (optional)
Now that we have a cleaned compact VDI, we can go ahead and Sysprep the system for future cloning or imaging.
For those who do not know what Sysprep is (??), it's a System Preparation (Sysprep) tool prepares an installation of Windows for duplication, imaging or cloning. If you want to create an image with custom application or settings, Sysprep is the tool for it.
1 - Fire up Windows Server machine
2 - Open Cmd or PowerShell and run:
Run: C:WindowsSystem32Sysprep ./sysprep.exe
Shutdown options as Shutdown
Now we have a compact cleaned VDI, ready for future imaging or cloning.That's all for this tutorial, stay tuned for more.NOTE: Comments and suggestions on making better tutorials are welcomed!
@Z33MaxView Part 1: Create a Complete Virtual Environment for Penetration Testing – Part 1View Part 2: Create a Complete Virtual Environment for Penetration Testing - Part 2View Part 3: Create a Complete Virtual Environment for Penetration Testing - Part 3View Part 4: Create a Complete Virtual Environment for Penetration Testing - Part 4