def snapshot(name, vmname, ipaddr, resolution, ramsize, cpus, hostname, adapter, vm_visible, count, vrde, vrde_port, interactive, debug): if debug: log.setLevel(logging.DEBUG) session = Session() if adapter: log.error( "Specifying a different adapter is not yet supported for " "snapshots (this will require detaching the current adapter and " "attaching a new one after the static IP address has been " "updated or so)." ) exit(1) image = session.query(Image).filter_by(name=name).first() if not image: log.error("Image not found: %s", name) exit(1) # From now on this image is multiattach. image.mode = "multiattach" session.commit() if not count: snapshot = do_snapshot( image, vmname, ipaddr, resolution, ramsize, cpus, hostname or random_string(8, 16), adapter, vm_visible, vrde, vrde_port, interactive ) session.add(snapshot) else: if hostname: log.error( "You specified a hostname, but this is not supported when " "creating multiple snapshots at once." ) exit(1) for x in xrange(count): snapshot = do_snapshot( image, "%s%d" % (vmname, x + 1), ipaddr, resolution, ramsize, cpus, hostname, adapter, vm_visible, vrde, vrde_port, interactive ) session.add(snapshot) # TODO Implement some limits to make sure that the IP address does # not "exceed" its provided subnet (and thus also require the user # to specify an IP range, rather than an IP address). ipaddr = ipaddr_increase(ipaddr) hostname = random_string(8, 16) session.commit()
def _autounattend_xml(self, product): values = { # "PRODUCTKEY": self.serial_key, "COMPUTERNAME": random_string(8, 14), "USERNAME": random_string(8, 12), "PASSWORD": random_string(8, 16), "PRODUCT": product.upper(), "ARCH": self.arch, "INTERFACE": self.interface, } xml_doc = lxml.etree.fromstring( open(os.path.join(self.path, "autounattend.xml"), "rb").read()) # Get the proper component tag to work with # We *should* be able to pick this up with a single findall... # but that doesn't work for some reason - searching by attributes doesn't return anything # for multiple activation key (MAK) keys: if self.serial_key_type == "mak": shell_setup_component = next( z for z in xml_doc.findall(".//component", namespaces=xml_doc.nsmap) if z.get("name") == 'Microsoft-Windows-Shell-Setup' and z.getparent().get("pass") == "specialize") product_key = lxml.etree.Element("ProductKey") product_key.text = self.serial_key shell_setup_component.append(product_key) # Need to re-assign xml_doc to be the modified XML xml_doc = shell_setup_component.getroottree() else: setup_userdata_xml = next( z for z in xml_doc.findall(".//component/UserData", namespaces=xml_doc.nsmap) if z.getparent().get("name") == 'Microsoft-Windows-Setup') product_key = lxml.etree.Element("ProductKey") child_key = lxml.etree.SubElement(product_key, "Key") child_key.text = self.serial_key willshowui = lxml.etree.SubElement(product_key, "WillShowUI") willshowui.text = "OnError" setup_userdata_xml.append(product_key) xml_doc = setup_userdata_xml.getroottree() # buf = open(os.path.join(self.path, "autounattend.xml"), "rb").read() buf = lxml.etree.tostring(xml_doc) for key, value in values.items(): buf = buf.replace("@%s@" % key, value) return buf
def _autounattend_xml(self): values = { 'PRODUCTKEY': self.serial_key, 'COMPUTERNAME': random_string(8, 16), 'USERNAME': random_string(8, 12), 'PASSWORD': random_string(8, 16), } buf = open(os.path.join(self.path, 'autounattend.xml'), 'rb').read() for key, value in values.items(): buf = buf.replace('@%s@' % key, value) return buf
def configure_winnt_sif(path, args): values = { 'PRODUCTKEY': args.serial_key, 'COMPUTERNAME': random_string(8, 16), 'FULLNAME': '%s %s' % (random_string(4, 8), random_string(4, 10)), 'ORGANIZATION': '', 'WORKGROUP': random_string(4, 8), 'KBLAYOUT': args.keyboard_layout, } buf = open(path, 'rb').read() for key, value in values.items(): buf = buf.replace('@%s@' % key, value) return buf
def _autounattend_xml(self, product): values = { 'PRODUCTKEY': self.serial_key, 'COMPUTERNAME': random_string(8, 14), 'USERNAME': random_string(8, 12), 'PASSWORD': random_string(8, 16), "PRODUCT": product.upper(), "ARCH": self.ARCH, "INTERFACE": self.interface, } buf = open(os.path.join(self.path, 'autounattend.xml'), 'rb').read() for key, value in values.items(): buf = buf.replace('@%s@' % key, value) return buf
def _autounattend_xml(self, product): values = { "PRODUCTKEY": self.serial_key, "COMPUTERNAME": random_string(8, 14), "USERNAME": random_string(8, 12), "PASSWORD": random_string(8, 16), "PRODUCT": product.upper(), "ARCH": self.arch, "INTERFACE": self.interface, } buf = open(os.path.join(self.path, "autounattend.xml"), "rb").read() for key, value in values.items(): buf = buf.replace("@%s@" % key, value) return buf
def _winnt_sif(self): values = { 'PRODUCTKEY': self.serial_key, 'COMPUTERNAME': random_string(8, 16), 'FULLNAME': '%s %s' % (random_string(4, 8), random_string(4, 10)), 'ORGANIZATION': '', 'WORKGROUP': random_string(4, 8), # 'KBLAYOUT': s.keyboard_layout, 'KBLAYOUT': 'US', } buf = open(os.path.join(self.path, 'winnt.sif'), 'rb').read() for key, value in values.items(): buf = buf.replace('@%s@' % key, value) fd, winntsif = tempfile.mkstemp(suffix='.sif', dir=self.tempdir) os.write(fd, buf) os.close(fd) return winntsif
def _winnt_sif(self): values = { "PRODUCTKEY": self.serial_key, "COMPUTERNAME": random_string(8, 16), "FULLNAME": "%s %s" % (random_string(4, 8), random_string(4, 10)), "ORGANIZATION": "", "WORKGROUP": random_string(4, 8), # "KBLAYOUT": s.keyboard_layout, "KBLAYOUT": "US", } buf = open(os.path.join(self.path, "winnt.sif"), "rb").read() for key, value in values.items(): buf = buf.replace("@%s@" % key, value) fd, winntsif = tempfile.mkstemp(suffix=".sif", dir=self.tempdir) os.write(fd, buf) os.close(fd) return winntsif
def _winnt_sif(self): s = self.s values = { 'PRODUCTKEY': self.serial_key, 'COMPUTERNAME': random_string(8, 16), 'FULLNAME': '%s %s' % (random_string(4, 8), random_string(4, 10)), 'ORGANIZATION': '', 'WORKGROUP': random_string(4, 8), 'KBLAYOUT': s.keyboard_layout, } buf = open(os.path.join(self.path, 'winnt.sif'), 'rb').read() for key, value in values.items(): buf = buf.replace('@%s@' % key, value) fd, winntsif = tempfile.mkstemp(suffix='.sif', dir=s.temp_dirpath) os.write(fd, buf) os.close(fd) return winntsif
def snapshot(name, vmname, ipaddr, resolution, ramsize, cpus, hostname, adapter, vm_visible, count): session = Session() image = session.query(Image).filter_by(name=name).first() if not image: log.error("Image not found: %s", name) exit(1) # From now on this image is multiattach. image.mode = "multiattach" session.commit() if not count: snapshot = do_snapshot( image, vmname, ipaddr, resolution, ramsize, cpus, hostname or random_string(8, 16), adapter, vm_visible ) session.add(snapshot) else: if hostname: log.error( "You specified a hostname, but this is not supported when " "creating multiple snapshots at once." ) exit(1) for x in xrange(count): snapshot = do_snapshot( image, "%s%d" % (vmname, x + 1), ipaddr, resolution, ramsize, cpus, hostname, adapter, vm_visible ) session.add(snapshot) # TODO Implement some limits to make sure that the IP address does # not "exceed" its provided subnet (and thus also require the user # to specify an IP range, rather than an IP address). ipaddr = ipaddr_increase(ipaddr) hostname = random_string(8, 16) session.commit()
if not snapshot: log.error("Snapshot not found: %s", vmname) exit(1) # TODO Add snapshot.port & snapshot.adapter to the configuration. # But those options will require various changes in Cuckoo as well. register_cuckoo(snapshot.ipaddr, tags, vmname, cuckoo) @main.command() @click.argument("name") @click.argument("vmname") @click.argument("ipaddr", required=False, default="192.168.56.101") @click.option("--resolution", help="Screen resolution.") @click.option("--ramsize", type=int, help="Amount of virtual memory to assign.") @click.option("--cpus", type=int, help="Amount of CPUs to assign.") @click.option("--hostname", default=random_string(8, 16), help="Hostname for this VM.") @click.option("--adapter", help="Hostonly adapter for this VM.") @click.option("--vm-visible", is_flag=True, help="Start the Virtual Machine in GUI mode.") def snapshot(name, vmname, ipaddr, resolution, ramsize, cpus, hostname, adapter, vm_visible): session = Session() image = session.query(Image).filter_by(name=name).first() if not image: log.error("Image not found: %s", name) exit(1) # From now on this image is multiattach. image.mode = "multiattach" session.commit()