Пример #1
0
    def submit_job(self, sample_path, sensor_path, job):
        """Submit a job to cuckoo and notify hermes.

        Keyword arguments:
            sample_path -- the path to the sample file
            sensor_path -- the path to the sensor file
            job -- the job which is submitted to cuckoo
        """

        # dummy default values
        enforce_timeout = False
        custom_options = ""

        cuckoo_for_job = self.cuckoo_instances[
            job.virtual_machine.hypervisor]

        if sensor_path:
            # copy sensor to cuckoo sensor folder
            self.copy_sensor_file_to_cuckoo(sensor_path, cuckoo_for_job.sensor_dir)
            path, sensor_filename = os.path.split(sensor_path)
        else:
            sensor_filename = None

        client = RestApiClient(cuckoo_for_job.ip,
                               cuckoo_for_job.port)

        try:
            response = client.create_file_task(
                job.id,
                sample_path,
                sensor_filename,
                job.timeout,
                job.priority,
                job.memory_dump,
                job.simulated_time,
                enforce_timeout,
                custom_options
            )
            job.cuckoo_id = response['task_id']

            try:
                self.hermes.notify_start_job(self.id, job.id)
            except ApiError, e:
                # log.error(e.msg)
                raise HermesError(str(e))
            except RequestError, e:
                # log.error(e.msg)
                raise HermesError(str(e))
Пример #2
0
    def submit_job(self, sample_path, sensor_path, job):
        """Submit a job to cuckoo and notify hermes.

        Keyword arguments:
            sample_path -- the path to the sample file
            sensor_path -- the path to the sensor file
            job -- the job which is submitted to cuckoo
        """

        # dummy default values
        enforce_timeout = False
        custom_options = ""

        cuckoo_for_job = self.cuckoo_instances[job.virtual_machine.hypervisor]

        if sensor_path:
            # copy sensor to cuckoo sensor folder
            self.copy_sensor_file_to_cuckoo(sensor_path,
                                            cuckoo_for_job.sensor_dir)
            path, sensor_filename = os.path.split(sensor_path)
        else:
            sensor_filename = None

        client = RestApiClient(cuckoo_for_job.ip, cuckoo_for_job.port)

        try:
            response = client.create_file_task(job.id, sample_path,
                                               sensor_filename, job.timeout,
                                               job.priority, job.memory_dump,
                                               job.simulated_time,
                                               enforce_timeout, custom_options)
            job.cuckoo_id = response['task_id']

            try:
                self.hermes.notify_start_job(self.id, job.id)
            except ApiError, e:
                # log.error(e.msg)
                raise HermesError(str(e))
            except RequestError, e:
                # log.error(e.msg)
                raise HermesError(str(e))
Пример #3
0
    def get_cuckoo_result(self, job):
        """Get the current state of the given job and update the
        state according to the result.

        Keyword arguments:
            job -- the job which is used to obtain the result
        """

        cuckoo_for_job = self.cuckoo_instances[job.virtual_machine.hypervisor]

        client = RestApiClient(cuckoo_for_job.ip,
                               cuckoo_for_job.port)
        try:
            response = client.view_task(job.id)
            status = response['task']['status']
            log.info("job " + str(job.id) + " status " + status)

            if job.state != status:
                # state has changed, update job and notify hermes
                if status == "pending":
                    job.state = job.STATE_PENDING
                elif status == "running":
                    job.state = job.STATE_PROCESSING
                    # self.hermes.notify_start_job(self.id, job.id)
                elif status == "reported":

                    # check for errors
                    errors = response['task']['errors']
                    print errors
                    if len(errors) > 0:
                        job.state = job.STATE_FAILURE
                        self.abort_job(str(errors), job)
                    else:
                        job.state = job.STATE_SUCCESS
                        self.retry_loop_notify_finish(job)

        except CuckooError, e:
            error_msg = str(e)
            log.error("CuckooError while getting cuckoo result: " + error_msg)
            self.abort_job(error_msg, job)
Пример #4
0
    def get_cuckoo_result(self, job):
        """Get the current state of the given job and update the
        state according to the result.

        Keyword arguments:
            job -- the job which is used to obtain the result
        """

        cuckoo_for_job = self.cuckoo_instances[job.virtual_machine.hypervisor]

        client = RestApiClient(cuckoo_for_job.ip, cuckoo_for_job.port)
        try:
            response = client.view_task(job.id)
            status = response['task']['status']
            log.info("job " + str(job.id) + " status " + status)

            if job.state != status:
                # state has changed, update job and notify hermes
                if status == "pending":
                    job.state = job.STATE_PENDING
                elif status == "running":
                    job.state = job.STATE_PROCESSING
                    # self.hermes.notify_start_job(self.id, job.id)
                elif status == "reported":

                    # check for errors
                    errors = response['task']['errors']
                    print errors
                    if len(errors) > 0:
                        job.state = job.STATE_FAILURE
                        self.abort_job(str(errors), job)
                    else:
                        job.state = job.STATE_SUCCESS
                        self.retry_loop_notify_finish(job)

        except CuckooError, e:
            error_msg = str(e)
            log.error("CuckooError while getting cuckoo result: " + error_msg)
            self.abort_job(error_msg, job)