Auto Restore Virtualbox
March 18, 2009 1 Comment
For the security class I’m teaching we recently had a box to pwn. Problem is, they would sometimes get the address wrong and crash the virtual system. I probably would have just distributed the vdi, but not all of them have machines robust enough to run a vm, so I had to set something up.
First off, I gave the virtual vulnerable box a public IP by bridging.
auto eth0 iface eth0 inet manual auto br0 iface br0 inet static address 18.104.22.168 netmask 255.255.0.0 gateway 22.214.171.124 bridge_ports eth0 vbox0 vbox1 # The loopback network interface auto lo iface lo inet loopback
vbox0 lundeen br0 vbox1 lundeen br0
Awesome, now firewall rules work. In the vulnbox, I give myself an ip address. On the host, I set up very strict firewall rules using iptables.
Another big issue is auto-restore. Since the class often gets an address wrong, the vulnbox often crashes.
The following will shut the box down, revert to a snapshot, and turn it back on.
/usr/bin/VBoxManage controlvm vulnxp poweroff; sleep 5; /usr/bin/VBoxManage snapshot vulnxp discardcurrent -state sleep 10; /usr/bin/VBoxManage startvm vulnxp</pre>
Anyway, I put this in crontab to do every 20 minutes.
0,20,40 * * * * /path/to/virtualscript