def _initialize_check(self): """Runs checks against virtualization software when a machine manager is initialized. @note: in machine manager modules you may override or superclass his method. @raise CuckooMachineError: if a misconfiguration or a unkown vm state is found. """ try: configured_vms = self._list() except NotImplementedError: return for machine in self.machines(): # If this machine is already in the "correct" state, then we # go on to the next machine. if machine.label in configured_vms and \ self._status(machine.label) in [self.POWEROFF, self.ABORTED]: continue # This machine is currently not in its correct state, we're going # to try to shut it down. If that works, then the machine is fine. try: self.stop(machine.label) except CuckooMachineError as e: raise CuckooCriticalError( "Please update your configuration. Unable to shut '%s' " "down or find the machine in its proper state: %s" % (machine.label, e)) if not config("cuckoo:timeouts:vm_state"): raise CuckooCriticalError( "Virtual machine state change timeout has not been set " "properly, please update it to be non-null.")
def _wait_status(self, label, *states): """Waits for a vm status. @param label: virtual machine name. @param state: virtual machine status, accepts multiple states as list. @raise CuckooMachineError: if default waiting timeout expire. """ # This block was originally suggested by Loic Jaquemet. waitme = 0 try: current = self._status(label) except NameError: return while current not in states: log.debug( "Waiting %i cuckooseconds for machine %s to switch " "to status %s", waitme, label, states) if waitme > config("cuckoo:timeouts:vm_state"): raise CuckooMachineError( "Timeout hit while for machine %s to change status" % label) time.sleep(1) waitme += 1 current = self._status(label)
def _initialize(self, module_name): """Read configuration. @param module_name: module name. """ machinery = self.options.get(module_name) for vmname in machinery["machines"]: options = self.options.get(vmname) # If configured, use specific network interface for this # machine, else use the default value. if options.get("interface"): interface = options["interface"] else: interface = machinery.get("interface") if options.get("resultserver_ip"): ip = options["resultserver_ip"] else: ip = config("cuckoo:resultserver:ip") if options.get("resultserver_port"): port = options["resultserver_port"] else: # The ResultServer port might have been dynamically changed, # get it from the ResultServer singleton. Also avoid import # recursion issues by importing ResultServer here. from cuckoo.core.resultserver import ResultServer port = ResultServer().port self.db.add_machine(name=vmname, label=options[self.LABEL], ip=options.ip, platform=options.platform, options=options.get("options", ""), tags=options.tags, interface=interface, snapshot=options.snapshot, resultserver_ip=ip, resultserver_port=port)
#!/usr/bin/env python3 from common.config import config from common.colourprint import Printer from warrant import Cognito props = config() cognito = Cognito(props['USER_POOL_ID'], props['CLIENT_ID'], user_pool_region='eu-west-1', username=props['USERNAME']) print('Requesting a password reset for {}'.format(props['USERNAME'])) cognito.initiate_forgot_password() Printer.success()