diff options
author | Michael Weiser <michael.weiser@gmx.de> | 2019-04-15 16:15:24 +0000 |
---|---|---|
committer | Michael Weiser <michael.weiser@gmx.de> | 2019-04-15 16:15:24 +0000 |
commit | 37594674081de76ca59b93087f9d52a12227784a (patch) | |
tree | 6b31bd5980e6130a8c4572e93f968f7a452d389b /peekaboo | |
parent | 00f8f3529230435a04af64c2a67d6e151ee1a88d (diff) |
Rename analysis failed to submit failed exception
Rename CuckooAnalysisFailedException to CuckooSubmitFailedException to
more clearly state its purpose and meaning. Add some documentation.
Remove an unnecessary else clause.
Diffstat (limited to 'peekaboo')
-rw-r--r-- | peekaboo/exceptions.py | 6 | ||||
-rw-r--r-- | peekaboo/ruleset/rules.py | 4 | ||||
-rw-r--r-- | peekaboo/toolbox/cuckoo.py | 53 |
3 files changed, 34 insertions, 29 deletions
diff --git a/peekaboo/exceptions.py b/peekaboo/exceptions.py index bc11ec0..7559cac 100644 --- a/peekaboo/exceptions.py +++ b/peekaboo/exceptions.py @@ -41,8 +41,12 @@ class PeekabooRulesetException(PeekabooException): class CuckooReportPendingException(PeekabooRulesetException): + """ An exception signifying that we're waiting for Cuckoo to finish its + analysis an defer our interpretation of its findings until its report + becomes available. """ pass -class CuckooAnalysisFailedException(PeekabooException): +class CuckooSubmitFailedException(PeekabooException): + """ An exception raised if submitting a job to Cuckoo fails. """ pass diff --git a/peekaboo/ruleset/rules.py b/peekaboo/ruleset/rules.py index 93b2872..379adf4 100644 --- a/peekaboo/ruleset/rules.py +++ b/peekaboo/ruleset/rules.py @@ -30,7 +30,7 @@ import re import logging from peekaboo.ruleset import Result, RuleResult from peekaboo.exceptions import CuckooReportPendingException, \ - CuckooAnalysisFailedException + CuckooSubmitFailedException logger = logging.getLogger(__name__) @@ -199,7 +199,7 @@ class CuckooRule(Rule): if report is None: try: job_id = sample.submit_to_cuckoo() - except CuckooAnalysisFailedException as failed: + except CuckooSubmitFailedException as failed: logger.error("Submit to Cuckoo failed: %s", failed) # exception message intentionally not present in message # delivered back to client as to not disclose internal diff --git a/peekaboo/toolbox/cuckoo.py b/peekaboo/toolbox/cuckoo.py index 4df0a16..1ede5f7 100644 --- a/peekaboo/toolbox/cuckoo.py +++ b/peekaboo/toolbox/cuckoo.py @@ -38,7 +38,7 @@ from threading import RLock import requests from twisted.internet import protocol, reactor, process -from peekaboo.exceptions import CuckooAnalysisFailedException +from peekaboo.exceptions import CuckooSubmitFailedException logger = logging.getLogger(__name__) @@ -65,11 +65,11 @@ class Cuckoo: @type sample: Sample @returns: None - @raises: CuckooAnalysisFailedException on job id collision """ + @raises: CuckooSubmitFailedException on job id collision """ with self.running_jobs_lock: if (job_id in self.running_jobs and self.running_jobs[job_id] is not sample): - raise CuckooAnalysisFailedException( + raise CuckooSubmitFailedException( 'A job with ID %d is already registered as running ' 'for sample %s' % (job_id, self.running_jobs[job_id])) @@ -160,33 +160,34 @@ class CuckooEmbed(Cuckoo): stderr=subprocess.PIPE, universal_newlines=True) p.wait() - except Exception as e: - raise CuckooAnalysisFailedException(e) + except Exception as error: + raise CuckooSubmitFailedException(error) if not p.returncode == 0: - raise CuckooAnalysisFailedException('cuckoo submit returned a non-zero return code.') - else: - out, err = p.communicate() - logger.debug("cuckoo submit STDOUT: %s", out) - logger.debug("cuckoo submit STDERR: %s", err) - - match = None - pattern_no = 0 - for pattern in self.job_id_patterns: - match = re.search(pattern, out) - if match is not None: - logger.debug('Pattern %d matched.' % pattern_no) - break + raise CuckooSubmitFailedException( + 'cuckoo submit returned a non-zero return code.') - pattern_no += 1 - + out, err = p.communicate() + logger.debug("cuckoo submit STDOUT: %s", out) + logger.debug("cuckoo submit STDERR: %s", err) + + match = None + pattern_no = 0 + for pattern in self.job_id_patterns: + match = re.search(pattern, out) if match is not None: - job_id = int(match.group(1)) - self.register_running_job(job_id, sample) - return job_id + logger.debug('Pattern %d matched.', pattern_no) + break + + pattern_no += 1 + + if match is not None: + job_id = int(match.group(1)) + self.register_running_job(job_id, sample) + return job_id - raise CuckooAnalysisFailedException( - 'Unable to extract job ID from given string %s' % out) + raise CuckooSubmitFailedException( + 'Unable to extract job ID from given string %s' % out) def get_report(self, job_id): path = os.path.join(self.cuckoo_storage, @@ -306,7 +307,7 @@ class CuckooApi(Cuckoo): if task_id > 0: self.register_running_job(task_id, sample) return task_id - raise CuckooAnalysisFailedException( + raise CuckooSubmitFailedException( 'Unable to extract job ID from given string %s' % response) def get_report(self, job_id): |