Ready to Start Your Career?

Part 5: Create a Complete Virtual Environment for Penetration Testing

Z33MAX 's profile image

By: Z33MAX

March 24, 2016

Part 5: Create a Complete Virtual Environment for Penetration Testing - CybraryWelcome 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: 

Tutorial Guidelines:

  • 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

15.jpg- Go to the Tools tab and click on Optimization

21.jpg

- Choose C drive; click on optimize

23.jpg

NOTE: Defragmentation might take sometime. (Grab cup of coffee and WAITT)

     24.JPG

 
  • When the defragmentation is done, click close

      25.jpg

 

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

    13.jpg

-  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.

       14.jpg

     -  Now that the service is stopped, go to the C drive and navigate to Windows Folder >>>>

             16.jpg

- 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.

 

           18.jpg

 

   18.jpg

     -  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.

39.jpg

 

- 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.

35.jpg

  • Switch to Security tab and choose Trusted Sites >>>> click on Sites.

36.jpg
  • Add the website URL to the trusted sites list. Once you're done, you'll able to download it.

40.jpg
  • 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.

41.JPG

  • Now that you downloaded it, extract it using unzip or 7-zip compression utilities.

Right-click on the zip file and choose Extract all.

42.jpg

43.JPG

  • At this point, go back to the command line (cmd) and run the sDelete.exe. Use the commands below:

    • cd Downloads

    • cd  sDelete.

    • .sDelete   -z   c: (to run the exe file)

 

44.JPG

  • Click Agree to continue

45.JPG

  • The process of cleaning will start and it would take few minutes.

47.JPG

  • When it's done, the driver will be shown as a zapped drive.

 

48.jpg

- After finishing the above process, shut down the Windows system.

49.JPG

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

Example:

C:Program FilesOracleVirtualBox>.VirtualBox.exe modifyvdi   C:UsersZ33MAXVirtualBox VMsNew groupWindows Server R 2012   -compact

Note:

  • 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.

Terminology:

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

50.JPG

  • Choose OOBE

  • Check Generalize

  • Shutdown options as Shutdown

 

51.png

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
Schedule Demo