当前位置: 首页>>代码示例>>Python>>正文


Python RunAuxiliary.start方法代码示例

本文整理汇总了Python中lib.cuckoo.core.plugins.RunAuxiliary.start方法的典型用法代码示例。如果您正苦于以下问题:Python RunAuxiliary.start方法的具体用法?Python RunAuxiliary.start怎么用?Python RunAuxiliary.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.cuckoo.core.plugins.RunAuxiliary的用法示例。


在下文中一共展示了RunAuxiliary.start方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: launch_analysis

# 需要导入模块: from lib.cuckoo.core.plugins import RunAuxiliary [as 别名]
# 或者: from lib.cuckoo.core.plugins.RunAuxiliary import start [as 别名]
    def launch_analysis(self):
        """Start analysis."""
        succeeded = False
        dead_machine = False

        log.info("Starting analysis of %s \"%s\" (task=%d)",
                 self.task.category.upper(), self.task.target, self.task.id)

        # Initialize the analysis folders.
        if not self.init_storage():
            return False

        if self.task.category == "file":
            # Check whether the file has been changed for some unknown reason.
            # And fail this analysis if it has been modified.
            if not self.check_file():
                return False

            # Store a copy of the original file.
            if not self.store_file():
                return False

        # Acquire analysis machine.
        try:
            self.acquire_machine()
        except CuckooOperationalError as e:
            machine_lock.release()
            log.error("Cannot acquire machine: {0}".format(e))
            return False

        # At this point we can tell the ResultServer about it.
        try:
            ResultServer().add_task(self.task, self.machine)
        except Exception as e:
            machinery.release(self.machine.label)
            self.errors.put(e)

        aux = RunAuxiliary(task=self.task, machine=self.machine)
        aux.start()

        # Generate the analysis configuration file.
        options = self.build_options()

        try:
            unlocked = False

            # Mark the selected analysis machine in the database as started.
            guest_log = self.db.guest_start(self.task.id,
                                            self.machine.name,
                                            self.machine.label,
                                            machinery.__class__.__name__)
            # Start the machine.
            machinery.start(self.machine.label)

            # By the time start returns it will have fully started the Virtual
            # Machine. We can now safely release the machine lock.
            machine_lock.release()
            unlocked = True

            # Initialize the guest manager.
            guest = GuestManager(self.machine.name, self.machine.ip,
                                 self.machine.platform)

            # Start the analysis.
            guest.start_analysis(options)

            guest.wait_for_completion()
            succeeded = True
        except CuckooMachineError as e:
            if not unlocked:
                machine_lock.release()
            log.error(str(e), extra={"task_id": self.task.id})
            dead_machine = True
        except CuckooGuestError as e:
            if not unlocked:
                machine_lock.release()
            log.error(str(e), extra={"task_id": self.task.id})
        finally:
            # Stop Auxiliary modules.
            aux.stop()

            # Take a memory dump of the machine before shutting it off.
            if self.cfg.cuckoo.memory_dump or self.task.memory:
                try:
                    dump_path = os.path.join(self.storage, "memory.dmp")
                    machinery.dump_memory(self.machine.label, dump_path)
                except NotImplementedError:
                    log.error("The memory dump functionality is not available "
                              "for the current machine manager.")
                except CuckooMachineError as e:
                    log.error(e)

            try:
                # Stop the analysis machine.
                machinery.stop(self.machine.label)
            except CuckooMachineError as e:
                log.warning("Unable to stop machine %s: %s",
                            self.machine.label, e)

            # Mark the machine in the database as stopped. Unless this machine
#.........这里部分代码省略.........
开发者ID:Sunrel,项目名称:cuckoo,代码行数:103,代码来源:scheduler.py

示例2: launch_analysis

# 需要导入模块: from lib.cuckoo.core.plugins import RunAuxiliary [as 别名]
# 或者: from lib.cuckoo.core.plugins.RunAuxiliary import start [as 别名]
    def launch_analysis(self):
        """Start analysis."""
        succeeded = False

        target = self.task.target
        if self.task.category == "file":
            target = os.path.basename(target)

        log.info("Starting analysis of %s \"%s\" (task #%d, options \"%s\")",
                 self.task.category.upper(), target, self.task.id,
                 emit_options(self.task.options))

        # Initialize the analysis folders.
        if not self.init_storage():
            return False

        self.store_task_info()

        if self.task.category == "file":
            # Check whether the file has been changed for some unknown reason.
            # And fail this analysis if it has been modified.
            if not self.check_file():
                return False

            # Store a copy of the original file.
            if not self.store_file():
                return False

        # Acquire analysis machine.
        try:
            self.acquire_machine()
        except CuckooOperationalError as e:
            machine_lock.release()
            log.error("Cannot acquire machine: {0}".format(e))
            return False

        # At this point we can tell the ResultServer about it.
        try:
            ResultServer().add_task(self.task, self.machine)
        except Exception as e:
            machinery.release(self.machine.label)
            self.errors.put(e)

        aux = RunAuxiliary(task=self.task, machine=self.machine)
        aux.start()

        # Generate the analysis configuration file.
        options = self.build_options()

        try:
            unlocked = False
            self.interface = None

            # Mark the selected analysis machine in the database as started.
            guest_log = self.db.guest_start(self.task.id,
                                            self.machine.name,
                                            self.machine.label,
                                            machinery.__class__.__name__)
            # Start the machine.
            machinery.start(self.machine.label, self.task)

            # Enable network routing.
            self.route_network()

            # By the time start returns it will have fully started the Virtual
            # Machine. We can now safely release the machine lock.
            machine_lock.release()
            unlocked = True

            # Run and manage the components inside the guest unless this
            # machine has the "noagent" option specified (please refer to the
            # wait_finish() function for more details on this function).
            if "noagent" not in self.machine.options:
                self.guest_manage(options)
            else:
                self.wait_finish()

            succeeded = True
        except CuckooMachineError as e:
            if not unlocked:
                machine_lock.release()
            log.error(str(e), extra={"task_id": self.task.id})
            log.critical(
                "A critical error has occurred trying to use the machine "
                "with name %s during an analysis due to which it is no "
                "longer in a working state, please report this issue and all "
                "of the related environment details to the developers so we "
                "can improve this situation. (Note that before we would "
                "simply remove this VM from doing any more analyses, but as "
                "all the VMs will eventually be depleted that way, hopefully "
                "we'll find a better solution now).", self.machine.name,
            )
        except CuckooGuestError as e:
            if not unlocked:
                machine_lock.release()
            log.error(str(e), extra={"task_id": self.task.id})
        finally:
            # Stop Auxiliary modules.
            aux.stop()

#.........这里部分代码省略.........
开发者ID:0x71,项目名称:cuckoo,代码行数:103,代码来源:scheduler.py

示例3: launch_analysis

# 需要导入模块: from lib.cuckoo.core.plugins import RunAuxiliary [as 别名]
# 或者: from lib.cuckoo.core.plugins.RunAuxiliary import start [as 别名]
    def launch_analysis(self):
        """Start analysis."""
        succeeded = False
        dead_machine = False

        log.info("Starting analysis of %s \"%s\" (task=%d)",
                 self.task.category.upper(), self.task.target, self.task.id)
        # Initialize the the analysis folders.
        if not self.init_storage():
            return False
	if self.task.category == "file":
	    # Check whether the file has been changed for some unknown reason.
            # And fail this analysis if it has been modified.
            	if not self.check_file():
                	return False

            # Store a copy of the original file.
                if not self.store_file():
                        return False


	# Acquire analysis machine.
        try:
            self.acquire_machine()
        except CuckooOperationalError as e:
            log.error("Cannot acquire machine: {0}".format(e))
            return False

        # Generate the analysis configuration file.
        options = self.build_options()

        # At this point we can tell the Resultserver about it.
        try:
	    Resultserver().set_machinery(machinery)
            Resultserver().add_task(self.task, self.machine)
        except Exception as e:
            machinery.release(self.machine.label)
            self.errors.put(e)

        aux = RunAuxiliary(task=self.task, machine=self.machine)
        aux.start()

        try:
	    
            # Mark the selected analysis machine in the database as started.
            guest_log = Database().guest_start(self.task.id,
                                               self.machine.name,
                                               self.machine.label,
                                               machinery.__class__.__name__)
            # Start the machine.
            # machinery.start(self.machine.label)
	except CuckooMachineError as e:
            log.error(str(e), extra={"task_id": self.task.id})
            dead_machine = True
        else:
            try:
                # Initialize the guest manager.
                guest = GuestManager(self.machine.name, self.machine.ip, self.machine.platform)
                # Start the analysis.
                guest.start_analysis(options)
            except CuckooGuestError as e:
                log.error(str(e), extra={"task_id": self.task.id})
                
	    
	    # Wait for analysis completion.
	    time_taken_for_analysis = 0
            try:
                guest.wait_for_completion(self.machine, self.storage, machinery)
                succeeded = True
            except CuckooGuestError as e:
                log.error(str(e), extra={"task_id": self.task.id})
                succeeded = False

        finally:
	    """
	    log.info("Taking last dump before terminating...")
	    mem_dir = os.path.join(self.storage, "memory", "dumps")
            try:
            	os.makedirs(mem_dir)
            except:
                pass
            if len (os.listdir(mem_dir)) == 0:
            	dump_dir = '1'
            else:
                dump_dir = str(int(max(os.listdir(mem_dir))) + 1)
            try:
                os.makedirs(os.path.join(mem_dir, dump_dir))
            except:
                pass
            dump_path = os.path.join(mem_dir, dump_dir, "memory.dmp")
	    machinery.dump_memory(self.machine.label, dump_path)
	    info_dict = {"trigger": {"name" : "End", "args": {}}, "time" : str(time_taken_for_analysis)}
	    json.dump(info_dict, file(os.path.join(mem_dir, dump_dir, "info.json"),"wb"), sort_keys=False, indent=4)
	    """
            # Stop Auxiliary modules.
            aux.stop()

             
            try:
                # Stop the analysis machine.
#.........这里部分代码省略.........
开发者ID:Hardknox,项目名称:MemoryAnalysis,代码行数:103,代码来源:scheduler.py

示例4: AnalysisManager

# 需要导入模块: from lib.cuckoo.core.plugins import RunAuxiliary [as 别名]
# 或者: from lib.cuckoo.core.plugins.RunAuxiliary import start [as 别名]

#.........这里部分代码省略.........
        """Generate analysis options.
        @return: options dict.
        """
        options = {}

        if self.task.category == "file":
            options["file_name"] = File(self.task.target).get_name()
            options["file_type"] = File(self.task.target).get_type()
            options["pe_exports"] = \
                ",".join(File(self.task.target).get_exported_functions())

            package, activity = File(self.task.target).get_apk_entry()
            self.task.options["apk_entry"] = "%s:%s" % (package, activity)

        options["id"] = self.task.id
        options["ip"] = self.machine.resultserver_ip
        options["port"] = self.machine.resultserver_port
        options["category"] = self.task.category
        options["target"] = self.task.target
        options["package"] = self.task.package
        options["options"] = emit_options(self.task.options)
        options["enforce_timeout"] = self.task.enforce_timeout
        options["clock"] = self.task.clock
        options["terminate_processes"] = self.cfg.cuckoo.terminate_processes

        if not self.task.timeout:
            options["timeout"] = self.cfg.timeouts.default
        else:
            options["timeout"] = self.task.timeout

        # copy in other analyzer specific options, TEMPORARY (most likely)
        vm_options = getattr(machinery.options, self.machine.name)
        for k in vm_options:
            if k.startswith("analyzer_"):
                options[k] = vm_options[k]

        return options

    def route_network(self):
        """Enable network routing if desired."""
        # Determine the desired routing strategy (none, internet, VPN).
        route = self.task.options.get("route", self.cfg.routing.route)

        if route == "none":
            self.interface = None
            self.rt_table = None
        elif route == "internet" and self.cfg.routing.internet != "none":
            self.interface = self.cfg.routing.internet
            self.rt_table = self.cfg.routing.rt_table
        elif route in vpns:
            self.interface = vpns[route].interface
            self.rt_table = vpns[route].rt_table
        else:
            log.warning("Unknown network routing destination specified, "
                        "ignoring routing for this analysis: %r", route)
            self.interface = None
            self.rt_table = None

        # Check if the network interface is still available. If a VPN dies for
        # some reason, its tunX interface will no longer be available.
        if self.interface and not rooter("nic_available", self.interface):
            log.error(
                "The network interface '%s' configured for this analysis is "
                "not available at the moment, switching to route=none mode.",
                self.interface
            )
开发者ID:alonlavian,项目名称:cuckoo,代码行数:70,代码来源:scheduler.py

示例5: launch_analysis

# 需要导入模块: from lib.cuckoo.core.plugins import RunAuxiliary [as 别名]
# 或者: from lib.cuckoo.core.plugins.RunAuxiliary import start [as 别名]
    def launch_analysis(self):
        """Start analysis."""
        succeeded = False
        dead_machine = False

        log.info("Starting analysis of %s \"%s\" (task=%d)",
                 self.task.category.upper(), self.task.target, self.task.id)

        # Initialize the analysis folders.
        if not self.init_storage():
            return False

        if self.task.category == "file":
            sample = Database().view_sample(self.task.sample_id)

            is_first_task = len(Database().list_tasks(experiment=self.task.experiment_id)) == 1

            if is_first_task:
                # Check whether the file has been changed for some unknown reason.
                # And fail this analysis if it has been modified.
                if not self.check_file():
                    return False

                # Store a copy of the original file.
                if not self.store_file():
                    return False

            self.binary = os.path.join(CUCKOO_ROOT, "storage", "binaries", sample.sha256)

            self.create_symlink()

        # FIXME - Scheduling should happen at the end of the experiment, but
        #           since the management of the experiment is not final that
        #           will do it.
        if self.task.repeat == TASK_RECURRENT:
            Database().schedule(self.task.id)

        # Acquire analysis machine.
        try:
            self.acquire_machine()
        except CuckooOperationalError as e:
            machine_lock.release()
            log.error("Cannot acquire machine: {0}".format(e))
            return False

        # Generate the analysis configuration file.
        options = self.build_options()

        # At this point we can tell the ResultServer about it.
        try:
            ResultServer().add_task(self.task, self.machine)
        except Exception as e:
            machinery.release(self.machine.label)
            self.errors.put(e)

        aux = RunAuxiliary(task=self.task, machine=self.machine)
        aux.start()

        try:
            # Mark the selected analysis machine in the database as started.
            guest_log = Database().guest_start(self.task.id,
                                               self.machine.name,
                                               self.machine.label,
                                               machinery.__class__.__name__)

            # Starting the machinery takes some time. In order not to run into
            # race conditions with max_machines_count because acquiring new
            # machines takes place in parallel next to starting machines, for
            # which it takes a little delay before the machines' status turns
            # into "running", we hold the machine lock until the machine has
            # fully started (or gives an error, of course).
            try:
                # Start the machine, revert only if we are the first task in
                # the experiment.
                machinery.start(self.machine.label, revert=is_first_task)
            finally:
                machine_lock.release()

            # Initialize the guest manager.
            # FIXME - The critical timeout options is analysis_timeout + 60 sec
            #           should it be configurable?
            guest = GuestManager(self.machine.name,
                                 self.machine.ip,
                                 options["timeout"] + 60,
                                 self.machine.platform)

            # Start the analysis if we are the first task of a series
            if is_first_task:
                guest.start_analysis(options)

            guest.wait_for_completion()
            succeeded = True
        except CuckooMachineError as e:
            log.error(str(e), extra={"task_id": self.task.id})
            dead_machine = True
        except CuckooGuestError as e:
            log.error(str(e), extra={"task_id": self.task.id})
        finally:
            # Stop Auxiliary modules.
            aux.stop()
#.........这里部分代码省略.........
开发者ID:uCares,项目名称:longcuckoo,代码行数:103,代码来源:scheduler.py


注:本文中的lib.cuckoo.core.plugins.RunAuxiliary.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。