2 Created on Nov 19, 2013
8 from subprocess import Popen, PIPE, call, STARTUPINFO, _subprocess
12 from cygwin import Cygwin
13 from environment import Environment
21 from opensecurity_util import logger, setupLogger, OpenSecurityException
27 class VMManagerException(Exception):
28 def __init__(self, value):
31 return repr(self.value)
38 def __init__(self, vendorid, productid, revision):
39 self.vendorid = vendorid.lower()
40 self.productid = productid.lower()
41 self.revision = revision.lower()
44 def __eq__(self, other):
45 return self.vendorid == other.vendorid and self.productid == other.productid and self.revision == other.revision
48 return hash(self.vendorid) ^ hash(self.productid) ^ hash(self.revision)
51 return "VendorId = \'" + str(self.vendorid) + "\' ProductId = \'" + str(self.productid) + "\' Revision = \'" + str(self.revision) + "\'"
53 #def __getitem__(self, item):
54 # return self.coords[item]
56 class VMManager(object):
57 vmRootName = "SecurityDVM"
58 systemProperties = None
64 self.systemProperties = self.getSystemProperties()
65 self.machineFolder = self.systemProperties["Default machine folder"]
67 self.rsdHandler = DeviceHandler(self)
68 self.rsdHandler.start()
73 if VMManager._instance == None:
74 VMManager._instance = VMManager()
75 return VMManager._instance
78 if self.rsdHandler != None:
79 self.rsdHandler.stop()
80 self.rsdHandler.join()
81 drives = self.getNetworkDrives()
82 for drive in drives.keys():
83 self.unmapNetworkDrive(drive)
84 for vm in self.listSDVM():
88 # return hosty system properties
89 def getSystemProperties(self):
90 result = checkResult(Cygwin.vboxExecute('list systemproperties'))
93 props = dict((k.strip(),v.strip().strip('"')) for k,v in (line.split(':', 1) for line in result[1].strip().splitlines()))
96 # return the folder containing the guest VMs
97 def getMachineFolder(self):
98 return self.machineFolder
100 # list all existing VMs registered with VBox
102 result = checkResult(Cygwin.vboxExecute('list vms'))[1]
103 vms = list(k.strip().strip('"') for k,_ in (line.split(' ') for line in result.splitlines()))
107 def listRunningVMS(self):
108 result = checkResult(Cygwin.vboxExecute('list runningvms'))[1]
109 vms = list(k.strip().strip('"') for k,_ in (line.split(' ') for line in result.splitlines()))
112 # list existing SDVMs
117 if vm.startswith(self.vmRootName) and vm != self.vmRootName:
121 # generate valid (not already existing SDVM name). necessary for creating a new VM
122 def generateSDVMName(self):
124 for i in range(0,999):
125 if(not self.vmRootName+str(i) in vms):
126 return self.vmRootName+str(i)
129 # check if the device is mass storage type
131 def isMassStorageDevice(device):
132 keyname = 'SYSTEM\CurrentControlSet\Enum\USB' + '\VID_' + device.vendorid+'&'+'PID_'+ device.productid
133 key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyname)
134 #subkeys = _winreg.QueryInfoKey(key)[0]
135 #for i in range(0, subkeys):
136 # print _winreg.EnumKey(key, i)
137 devinfokeyname = _winreg.EnumKey(key, 0)
138 _winreg.CloseKey(key)
140 devinfokey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyname+'\\'+devinfokeyname)
141 value = _winreg.QueryValueEx(devinfokey, 'SERVICE')[0]
142 _winreg.CloseKey(devinfokey)
144 return 'USBSTOR' in value
146 # return the RSDs connected to the host
148 def getConnectedRSDS():
149 results = checkResult(Cygwin.vboxExecute('list usbhost'))[1]
150 results = results.split('Host USB Devices:')[1].strip()
152 items = list( "UUID:"+result for result in results.split('UUID:') if result != '')
156 for line in item.splitlines():
158 k,v = line[:line.index(':')].strip(), line[line.index(':')+1:].strip()
161 #if 'Product' in props.keys() and props['Product'] == 'Mass Storage':
163 usb_filter = USBFilter( re.search(r"\((?P<vid>[0-9A-Fa-f]+)\)", props['VendorId']).groupdict()['vid'],
164 re.search(r"\((?P<pid>[0-9A-Fa-f]+)\)", props['ProductId']).groupdict()['pid'],
165 re.search(r"\((?P<rev>[0-9A-Fa-f]+)\)", props['Revision']).groupdict()['rev'] )
166 if VMManager.isMassStorageDevice(usb_filter):
167 rsds[props['UUID']] = usb_filter;
168 logger.debug(usb_filter)
171 # return the RSDs attached to all existing SDVMs
172 def getAttachedRSDs(self):
173 vms = self.listSDVM()
174 attached_devices = dict()
176 rsd_filter = self.getUSBFilter(vm)
177 if rsd_filter != None:
178 attached_devices[vm] = rsd_filter
179 return attached_devices
181 # configures hostonly networking and DHCP server. requires admin rights
182 def configureHostNetworking(self):
183 #cmd = 'vboxmanage list hostonlyifs'
184 #Cygwin.vboxExecute(cmd)
185 #cmd = 'vboxmanage hostonlyif remove \"VirtualBox Host-Only Ethernet Adapter\"'
186 #Cygwin.vboxExecute(cmd)
187 #cmd = 'vboxmanage hostonlyif create'
188 #Cygwin.vboxExecute(cmd)
189 checkResult(Cygwin.vboxExecute('hostonlyif ipconfig \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.1 --netmask 255.255.255.0'))
190 #cmd = 'vboxmanage dhcpserver add'
191 #Cygwin.vboxExecute(cmd)
192 checkResult(Cygwin.vboxExecute('dhcpserver modify --ifname \"VirtualBox Host-Only Ethernet Adapter\" --ip 192.168.56.100 --netmask 255.255.255.0 --lowerip 192.168.56.101 --upperip 192.168.56.200'))
194 def isSDVMExisting(self, vm_name):
195 sdvms = self.listSDVM()
196 return vm_name in sdvms
198 #create new virtual machine instance based on template vm named SecurityDVM (\SecurityDVM\SecurityDVM.vmdk)
199 def createVM(self, vm_name):
200 if self.isSDVMExisting(vm_name):
202 #remove eventually existing SDVM folder
203 machineFolder = Cygwin.cygPath(self.machineFolder)
204 checkResult(Cygwin.bashExecute('/usr/bin/rm -rf \\\"' + machineFolder + '/' + vm_name + '\\\"'))
205 hostonly_if = self.getHostOnlyIFs()
206 checkResult(Cygwin.vboxExecute('createvm --name ' + vm_name + ' --ostype Debian --register'))
207 checkResult(Cygwin.vboxExecute('modifyvm ' + vm_name + ' --memory 512 --vram 10 --cpus 1 --usb on --usbehci on --nic1 hostonly --hostonlyadapter1 \"' + hostonly_if['Name'] + '\" --nic2 nat'))
208 checkResult(Cygwin.vboxExecute('storagectl ' + vm_name + ' --name SATA --add sata --portcount 2'))
211 # attach storage image to controller
212 def storageAttach(self, vm_name):
213 if self.isStorageAttached(vm_name):
214 self.storageDetach(vm_name)
215 checkResult(Cygwin.vboxExecute('storageattach ' + vm_name + ' --storagectl SATA --port 0 --device 0 --type hdd --medium \"'+ self.machineFolder + '\SecurityDVM\SecurityDVM.vmdk\"'))
217 # return true if storage is attached
218 def isStorageAttached(self, vm_name):
219 info = self.getVMInfo(vm_name)
220 return (info['SATA-0-0']!='none')
222 # detach storage from controller
223 def storageDetach(self, vm_name):
224 if self.isStorageAttached(vm_name):
225 checkResult(Cygwin.vboxExecute('storageattach ' + vm_name + ' --storagectl SATA --port 0 --device 0 --type hdd --medium none'))
227 def changeStorageType(self, filename, storage_type):
228 checkResult(Cygwin.vboxExecute('modifyhd \"' + filename + '\" --type ' + storage_type))
230 # list storage snaphots for VM
231 def updateTemplate(self):
234 self.poweroffVM('SecurityDVM')
235 self.waitShutdown('SecurityDVM')
238 self.genCertificateISO('SecurityDVM')
239 self.attachCertificateISO('SecurityDVM')
241 self.storageDetach('SecurityDVM')
242 results = checkResult(Cygwin.vboxExecute('list hdds'))[1]
243 results = results.replace('Parent UUID', 'Parent')
244 items = list( "UUID:"+result for result in results.split('UUID:') if result != '')
249 for line in item.splitlines():
251 k,v = line[:line.index(':')].strip(), line[line.index(':')+1:].strip()
253 snaps[props['UUID']] = props
256 template_storage = self.machineFolder + '\SecurityDVM\SecurityDVM.vmdk'
260 for hdd in snaps.values():
261 if hdd['Location'] == template_storage:
262 template_uuid = hdd['UUID']
263 logger.debug('found parent uuid ' + template_uuid)
266 for hdd in snaps.values():
267 if hdd['Parent'] == template_uuid:
268 #template_uuid = hdd['UUID']
269 logger.debug('removing snapshot ' + hdd['UUID'])
270 checkResult(Cygwin.vboxExecute('closemedium disk {' + hdd['UUID'] + '} --delete'))#[1]
271 # parse result 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
273 self.changeStorageType(template_storage,'normal')
274 self.storageAttach('SecurityDVM')
275 self.startVM('SecurityDVM')
276 self.waitStartup('SecurityDVM')
277 checkResult(Cygwin.sshExecute('"sudo apt-get -y update"', VMManager.getHostOnlyIP('SecurityDVM'), 'osecuser', Cygwin.cygPath(self.machineFolder) + '/' + 'SecurityDVM' + '/dvm_key'))
278 checkResult(Cygwin.sshExecute('"sudo apt-get -y upgrade"', VMManager.getHostOnlyIP('SecurityDVM'), 'osecuser', Cygwin.cygPath(self.machineFolder) + '/' + 'SecurityDVM' + '/dvm_key'))
279 #self.stopVM('SecurityDVM')
280 self.hibernateVM('SecurityDVM')
281 self.waitShutdown('SecurityDVM')
282 self.storageDetach('SecurityDVM')
283 self.changeStorageType(template_storage,'immutable')
284 self.storageAttach('SecurityDVM')
285 self.rsdHandler = DeviceHandler(self)
286 self.rsdHandler.start()
288 #remove VM from the system. should be used on VMs returned by listSDVMs
289 def removeVM(self, vm_name):
290 logger.info('Removing ' + vm_name)
291 checkResult(Cygwin.vboxExecute('unregistervm ' + vm_name + ' --delete'))
292 machineFolder = Cygwin.cygPath(self.machineFolder)
293 checkResult(Cygwin.bashExecute('/usr/bin/rm -rf \\\"' + machineFolder + '/' + vm_name + '\\\"'))
296 def startVM(self, vm_name):
297 logger.info('Starting ' + vm_name)
298 result = checkResult(Cygwin.vboxExecute('startvm ' + vm_name + ' --type headless' ))
299 while 'successfully started' not in result[1]:
300 logger.error("Failed to start SDVM: " + vm_name + " retrying")
302 result = checkResult(Cygwin.vboxExecute('startvm ' + vm_name + ' --type headless'))
305 # return wether VM is running or not
306 def isVMRunning(self, vm_name):
307 return vm_name in self.listRunningVMS()
310 def stopVM(self, vm_name):
311 logger.info('Sending shutdown signal to ' + vm_name)
312 checkResult(Cygwin.sshExecute( '"sudo shutdown -h now"', VMManager.getHostOnlyIP(vm_name), 'osecuser', Cygwin.cygPath(self.machineFolder) + '/' + vm_name + '/dvm_key' ))
315 def hibernateVM(self, vm_name):
316 logger.info('Sending hibernate-disk signal to ' + vm_name)
317 checkResult(Cygwin.sshExecute( '"sudo hibernate-disk&"', VMManager.getHostOnlyIP(vm_name), 'osecuser', Cygwin.cygPath(self.machineFolder) + '/' + vm_name + '/dvm_key', wait_return=False))
320 def poweroffVM(self, vm_name):
321 if not self.isVMRunning(vm_name):
323 logger.info('Powering off ' + vm_name)
324 return checkResult(Cygwin.vboxExecute('controlvm ' + vm_name + ' poweroff'))
326 #list the hostonly IFs exposed by the VBox host
328 def getHostOnlyIFs():
329 result = Cygwin.vboxExecute('list hostonlyifs')[1]
332 props = dict((k.strip(),v.strip().strip('"')) for k,v in (line.split(':', 1) for line in result.strip().splitlines()))
335 # return the hostOnly IP for a running guest or the host
337 def getHostOnlyIP(vm_name):
339 logger.info('Gettting hostOnly IP address for Host')
340 return VMManager.getHostOnlyIFs()['IPAddress']
342 logger.info('Gettting hostOnly IP address ' + vm_name)
343 result = checkResult(Cygwin.vboxExecute('guestproperty get ' + vm_name + ' /VirtualBox/GuestInfo/Net/0/V4/IP'))
347 if result.startswith('No value set!'):
349 return result[result.index(':')+1:].strip()
351 # attach removable storage device to VM by provision of filter
352 def attachRSD(self, vm_name, rsd_filter):
353 return checkResult(Cygwin.vboxExecute('usbfilter add 0 --target ' + vm_name + ' --name OpenSecurityRSD --vendorid ' + rsd_filter.vendorid + ' --productid ' + rsd_filter.productid + ' --revision ' + rsd_filter.revision))
355 # detach removable storage from VM by
356 def detachRSD(self, vm_name):
357 return checkResult(Cygwin.vboxExecute('usbfilter remove 0 --target ' + vm_name))
359 # return the description set for an existing VM
360 def getVMInfo(self, vm_name):
361 results = checkResult(Cygwin.vboxExecute('showvminfo ' + vm_name + ' --machinereadable'))[1]
362 props = dict((k.strip().strip('"'),v.strip().strip('"')) for k,v in (line.split('=', 1) for line in results.splitlines()))
365 # return the configured USB filter for an existing VM
366 def getUSBFilter(self, vm_name):
367 props = self.getVMInfo(vm_name)
368 keys = set(['USBFilterVendorId1', 'USBFilterProductId1', 'USBFilterRevision1'])
369 keyset = set(props.keys())
371 if keyset.issuperset(keys):
372 usb_filter = USBFilter(props['USBFilterVendorId1'], props['USBFilterProductId1'], props['USBFilterRevision1'])
375 #generates ISO containing authorized_keys for use with guest VM
376 def genCertificateISO(self, vm_name):
377 machineFolder = Cygwin.cygPath(self.machineFolder)
378 # remove .ssh folder if exists
379 checkResult(Cygwin.bashExecute('/usr/bin/rm -rf \\\"' + machineFolder + '/' + vm_name + '/.ssh\\\"'))
380 # remove .ssh folder if exists
381 checkResult(Cygwin.bashExecute('/usr/bin/rm -rf \\\"' + machineFolder + '/' + vm_name + '/dvm_key\\\"'))
382 # create .ssh folder in vm_name
383 checkResult(Cygwin.bashExecute('/usr/bin/mkdir -p \\\"' + machineFolder + '/' + vm_name + '/.ssh\\\"'))
384 # generate dvm_key pair in vm_name / .ssh
385 checkResult(Cygwin.bashExecute('/usr/bin/ssh-keygen -q -t rsa -N \\\"\\\" -C \\\"' + vm_name + '\\\" -f \\\"' + machineFolder + '/' + vm_name + '/.ssh/dvm_key\\\"'))
386 # move out private key
387 checkResult(Cygwin.bashExecute('/usr/bin/mv \\\"' + machineFolder + '/' + vm_name + '/.ssh/dvm_key\\\" \\\"' + machineFolder + '/' + vm_name + '\\\"'))
388 # set permissions for private key
389 checkResult(Cygwin.bashExecute('/usr/bin/chmod 500 \\\"' + machineFolder + '/' + vm_name + '/dvm_key\\\"'))
390 # rename public key to authorized_keys
391 checkResult(Cygwin.bashExecute('/usr/bin/mv \\\"' + machineFolder + '/' + vm_name + '/.ssh/dvm_key.pub\\\" \\\"' + machineFolder + '/' + vm_name + '/.ssh/authorized_keys\\\"'))
392 # set permissions for authorized_keys
393 checkResult(Cygwin.bashExecute('/usr/bin/chmod 500 \\\"' + machineFolder + '/' + vm_name + '/.ssh/authorized_keys\\\"'))
394 # generate iso image with .ssh/authorized keys
395 checkResult(Cygwin.bashExecute('/usr/bin/genisoimage -J -R -o \\\"' + machineFolder + '/' + vm_name + '/'+ vm_name + '.iso\\\" \\\"' + machineFolder + '/' + vm_name + '/.ssh\\\"'))
397 # attaches generated ssh public cert to guest vm
398 def attachCertificateISO(self, vm_name):
399 result = checkResult(Cygwin.vboxExecute('storageattach ' + vm_name + ' --storagectl SATA --port 1 --device 0 --type dvddrive --mtype readonly --medium \"' + self.machineFolder + '\\' + vm_name + '\\'+ vm_name + '.iso\"'))
402 # wait for machine to come up
403 def waitStartup(self, vm_name, timeout_ms = 30000):
404 checkResult(Cygwin.vboxExecute('guestproperty wait ' + vm_name + ' SDVMStarted --timeout ' + str(timeout_ms) + ' --fail-on-timeout'))
405 return VMManager.getHostOnlyIP(vm_name)
407 # wait for machine to shutdown
408 def waitShutdown(self, vm_name):
409 while vm_name in self.listRunningVMS():
413 # handles browsing request
414 def handleBrowsingRequest(self):
415 handler = BrowsingHandler(self)
419 #Small function to check the availability of network resource.
420 #def isAvailable(self, path):
421 #return os.path.exists(path)
422 #result = Cygwin.cmdExecute('IF EXIST "' + path + '" echo YES')
423 #return string.find(result[1], 'YES',)
425 #Small function to check if the mention location is a directory
426 def isDirectory(self, path):
427 result = checkResult(Cygwin.cmdExecute('dir ' + path + ' | FIND ".."'))
428 return string.find(result[1], 'DIR',)
430 def mapNetworkDrive(self, drive, networkPath, user, password):
431 self.unmapNetworkDrive(drive)
432 #Check for drive availability
433 if os.path.exists(drive):
434 logger.error("Drive letter is already in use: " + drive)
436 #Check for network resource availability
438 while not os.path.exists(networkPath):
442 logger.info("Path not accessible: " + networkPath + " retrying")
446 command = 'USE ' + drive + ' ' + networkPath + ' /PERSISTENT:NO'
448 command += ' ' + password + ' /User' + user
450 #TODO: Execute 'NET USE' command with authentication
451 result = checkResult(Cygwin.execute('C:\\Windows\\system32\\net.exe', command))
452 if string.find(result[1], 'successfully',) == -1:
453 logger.error("Failed: NET " + command)
457 def unmapNetworkDrive(self, drive):
458 drives = self.getNetworkDrives()
459 if drive not in drives.keys():
461 result = checkResult(Cygwin.execute('C:\\Windows\\system32\\net.exe', 'USE ' + drive + ' /DELETE /YES'))
462 if string.find(str(result[1]), 'successfully',) == -1:
463 logger.error(result[2])
467 def getNetworkDrives(self):
468 ip = VMManager.getHostOnlyIP(None)
469 ip = ip[:ip.rindex('.')]
471 result = checkResult(Cygwin.execute('C:\\Windows\\system32\\net.exe', 'USE'))
472 for line in result[1].splitlines():
475 drives[parts[1]] = parts[2]
478 def genNetworkDrive(self):
479 network_drives = self.getNetworkDrives()
480 logical_drives = VMManager.getLogicalDrives()
481 drives = list(map(chr, range(68, 91)))
483 if drive+':' not in network_drives and drive not in logical_drives:
486 def getNetworkDrive(self, vm_name):
487 ip = self.getHostOnlyIP(vm_name)
488 result = checkResult(Cygwin.execute('C:\\Windows\\system32\\net.exe', 'USE'))
489 for line in result[1].splitlines():
490 if line != None and ip in line:
494 def getLogicalDrives():
495 drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives()
496 return list(itertools.compress(string.ascii_uppercase, map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1])))
499 def getDriveType(drive):
500 return ctypes.cdll.kernel32.GetDriveTypeW(u"%s:\\"%drive)
503 def getVolumeInfo(drive):
504 volumeNameBuffer = ctypes.create_unicode_buffer(1024)
505 fileSystemNameBuffer = ctypes.create_unicode_buffer(1024)
507 max_component_length = None
508 file_system_flags = None
510 rc = ctypes.cdll.kernel32.GetVolumeInformationW(
511 #ctypes.c_wchar_p("F:\\"),
514 ctypes.sizeof(volumeNameBuffer),
516 max_component_length,
518 fileSystemNameBuffer,
519 ctypes.sizeof(fileSystemNameBuffer)
522 return volumeNameBuffer.value, fileSystemNameBuffer.value
524 def checkResult(result):
526 logger.error('Command failed:' + ''.join(result[2]))
527 raise OpenSecurityException('Command failed:' + ''.join(result[2]))
532 # handles browsing request
533 class BrowsingHandler(threading.Thread):
536 def __init__(self, vmmanager):
537 threading.Thread.__init__(self)
543 new_sdvm = self.vmm.generateSDVMName()
544 self.vmm.createVM(new_sdvm)
545 self.vmm.storageAttach(new_sdvm)
546 self.vmm.genCertificateISO(new_sdvm)
547 self.vmm.attachCertificateISO(new_sdvm)
548 self.vmm.startVM(new_sdvm)
549 new_ip = self.vmm.waitStartup(new_sdvm)
550 drive = self.vmm.genNetworkDrive()
552 self.vmm.mapNetworkDrive(drive, '\\\\' + new_ip + '\\Download', None, None)
553 #browser = '/usr/bin/iceweasel'
554 #browser = '/usr/bin/midori'
555 #browser = '/usr/bin/chromium '
556 browser = '\\\"/usr/bin/chromium; pidof dbus-launch | xargs kill\\\"'
559 #if Cygwin.is_X11_running()==True:
560 #result = checkResult(Cygwin.bashExecute('DISPLAY=:0 xhost '+new_ip))
561 result = checkResult(Cygwin.sshExecuteX11(browser, new_ip, 'osecuser', Cygwin.cygPath(self.vmm.getMachineFolder()) + '/' + new_sdvm + '/dvm_key'))
563 logger.error("BrowsingHandler failed. Cleaning up")
565 self.vmm.unmapNetworkDrive(drive)
566 self.vmm.poweroffVM(new_sdvm)
567 self.vmm.removeVM(new_sdvm)
569 class DeviceHandler(threading.Thread):
574 def __init__(self, vmmanger):
575 threading.Thread.__init__(self)
582 self.connectedRSDs = dict()
584 tmp_rsds = self.vmm.getConnectedRSDS()
586 self.attachedRSDs = self.vmm.getAttachedRSDs()
587 for vm_name in self.attachedRSDs.keys():
588 if self.attachedRSDs[vm_name] not in tmp_rsds.values():
589 drive = self.vmm.getNetworkDrive(vm_name)
590 self.vmm.unmapNetworkDrive(drive)
591 #self.stopVM(vm_name)
592 self.vmm.detachRSD(vm_name)
593 self.vmm.poweroffVM(vm_name)
594 self.vmm.removeVM(vm_name)
598 if tmp_rsds.keys() == self.connectedRSDs.keys():
599 logger.debug("Nothing's changed. sleep(3)")
603 logger.info("Something's changed")
604 self.connectedRSDs = tmp_rsds
608 #create new vm for attached device if any
609 self.attachedRSDs = self.vmm.getAttachedRSDs()
610 self.connectedRSDs = self.vmm.getConnectedRSDS()
613 for connected_device in self.connectedRSDs.values():
614 if (self.attachedRSDs and False) or (connected_device not in self.attachedRSDs.values()):
615 new_sdvm = self.vmm.generateSDVMName()
616 self.vmm.createVM(new_sdvm)
617 self.vmm.storageAttach(new_sdvm)
618 self.vmm.attachRSD(new_sdvm, connected_device)
619 self.vmm.startVM(new_sdvm)
620 new_ip = self.vmm.waitStartup(new_sdvm)
621 drive = self.vmm.genNetworkDrive()
623 self.vmm.mapNetworkDrive(drive, '\\\\' + new_ip + '\\USB', None, None)
625 if __name__ == '__main__':
626 #man = VMManager.getInstance()
628 #print man.getConnectedRSDs()
629 #print man.getNetworkDrives()
630 #man.genNetworkDrive()
631 #drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives()
632 #print list(itertools.compress(string.ascii_uppercase, map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1])))
633 #print list(map(chr, range(68, 91)))
634 #print Cygwin.getRegEntry('SYSTEM\CurrentControlSet\Enum\USB', 'VID_1058&PID_0704')[0]
635 #devices = VMManager.getConnectedRSDS()
638 drives = VMManager.getLogicalDrives()
640 print VMManager.getDriveType("E")
641 print VMManager.getVolumeInfo("E")
642 #for device in devices.values():
644 # if VMManager.isMassStorageDevice(device):
654 #man.genCertificateISO('SecurityDVM0')
655 #man.guestExecute('SecurityDVM0', '/bin/ls -la')
656 #logger = setupLogger('VMManager')
659 #man.sshExecute('/bin/ls -la', 'SecurityDVM0')
660 #man.sshExecuteX11('/usr/bin/iceweasel', 'SecurityDVM0')
661 #man.removeVM('SecurityDVM0')
662 #man.netUse('192.168.56.134', 'USB\\')
663 #ip = '192.168.56.139'
665 #man.cygwin_path = 'c:\\cygwin64\\bin\\'
666 #man.handleDeviceChange()
667 #print man.listSDVM()
668 #man.configureHostNetworking()
669 #new_vm = man.generateSDVMName()
670 #man.createVM(new_vm)
673 #man.isAvailable('c:')
674 #ip = man.getHostOnlyIP('SecurityDVM0')
675 #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None)
677 #man.genCertificateISO(new_vm)
678 #man.attachCertificateISO(new_vm)
680 #man.attachCertificateISO(vm_name)
681 #man.guestExecute(vm_name, "ls")
682 #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel')
684 #print man.cygwinPath("C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\.ssh\*")
685 #man.genCertificateISO('SecurityDVM')
686 #man.attachCertificateISO('SecurityDVM')
687 #man.isStorageAttached('SecurityDVM')
688 #man.guestExecute('SecurityDVM', 'sudo apt-get -y update')
689 #man.guestExecute('SecurityDVM', 'sudo apt-get -y upgrade' )
691 #man.stopVM('SecurityDVM')
692 #man.storageDetach('SecurityDVM')
693 #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable')
694 #man.storageAttach('SecurityDVM')
697 #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""