Page 1 of 1

Command Script for running Hidden VM's

Posted: 14. Jul 2016, 16:48
by PeteyBrown
Hi,

In a different post I asked if there was a way of hiding the VM from the Virtualbox Manager screen as I work at various companies and run a VM for whatever company I am at and I wanted to hide the other companies VM's from appearing in the VM Manager screen as an employee was able to open another companies VM on my laptop.

To run a VM it has to be registered in the Virtualbox Manager Screen (there is no getting round this) so you can not hide the VM's unless you keep deleting (Remove Only) the VM from the Virtualbox Manager Screen

So I wrote this script to add my VM to the Virtualbox Manager Screen and then run it straight away, then uplond closing the VM Guest OS the script will then remove the entry in Virtualbox Manager Screen thus looking like you do not have that VM

Now I run a Linux Gateway VM which is configured to connect to a commercial VPN, then I will run my workstation VM (for what ever company I am at). The script does this in the correct order with necessary timeouts to make sure the gateway VM is running before the workstation VM starts. The script then monitors the workstation VM and as soon as I have powered down the workstaion VM at the end of the day (session) the script then sends the acpi power option to the Gateway OS and this then powers down the gateway VM then the script will Unregister both VM's from the Virtualbox Manager Screen thus they do not show.

For additional security, I am now keeping the VM's inside a Veracrypt encrypted File container so only when the container is open can the VM's be accessible, and the script resides inside the container as well so there is no indication on the HOST OS that these VM's exist. The encrypted file container is allocated drive Y: when it is opened.

The only downside is the command window is open while it is scanning the VM's but you can hide this as well by using chp, a piece of free open source software that allows you to run hidden command sessions.
http://www.commandline.co.uk/chp/

Code: Select all

    @ECHO OFF
    CLS
    SET "VMDIR=Y:\" 
    SET "VMG=My-Gateway"
    SET "VMW=My-Workstation"
    SET VBOXMANAGE="C:\Program Files\Oracle\VirtualBox\VBoxManage.exe"
   
    ECHO Starting VM's "%VMG%" at %VMDIR%%VMG%\%VMG%.vbox
	%VBOXMANAGE% registervm %VMDIR%%VMG%\%VMG%.vbox
	%VBOXMANAGE% startvm "%VMG%"
	Timeout /T 60
	ECHO Starting VM's "%VMW%" at %VMDIR%%VMW%\%VMW%.vbox
	%VBOXMANAGE% registervm %VMDIR%%VMW%\%VMW%.vbox
	%VBOXMANAGE% startvm "%VMW%"
	Timeout /T 60
	ECHO Monitoring VM "%VMG%" and "%VMW%"
    
    :check_running
	CLS
	ECHO Monitoring VM "%VMG%" and "%VMW%"
	Timeout /T 30
	DEL %TEMP%\runningvms.txt
    %VBOXMANAGE% list runningvms > %TEMP%\runningvms.txt
    FIND "%VMW%" %TEMP%\runningvms.txt > nul
    IF %errorlevel% EQU 0 (
        SET VMWRUNNING=1
		ECHO VM "%VMW%" is Running
    ) ELSE (
        SET VMWRUNNING=0
		ECHO VM "%VMW%" is NOT Running
    )
       	 
    IF %VMWRUNNING% EQU 1 (
        GOTO check_running
    )
     
    
    :end
	DEL %TEMP%\runningvms.txt
    ECHO "%VMG%" Shutting Down
	%VBOXMANAGE% controlvm "%VMG%" acpipowerbutton
	Timeout /T 30
	ECHO "%VMG%" Unregistering
	%VBOXMANAGE% unregistervm "%VMG%"
	ECHO "%VMW%" Unregistering
	%VBOXMANAGE% unregistervm "%VMW%"
	Exit