mirror of
https://github.com/cuckoosandbox/cuckoo.git
synced 2026-10-12 02:12:40 +00:00
Fixed valid docstrings to comply with PEP 257
This commit is contained in:
committed by
Ricardo van Zutphen
parent
1341162ae3
commit
d168984fc0
+3
-3
@@ -38,7 +38,7 @@ def json_error(status_code, message):
|
||||
return r
|
||||
|
||||
def shutdown_server():
|
||||
"""Shutdown API werkzeug server"""
|
||||
"""Shutdown API werkzeug server."""
|
||||
shutdown = request.environ.get("werkzeug.server.shutdown")
|
||||
if shutdown:
|
||||
shutdown()
|
||||
@@ -676,8 +676,8 @@ def vpn_status():
|
||||
|
||||
@app.route("/exit")
|
||||
def exit_api():
|
||||
"""Shuts down the server if in debug mode and
|
||||
using the werkzeug server"""
|
||||
"""Shut down the server if in debug mode and
|
||||
using the werkzeug server."""
|
||||
if not app.debug:
|
||||
return json_error(403, "This call can only be used in debug mode")
|
||||
|
||||
|
||||
+2
-2
@@ -99,7 +99,7 @@ def fetch_community(branch="master", force=False, filepath=None):
|
||||
open(filepath, "wb").write(t.extractfile(member).read())
|
||||
|
||||
def enumerate_files(path, pattern):
|
||||
"""Yields all filepaths from a directory."""
|
||||
"""Yield all filepaths from a directory."""
|
||||
if os.path.isfile(path):
|
||||
yield path
|
||||
elif os.path.isdir(path):
|
||||
@@ -346,7 +346,7 @@ def process_tasks(instance, maxcount, timeout):
|
||||
|
||||
def cuckoo_clean():
|
||||
"""Clean up cuckoo setup.
|
||||
It deletes logs, all stored data from file system and configured
|
||||
Delete logs, all stored data from file system and configured
|
||||
databases (SQL and MongoDB).
|
||||
"""
|
||||
# Init logging (without writing to file).
|
||||
|
||||
@@ -59,7 +59,7 @@ def rt_available(rt_table):
|
||||
return False
|
||||
|
||||
def vpn_status():
|
||||
"""Gets current VPN status."""
|
||||
"""Get current VPN status."""
|
||||
ret = {}
|
||||
for line in run(s.service, "openvpn", "status")[0].split("\n"):
|
||||
x = re.search("'(?P<vpn>\\w+)'\\ is\\ (?P<running>not)?", line)
|
||||
@@ -125,7 +125,7 @@ def init_rttable(rt_table, interface):
|
||||
run(s.ip, *args)
|
||||
|
||||
def flush_rttable(rt_table):
|
||||
"""Flushes specified routing table entries."""
|
||||
"""Flush specified routing table entries."""
|
||||
if rt_table in ["local", "main", "default"]:
|
||||
return
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class Replay(Auxiliary):
|
||||
self.port = None
|
||||
|
||||
def pcap2mitm(self, pcappath, tlsmaster):
|
||||
"""Used to translate a .pcap into a .mitm file."""
|
||||
"""Translate a .pcap into a .mitm file."""
|
||||
mitmpath = tempfile.mktemp(suffix=".mitm")
|
||||
with open(mitmpath, "wb") as f:
|
||||
httpreplay.utils.pcap2mitm(pcappath, f, tlsmaster, True)
|
||||
|
||||
@@ -14,7 +14,7 @@ log = logging.getLogger(__name__)
|
||||
db = Database()
|
||||
|
||||
class Services(Auxiliary):
|
||||
"""Allows one or more additional VMs to be run next to an analysis. Either
|
||||
"""Allow one or more additional VMs to be run next to an analysis. Either
|
||||
as global services (which are generally never rebooted) or on a
|
||||
per-analysis basis."""
|
||||
|
||||
|
||||
+41
-41
@@ -166,7 +166,7 @@ class Machinery(object):
|
||||
pass
|
||||
|
||||
def pcap_path(self, task_id):
|
||||
"""Returns the .pcap path for this task id."""
|
||||
"""Return the .pcap path for this task id."""
|
||||
return cwd("storage", "analyses", "%s" % task_id, "dump.pcap")
|
||||
|
||||
def set_options(self, options):
|
||||
@@ -228,7 +228,7 @@ class Machinery(object):
|
||||
)
|
||||
|
||||
def _initialize_check(self):
|
||||
"""Runs checks against virtualization software when a machine manager
|
||||
"""Run checks against virtualization software when a machine manager
|
||||
is initialized.
|
||||
@note: in machine manager modules you may override or superclass
|
||||
his method.
|
||||
@@ -271,7 +271,7 @@ class Machinery(object):
|
||||
return self.db.list_machines()
|
||||
|
||||
def availables(self):
|
||||
"""How many machines are free.
|
||||
"""Return how many machines are free.
|
||||
@return: free machines count.
|
||||
"""
|
||||
return self.db.count_machines_available()
|
||||
@@ -297,13 +297,13 @@ class Machinery(object):
|
||||
self.db.unlock_machine(label)
|
||||
|
||||
def running(self):
|
||||
"""Returns running virtual machines.
|
||||
"""Return running virtual machines.
|
||||
@return: running virtual machines list.
|
||||
"""
|
||||
return self.db.list_machines(locked=True)
|
||||
|
||||
def shutdown(self):
|
||||
"""Shutdown the machine manager. Kills all alive machines.
|
||||
"""Shutdown the machine manager and kill all alive machines.
|
||||
@raise CuckooMachineError: if unable to stop machine.
|
||||
"""
|
||||
if len(self.running()) > 0:
|
||||
@@ -339,13 +339,13 @@ class Machinery(object):
|
||||
raise NotImplementedError
|
||||
|
||||
def _list(self):
|
||||
"""Lists virtual machines configured.
|
||||
"""List virtual machines configured.
|
||||
@raise NotImplementedError: this method is abstract.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def dump_memory(self, label, path):
|
||||
"""Takes a memory dump of a machine.
|
||||
"""Take a memory dump of a machine.
|
||||
@param path: path to where to store the memory dump.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
@@ -372,7 +372,7 @@ class Machinery(object):
|
||||
raise NotImplementedError
|
||||
|
||||
def _wait_status(self, label, *states):
|
||||
"""Waits for a vm status.
|
||||
"""Wait 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.
|
||||
@@ -433,7 +433,7 @@ class LibVirtMachinery(Machinery):
|
||||
super(LibVirtMachinery, self).initialize(module)
|
||||
|
||||
def _initialize_check(self):
|
||||
"""Runs all checks when a machine manager is initialized.
|
||||
"""Run all checks when a machine manager is initialized.
|
||||
@raise CuckooMachineError: if libvirt version is not supported.
|
||||
"""
|
||||
# Version checks.
|
||||
@@ -449,7 +449,7 @@ class LibVirtMachinery(Machinery):
|
||||
super(LibVirtMachinery, self)._initialize_check()
|
||||
|
||||
def start(self, label, task):
|
||||
"""Starts a virtual machine.
|
||||
"""Start a virtual machine.
|
||||
@param label: virtual machine name.
|
||||
@param task: task object.
|
||||
@raise CuckooMachineError: if unable to start virtual machine.
|
||||
@@ -502,7 +502,7 @@ class LibVirtMachinery(Machinery):
|
||||
self._wait_status(label, self.RUNNING)
|
||||
|
||||
def stop(self, label):
|
||||
"""Stops a virtual machine. Kill them all.
|
||||
"""Stop a virtual machine. Kill them all.
|
||||
@param label: virtual machine name.
|
||||
@raise CuckooMachineError: if unable to stop virtual machine.
|
||||
"""
|
||||
@@ -536,7 +536,7 @@ class LibVirtMachinery(Machinery):
|
||||
self.vms = None
|
||||
|
||||
def dump_memory(self, label, path):
|
||||
"""Takes a memory dump.
|
||||
"""Take a memory dump.
|
||||
@param path: path to where to store the memory dump.
|
||||
"""
|
||||
log.debug("Dumping memory for machine %s", label)
|
||||
@@ -555,7 +555,7 @@ class LibVirtMachinery(Machinery):
|
||||
self._disconnect(conn)
|
||||
|
||||
def _status(self, label):
|
||||
"""Gets current status of a vm.
|
||||
"""Get current status of a vm.
|
||||
@param label: virtual machine name.
|
||||
@return: status string.
|
||||
"""
|
||||
@@ -600,7 +600,7 @@ class LibVirtMachinery(Machinery):
|
||||
"{0}".format(label))
|
||||
|
||||
def _connect(self):
|
||||
"""Connects to libvirt subsystem.
|
||||
"""Connect to libvirt subsystem.
|
||||
@raise CuckooMachineError: when unable to connect to libvirt.
|
||||
"""
|
||||
# Check if a connection string is available.
|
||||
@@ -614,7 +614,7 @@ class LibVirtMachinery(Machinery):
|
||||
raise CuckooMachineError("Cannot connect to libvirt")
|
||||
|
||||
def _disconnect(self, conn):
|
||||
"""Disconnects to libvirt subsystem.
|
||||
"""Disconnect from libvirt subsystem.
|
||||
@raise CuckooMachineError: if cannot disconnect from libvirt.
|
||||
"""
|
||||
try:
|
||||
@@ -870,7 +870,7 @@ class Signature(object):
|
||||
pass
|
||||
|
||||
def _check_value(self, pattern, subject, regex=False, all=False):
|
||||
"""Checks a pattern against a given subject.
|
||||
"""Check a pattern against a given subject.
|
||||
@param pattern: string or expression to check for.
|
||||
@param subject: target of the check.
|
||||
@param regex: boolean representing if the pattern is a regular
|
||||
@@ -995,7 +995,7 @@ class Signature(object):
|
||||
|
||||
def check_file(self, pattern, regex=False, actions=None, pid=None,
|
||||
all=False):
|
||||
"""Checks for a file being opened.
|
||||
"""Check for a file being opened.
|
||||
@param pattern: string or expression to check for.
|
||||
@param regex: boolean representing if the pattern is a regular
|
||||
expression or not and therefore should be compiled.
|
||||
@@ -1018,7 +1018,7 @@ class Signature(object):
|
||||
|
||||
def check_dll_loaded(self, pattern, regex=False, actions=None, pid=None,
|
||||
all=False):
|
||||
"""Checks for DLLs being loaded.
|
||||
"""Check for DLLs being loaded.
|
||||
@param pattern: string or expression to check for.
|
||||
@param regex: boolean representing if the pattern is a regular
|
||||
expression or not and therefore should be compiled.
|
||||
@@ -1032,7 +1032,7 @@ class Signature(object):
|
||||
all=all)
|
||||
|
||||
def check_command_line(self, pattern, regex=False, all=False):
|
||||
"""Checks for a command line being opened.
|
||||
"""Check for a command line being opened.
|
||||
@param pattern: string or expression to check for.
|
||||
@param regex: boolean representing if the pattern is a regular
|
||||
expression or not and therefore should be compiled.
|
||||
@@ -1045,7 +1045,7 @@ class Signature(object):
|
||||
|
||||
def check_key(self, pattern, regex=False, actions=None, pid=None,
|
||||
all=False):
|
||||
"""Checks for a registry key being accessed.
|
||||
"""Check for a registry key being accessed.
|
||||
@param pattern: string or expression to check for.
|
||||
@param regex: boolean representing if the pattern is a regular
|
||||
expression or not and therefore should be compiled.
|
||||
@@ -1073,7 +1073,7 @@ class Signature(object):
|
||||
return self.get_summary_generic(pid, ["mutex"])
|
||||
|
||||
def check_mutex(self, pattern, regex=False, all=False):
|
||||
"""Checks for a mutex being opened.
|
||||
"""Check for a mutex being opened.
|
||||
@param pattern: string or expression to check for.
|
||||
@param regex: boolean representing if the pattern is a regular
|
||||
expression or not and therefore should be compiled.
|
||||
@@ -1085,11 +1085,11 @@ class Signature(object):
|
||||
all=all)
|
||||
|
||||
def get_command_lines(self):
|
||||
"""Retrieves all command lines used."""
|
||||
"""Retrieve all command lines used."""
|
||||
return self.get_summary("command_line")
|
||||
|
||||
def get_wmi_queries(self):
|
||||
"""Retrieves all executed WMI queries."""
|
||||
"""Retrieve all executed WMI queries."""
|
||||
return self.get_summary("wmi_query")
|
||||
|
||||
def get_net_generic(self, subtype):
|
||||
@@ -1100,68 +1100,68 @@ class Signature(object):
|
||||
return self.get_results("network", {}).get(subtype, [])
|
||||
|
||||
def get_net_hosts(self):
|
||||
"""Returns a list of all hosts."""
|
||||
"""Return a list of all hosts."""
|
||||
return self.get_net_generic("hosts")
|
||||
|
||||
def get_net_domains(self):
|
||||
"""Returns a list of all domains."""
|
||||
"""Return a list of all domains."""
|
||||
return self.get_net_generic("domains")
|
||||
|
||||
def get_net_http(self):
|
||||
"""Returns a list of all http data."""
|
||||
"""Return a list of all http data."""
|
||||
return self.get_net_generic("http")
|
||||
|
||||
def get_net_http_ex(self):
|
||||
"""Returns a list of all http data."""
|
||||
"""Return a list of all http data."""
|
||||
return \
|
||||
self.get_net_generic("http_ex") + self.get_net_generic("https_ex")
|
||||
|
||||
def get_net_udp(self):
|
||||
"""Returns a list of all udp data."""
|
||||
"""Return a list of all udp data."""
|
||||
return self.get_net_generic("udp")
|
||||
|
||||
def get_net_icmp(self):
|
||||
"""Returns a list of all icmp data."""
|
||||
"""Return a list of all icmp data."""
|
||||
return self.get_net_generic("icmp")
|
||||
|
||||
def get_net_irc(self):
|
||||
"""Returns a list of all irc data."""
|
||||
"""Return a list of all irc data."""
|
||||
return self.get_net_generic("irc")
|
||||
|
||||
def get_net_smtp(self):
|
||||
"""Returns a list of all smtp data."""
|
||||
"""Return a list of all smtp data."""
|
||||
return self.get_net_generic("smtp")
|
||||
|
||||
def get_net_smtp_ex(self):
|
||||
""""Returns a list of all smtp data"""
|
||||
""""Return a list of all smtp data"""
|
||||
return self.get_net_generic("smtp_ex")
|
||||
|
||||
def get_virustotal(self):
|
||||
"""Returns the information retrieved from virustotal."""
|
||||
"""Return the information retrieved from virustotal."""
|
||||
return self.get_results("virustotal", {})
|
||||
|
||||
def get_volatility(self, module=None):
|
||||
"""Returns the data that belongs to the given module."""
|
||||
"""Return the data that belongs to the given module."""
|
||||
volatility = self.get_results("memory", {})
|
||||
return volatility if module is None else volatility.get(module, {})
|
||||
|
||||
def get_apkinfo(self, section=None, default={}):
|
||||
"""Returns the apkinfo results for this analysis."""
|
||||
"""Return the apkinfo results for this analysis."""
|
||||
apkinfo = self.get_results("apkinfo", {})
|
||||
return apkinfo if section is None else apkinfo.get(section, default)
|
||||
|
||||
def get_droidmon(self, section=None, default={}):
|
||||
"""Returns the droidmon results for this analysis."""
|
||||
"""Return the droidmon results for this analysis."""
|
||||
droidmon = self.get_results("droidmon", {})
|
||||
return droidmon if section is None else droidmon.get(section, default)
|
||||
|
||||
def get_googleplay(self, section=None, default={}):
|
||||
"""Returns the Google Play results for this analysis."""
|
||||
"""Return the Google Play results for this analysis."""
|
||||
googleplay = self.get_results("googleplay", {})
|
||||
return googleplay if section is None else googleplay.get(section, default)
|
||||
|
||||
def check_ip(self, pattern, regex=False, all=False):
|
||||
"""Checks for an IP address being contacted.
|
||||
"""Check for an IP address being contacted.
|
||||
@param pattern: string or expression to check for.
|
||||
@param regex: boolean representing if the pattern is a regular
|
||||
expression or not and therefore should be compiled.
|
||||
@@ -1173,7 +1173,7 @@ class Signature(object):
|
||||
all=all)
|
||||
|
||||
def check_domain(self, pattern, regex=False, all=False):
|
||||
"""Checks for a domain being contacted.
|
||||
"""Check for a domain being contacted.
|
||||
@param pattern: string or expression to check for.
|
||||
@param regex: boolean representing if the pattern is a regular
|
||||
expression or not and therefore should be compiled.
|
||||
@@ -1189,7 +1189,7 @@ class Signature(object):
|
||||
all=all)
|
||||
|
||||
def check_url(self, pattern, regex=False, all=False):
|
||||
"""Checks for a URL being contacted.
|
||||
"""Check for a URL being contacted.
|
||||
@param pattern: string or expression to check for.
|
||||
@param regex: boolean representing if the pattern is a regular
|
||||
expression or not and therefore should be compiled.
|
||||
@@ -1279,7 +1279,7 @@ class Signature(object):
|
||||
self.marks.append(mark)
|
||||
|
||||
def has_marks(self, count=None):
|
||||
"""Returns true if this signature has one or more marks."""
|
||||
"""Return true if this signature has one or more marks."""
|
||||
if count is not None:
|
||||
return len(self.marks) >= count
|
||||
return not not self.marks
|
||||
|
||||
@@ -148,7 +148,7 @@ class UUID(Type):
|
||||
log.error("Incorrect UUID %s", value)
|
||||
|
||||
def check(self, value):
|
||||
"""Checks if the value is of type UUID."""
|
||||
"""Check if the value is of type UUID."""
|
||||
try:
|
||||
click.UUID(value)
|
||||
return True
|
||||
@@ -1042,7 +1042,7 @@ class Config(object):
|
||||
|
||||
@staticmethod
|
||||
def from_confdir(dirpath, loose=False, sanitize=False):
|
||||
"""Reads all the configuration from a configuration directory. If
|
||||
"""Read all the configuration from a configuration directory. If
|
||||
`sanitize` is set, then black out sensitive fields."""
|
||||
ret = {}
|
||||
for filename in os.listdir(dirpath):
|
||||
@@ -1183,7 +1183,7 @@ def cast(s, value):
|
||||
return type_.parse(value)
|
||||
|
||||
def read_kv_conf(filepath):
|
||||
"""Reads a flat Cuckoo key/value configuration file."""
|
||||
"""Read a flat Cuckoo key/value configuration file."""
|
||||
ret = {}
|
||||
for line in open(filepath, "rb"):
|
||||
line = line.strip()
|
||||
|
||||
@@ -36,9 +36,9 @@ def set_timeout_value(value):
|
||||
# standard gethostbyname in thread
|
||||
# http://code.activestate.com/recipes/473878/
|
||||
def with_timeout(func, args=(), kwargs={}):
|
||||
"""This function will spawn a thread and run the given function
|
||||
using the args, kwargs and return the given default value if the
|
||||
timeout_duration is exceeded.
|
||||
"""Spawn a thread and run the given function using the args,
|
||||
kwargs and return the given default value if the timeout_duration
|
||||
is exceeded.
|
||||
"""
|
||||
class ResultThread(threading.Thread):
|
||||
daemon = True
|
||||
|
||||
@@ -13,7 +13,7 @@ from cuckoo.common.exceptions import CuckooOperationalError
|
||||
from cuckoo.misc import getuser
|
||||
|
||||
def temppath():
|
||||
"""Returns the true temporary directory."""
|
||||
"""Return the true temporary directory."""
|
||||
tmppath = config("cuckoo:cuckoo:tmppath")
|
||||
|
||||
# Backwards compatibility with older configuration.
|
||||
@@ -37,7 +37,7 @@ class Storage(object):
|
||||
class Folders(Storage):
|
||||
@staticmethod
|
||||
def create(root=".", folders=None):
|
||||
"""Creates a directory or multiple directories.
|
||||
"""Create a directory or multiple directories.
|
||||
@param root: root path.
|
||||
@param folders: folders list to be created.
|
||||
@raise CuckooOperationalError: if fails to create folder.
|
||||
@@ -149,7 +149,7 @@ class Files(Storage):
|
||||
|
||||
@staticmethod
|
||||
def hash_file(method, filepath):
|
||||
"""Calculates an hash on a file by path.
|
||||
"""Calculate a hash on a file by path.
|
||||
@param method: callable hashing method
|
||||
@param path: file path
|
||||
@return: computed hash string
|
||||
|
||||
@@ -55,7 +55,7 @@ def default_converter_64bit(v):
|
||||
return v
|
||||
|
||||
class BsonParser(ProtocolHandler):
|
||||
"""Receives and interprets .bson logs from the monitor.
|
||||
"""Receive and interpret .bson logs from the monitor.
|
||||
|
||||
The monitor provides us with "info" messages that explain how the function
|
||||
arguments will come through later on. This class remembers these info
|
||||
@@ -117,9 +117,9 @@ class BsonParser(ProtocolHandler):
|
||||
flags[argument] = "|".join(flags[argument])
|
||||
|
||||
def determine_unserializers(self, arginfo):
|
||||
"""Determines which unserializers (or converters) have to be used in
|
||||
order to parse the various arguments for this function call. Keeps in
|
||||
mind whether the current bson is 32-bit or 64-bit."""
|
||||
"""Determine which unserializers (or converters) have to be used in
|
||||
order to parse the various arguments for this function call. Maintains
|
||||
whether the current bson is 32-bit or 64-bit."""
|
||||
argnames, converters = [], []
|
||||
|
||||
for argument in arginfo:
|
||||
|
||||
@@ -105,7 +105,7 @@ class CmdExe(Scripting):
|
||||
return " ".join(self.args.get("command", []))
|
||||
|
||||
def ps1_cmdarg(s, minimum=1):
|
||||
"""Creates an exactly matching PowerShell command line argument regex,
|
||||
"""Create an exactly matching PowerShell command line argument regex,
|
||||
instead of a regex that matches anything with the same characters."""
|
||||
return "".join(
|
||||
"([%s%s^]" % (ch.lower(), ch.upper()) for ch in s
|
||||
|
||||
@@ -35,7 +35,7 @@ PRINTABLE_CHARACTERS = (
|
||||
)
|
||||
|
||||
def convert_char(c):
|
||||
"""Escapes characters.
|
||||
"""Escape characters.
|
||||
@param c: dirty char.
|
||||
@return: sanitized char.
|
||||
"""
|
||||
@@ -75,14 +75,14 @@ def constant_time_compare(a, b):
|
||||
return result == 0
|
||||
|
||||
def validate_hash(h):
|
||||
"""Validates a hash by length and contents."""
|
||||
"""Validate a hash by length and contents."""
|
||||
if len(h) not in (32, 40, 64, 128):
|
||||
return False
|
||||
|
||||
return bool(re.match("[0-9a-fA-F]*$", h))
|
||||
|
||||
def validate_url(url, allow_invalid=False):
|
||||
"""Validates an URL using Django's built-in URL validator"""
|
||||
"""Validate an URL using Django's built-in URL validator"""
|
||||
from django.core.validators import URLValidator
|
||||
val = URLValidator(schemes=["http", "https"])
|
||||
|
||||
@@ -230,7 +230,7 @@ def guid_name(guid):
|
||||
return GUIDS.get(guid)
|
||||
|
||||
def exception_message():
|
||||
"""Creates a message describing an unhandled exception."""
|
||||
"""Create a message describing an unhandled exception."""
|
||||
def get_os_release():
|
||||
"""Returns detailed OS release."""
|
||||
if platform.linux_distribution()[0]:
|
||||
@@ -271,7 +271,7 @@ _jsbeautify_blacklist = [
|
||||
_jsbeautify_lock = threading.Lock()
|
||||
|
||||
def jsbeautify(javascript):
|
||||
"""Beautifies Javascript through jsbeautifier and ignore some messages."""
|
||||
"""Beautify Javascript through jsbeautifier and ignore some messages."""
|
||||
with _jsbeautify_lock:
|
||||
origout, sys.stdout = sys.stdout, io.StringIO()
|
||||
|
||||
@@ -289,7 +289,7 @@ def jsbeautify(javascript):
|
||||
return javascript
|
||||
|
||||
def htmlprettify(html):
|
||||
"""Beautifies HTML through BeautifulSoup4."""
|
||||
"""Beautify HTML through BeautifulSoup4."""
|
||||
# The following ignores the following bs4 warning:
|
||||
# UserWarning: "." looks like a filename, not markup.
|
||||
with warnings.catch_warnings():
|
||||
@@ -297,7 +297,7 @@ def htmlprettify(html):
|
||||
return bs4.BeautifulSoup(html, "html.parser").prettify()
|
||||
|
||||
def json_default(obj):
|
||||
"""JSON serializer for objects not serializable by default json code"""
|
||||
"""JSON serialize objects not serializable by default json code"""
|
||||
if hasattr(obj, "to_dict"):
|
||||
return obj.to_dict()
|
||||
|
||||
@@ -330,7 +330,7 @@ def parse_bool(value):
|
||||
return bool(int(value))
|
||||
|
||||
def supported_version(version, minimum, maximum):
|
||||
"""Checks if a version number is supported as per the minimum and maximum
|
||||
"""Check if a version number is supported as per the minimum and maximum
|
||||
version numbers."""
|
||||
if minimum and StrictVersion(version) < StrictVersion(minimum):
|
||||
return False
|
||||
|
||||
+27
-27
@@ -120,7 +120,7 @@ class Machine(Base):
|
||||
self._rcparams = value
|
||||
|
||||
def to_dict(self):
|
||||
"""Converts object to dict.
|
||||
"""Convert object to dict.
|
||||
@return: dict
|
||||
"""
|
||||
d = {}
|
||||
@@ -136,7 +136,7 @@ class Machine(Base):
|
||||
return d
|
||||
|
||||
def to_json(self):
|
||||
"""Converts object to JSON.
|
||||
"""Convert object to JSON.
|
||||
@return: JSON data
|
||||
"""
|
||||
return json.dumps(self.to_dict())
|
||||
@@ -198,7 +198,7 @@ class Guest(Base):
|
||||
return "<Guest('{0}','{1}')>".format(self.id, self.name)
|
||||
|
||||
def to_dict(self):
|
||||
"""Converts object to dict.
|
||||
"""Convert object to dict.
|
||||
@return: dict
|
||||
"""
|
||||
d = {}
|
||||
@@ -211,7 +211,7 @@ class Guest(Base):
|
||||
return d
|
||||
|
||||
def to_json(self):
|
||||
"""Converts object to JSON.
|
||||
"""Convert object to JSON.
|
||||
@return: JSON data
|
||||
"""
|
||||
return json.dumps(self.to_dict())
|
||||
@@ -256,7 +256,7 @@ class Sample(Base):
|
||||
return "<Sample('{0}','{1}')>".format(self.id, self.sha256)
|
||||
|
||||
def to_dict(self):
|
||||
"""Converts object to dict.
|
||||
"""Convert object to dict.
|
||||
@return: dict
|
||||
"""
|
||||
d = {}
|
||||
@@ -265,7 +265,7 @@ class Sample(Base):
|
||||
return d
|
||||
|
||||
def to_json(self):
|
||||
"""Converts object to JSON.
|
||||
"""Convert object to JSON.
|
||||
@return: JSON data
|
||||
"""
|
||||
return json.dumps(self.to_dict())
|
||||
@@ -291,7 +291,7 @@ class Error(Base):
|
||||
task_id = Column(Integer, ForeignKey("tasks.id"), nullable=False)
|
||||
|
||||
def to_dict(self):
|
||||
"""Converts object to dict.
|
||||
"""Convert object to dict.
|
||||
@return: dict
|
||||
"""
|
||||
d = {}
|
||||
@@ -300,7 +300,7 @@ class Error(Base):
|
||||
return d
|
||||
|
||||
def to_json(self):
|
||||
"""Converts object to JSON.
|
||||
"""Convert object to JSON.
|
||||
@return: JSON data
|
||||
"""
|
||||
return json.dumps(self.to_dict())
|
||||
@@ -371,7 +371,7 @@ class Task(Base):
|
||||
self._options = value
|
||||
|
||||
def to_dict(self, dt=False):
|
||||
"""Converts object to dict.
|
||||
"""Convert object to dict.
|
||||
@param dt: encode datetime objects
|
||||
@return: dict
|
||||
"""
|
||||
@@ -398,7 +398,7 @@ class Task(Base):
|
||||
return d
|
||||
|
||||
def to_json(self):
|
||||
"""Converts object to JSON.
|
||||
"""Convert object to JSON.
|
||||
@return: JSON data
|
||||
"""
|
||||
return json_encode(self.to_dict())
|
||||
@@ -465,7 +465,7 @@ class Database(object):
|
||||
self._create_tables()
|
||||
|
||||
def _create_tables(self):
|
||||
"""Creates all the database tables etc."""
|
||||
"""Create all database tables etc."""
|
||||
try:
|
||||
Base.metadata.create_all(self.engine)
|
||||
except SQLAlchemyError as e:
|
||||
@@ -509,7 +509,7 @@ class Database(object):
|
||||
self.engine.dispose()
|
||||
|
||||
def _connect_database(self, connection_string):
|
||||
"""Connect to a Database.
|
||||
"""Connect to a database.
|
||||
@param connection_string: Connection string specifying the database
|
||||
"""
|
||||
try:
|
||||
@@ -677,7 +677,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def fetch(self, machine=None, service=True):
|
||||
"""Fetches a task waiting to be processed and locks it for running.
|
||||
"""Fetch a task waiting to be processed and lock it for running.
|
||||
@return: None or task
|
||||
"""
|
||||
session = self.Session()
|
||||
@@ -704,7 +704,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def guest_start(self, task_id, name, label, manager):
|
||||
"""Logs guest start.
|
||||
"""Log guest start.
|
||||
@param task_id: task identifier
|
||||
@param name: vm name
|
||||
@param label: vm label
|
||||
@@ -728,7 +728,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def guest_get_status(self, task_id):
|
||||
"""Logs guest start.
|
||||
"""Log guest start.
|
||||
@param task_id: task id
|
||||
@return: guest status
|
||||
"""
|
||||
@@ -745,7 +745,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def guest_set_status(self, task_id, status):
|
||||
"""Logs guest start.
|
||||
"""Log guest start.
|
||||
@param task_id: task identifier
|
||||
@param status: status
|
||||
"""
|
||||
@@ -764,7 +764,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def guest_remove(self, guest_id):
|
||||
"""Removes a guest start entry."""
|
||||
"""Remove a guest start entry."""
|
||||
session = self.Session()
|
||||
try:
|
||||
guest = session.query(Guest).get(guest_id)
|
||||
@@ -779,7 +779,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def guest_stop(self, guest_id):
|
||||
"""Logs guest stop.
|
||||
"""Log guest stop.
|
||||
@param guest_id: guest log entry id
|
||||
"""
|
||||
session = self.Session()
|
||||
@@ -799,7 +799,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def list_machines(self, locked=False):
|
||||
"""Lists virtual machines.
|
||||
"""List virtual machines.
|
||||
@return: list of virtual machines
|
||||
"""
|
||||
session = self.Session()
|
||||
@@ -817,7 +817,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def lock_machine(self, label=None, platform=None, tags=None):
|
||||
"""Places a lock on a free virtual machine.
|
||||
"""Place a lock on a free virtual machine.
|
||||
@param label: optional virtual machine label
|
||||
@param platform: optional virtual machine platform
|
||||
@param tags: optional tags required (list)
|
||||
@@ -876,7 +876,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def unlock_machine(self, label):
|
||||
"""Remove lock form a virtual machine.
|
||||
"""Remove a lock from a virtual machine.
|
||||
@param label: virtual machine label
|
||||
@return: unlocked machine
|
||||
"""
|
||||
@@ -905,7 +905,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def count_machines_available(self):
|
||||
"""How many virtual machines are ready for analysis.
|
||||
"""Return number of virtual machines ready for analysis.
|
||||
@return: free virtual machines count
|
||||
"""
|
||||
session = self.Session()
|
||||
@@ -920,7 +920,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def get_available_machines(self):
|
||||
""" Which machines are available
|
||||
"""Return machines that are available.
|
||||
@return: free virtual machines
|
||||
"""
|
||||
session = self.Session()
|
||||
@@ -1406,7 +1406,7 @@ class Database(object):
|
||||
session.close()
|
||||
|
||||
def minmax_tasks(self):
|
||||
"""Find tasks minimum and maximum
|
||||
"""Find tasks minimum and maximum.
|
||||
@return: unix timestamps of minimum and maximum
|
||||
"""
|
||||
session = self.Session()
|
||||
@@ -1426,7 +1426,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def count_tasks(self, status=None):
|
||||
"""Count tasks in the database
|
||||
"""Count tasks in the database.
|
||||
@param status: apply a filter according to the task status
|
||||
@return: number of tasks found
|
||||
"""
|
||||
@@ -1513,7 +1513,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def view_sample(self, sample_id):
|
||||
"""Retrieve information on a sample given a sample id.
|
||||
"""Retrieve information on a sample given a sample ID.
|
||||
@param sample_id: ID of the sample to query.
|
||||
@return: details on the sample used in sample: sample_id.
|
||||
"""
|
||||
@@ -1557,7 +1557,7 @@ class Database(object):
|
||||
|
||||
@classlock
|
||||
def count_samples(self):
|
||||
"""Counts the amount of samples in the database."""
|
||||
"""Count number of samples in the database."""
|
||||
session = self.Session()
|
||||
try:
|
||||
sample_count = session.query(Sample).count()
|
||||
|
||||
@@ -18,7 +18,7 @@ from cuckoo.misc import version, cwd
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class CuckooFeedback(object):
|
||||
"""Contacts Cuckoo HQ with feedback & optional analysis dump."""
|
||||
"""Contact Cuckoo HQ with feedback & optional analysis dump."""
|
||||
endpoint = "https://feedback.cuckoosandbox.org/api/submit/"
|
||||
exc_whitelist = (
|
||||
CuckooFeedbackError,
|
||||
@@ -200,7 +200,7 @@ class CuckooFeedbackObject(object):
|
||||
return self.include_report(report)
|
||||
|
||||
def gather_export_files(self, dirpath):
|
||||
"""Returns a list of all files of interest from an analysis."""
|
||||
"""Return a list of all files of interest from an analysis."""
|
||||
ret = []
|
||||
for name in self.export_files:
|
||||
if isinstance(name, basestring):
|
||||
|
||||
@@ -30,7 +30,7 @@ log = logging.getLogger(__name__)
|
||||
db = Database()
|
||||
|
||||
def analyzer_zipfile(platform, monitor):
|
||||
"""Creates the Zip file that is sent to the Guest."""
|
||||
"""Create the zip file that is sent to the Guest."""
|
||||
t = time.time()
|
||||
|
||||
zip_data = io.BytesIO()
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ from cuckoo.common.utils import random_token
|
||||
from cuckoo.misc import cwd
|
||||
|
||||
def write_supervisor_conf(username):
|
||||
"""Writes supervisord.conf configuration file if it does not exist yet."""
|
||||
"""Write supervisord.conf configuration file if it does not exist yet."""
|
||||
# TODO Handle updates?
|
||||
if os.path.exists(cwd("supervisord.conf")):
|
||||
return
|
||||
|
||||
@@ -466,7 +466,7 @@ class RunSignatures(object):
|
||||
self.api_sigs[call["api"]].remove(sig)
|
||||
|
||||
def process_yara_matches(self):
|
||||
"""Yields any Yara matches to each signature."""
|
||||
"""Yield any Yara matches to each signature."""
|
||||
def loop_yara(category, filepath, matches):
|
||||
for match in matches:
|
||||
match = YaraMatch(match, category)
|
||||
@@ -650,7 +650,7 @@ class RunReporting(object):
|
||||
)
|
||||
|
||||
def run(self):
|
||||
"""Generates all reports.
|
||||
"""Generate all reports.
|
||||
@raise CuckooReportError: if a report module fails.
|
||||
"""
|
||||
# In every reporting module you can specify a numeric value that
|
||||
|
||||
@@ -138,7 +138,7 @@ class AnalysisManager(threading.Thread):
|
||||
return True
|
||||
|
||||
def store_task_info(self):
|
||||
"""grab latest task from db (if available) and update self.task"""
|
||||
"""Grab latest task from db (if available) and update self.task"""
|
||||
dbtask = self.db.view_task(self.task.id)
|
||||
self.task = dbtask.to_dict()
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ def check_specific_config(filename):
|
||||
)
|
||||
|
||||
def check_configs():
|
||||
"""Checks if config files exist.
|
||||
"""Check if config files exist.
|
||||
@raise CuckooStartupError: if config files do not exist.
|
||||
"""
|
||||
configs = (
|
||||
@@ -97,7 +97,7 @@ def check_configs():
|
||||
return True
|
||||
|
||||
def check_version():
|
||||
"""Checks version of Cuckoo."""
|
||||
"""Check version of Cuckoo."""
|
||||
if not config("cuckoo:cuckoo:version_check"):
|
||||
return
|
||||
|
||||
@@ -219,14 +219,14 @@ def check_version():
|
||||
return r
|
||||
|
||||
def init_logging(level):
|
||||
"""Initializes logging."""
|
||||
"""Initialize logging."""
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
init_logger("cuckoo.log", level)
|
||||
init_logger("cuckoo.json")
|
||||
init_logger("task")
|
||||
|
||||
def init_console_logging(level=logging.INFO):
|
||||
"""Initializes logging only to console and database."""
|
||||
"""Initialize logging only to console and database."""
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
init_logger("console", level)
|
||||
init_logger("database")
|
||||
@@ -258,7 +258,7 @@ def init_tasks():
|
||||
db.set_status(task.id, TASK_FAILED_ANALYSIS)
|
||||
|
||||
def init_modules():
|
||||
"""Initializes plugins."""
|
||||
"""Initialize plugins."""
|
||||
log.debug("Imported modules...")
|
||||
|
||||
categories = (
|
||||
@@ -503,7 +503,7 @@ def init_routing():
|
||||
rooter("init_rttable", rt_table, interface)
|
||||
|
||||
def ensure_tmpdir():
|
||||
"""Verifies if the current user can read and create files in the
|
||||
"""Verify if the current user can read and create files in the
|
||||
cuckoo temporary directory (and creates it, if needed)."""
|
||||
try:
|
||||
if not os.path.isdir(temppath()):
|
||||
|
||||
@@ -58,7 +58,7 @@ class SubmitManager(object):
|
||||
)
|
||||
|
||||
def translate_options_from(self, entry, options):
|
||||
"""Translates from Web Interface options to Cuckoo database options."""
|
||||
"""Translate from Web Interface options to Cuckoo database options."""
|
||||
ret = {}
|
||||
|
||||
if not options.get("simulated-human-interaction", True):
|
||||
@@ -88,7 +88,7 @@ class SubmitManager(object):
|
||||
return ret
|
||||
|
||||
def translate_options_to(self, options):
|
||||
"""Translates from Cuckoo database options to Web Interface options."""
|
||||
"""Translate from Cuckoo database options to Web Interface options."""
|
||||
ret = {}
|
||||
|
||||
if not int(options.get("human", "1")):
|
||||
@@ -147,7 +147,7 @@ class SubmitManager(object):
|
||||
|
||||
def get_files(self, submit_id, password=None, astree=False):
|
||||
"""
|
||||
Returns files or URLs from a submitted analysis.
|
||||
Return files or URLs from a submitted analysis.
|
||||
@param password: The password to unlock container archives with
|
||||
@param astree: sflock option; determines the format in which the files are returned
|
||||
@return: A tree of files
|
||||
@@ -195,7 +195,7 @@ class SubmitManager(object):
|
||||
return files, submit.data["errors"], submit.data["options"]
|
||||
|
||||
def submit(self, submit_id, config):
|
||||
"""Reads, interprets, and converts the JSON configuration provided by
|
||||
"""Read, interpret, and convert the JSON configuration provided by
|
||||
the Web Interface into something we insert into the database."""
|
||||
ret = []
|
||||
submit = db.view_submit(submit_id)
|
||||
|
||||
@@ -38,7 +38,7 @@ class Screenshot:
|
||||
return HAVE_PIL
|
||||
|
||||
def equal(self, img1, img2, skip_area=None):
|
||||
"""Compares two screenshots using Root-Mean-Square Difference (RMS).
|
||||
"""Compare two screenshots using Root-Mean-Square Difference (RMS).
|
||||
@param img1: screenshot to compare.
|
||||
@param img2: screenshot to compare.
|
||||
@return: equal status.
|
||||
|
||||
@@ -6,7 +6,7 @@ BUFSIZE = 1024*1024
|
||||
|
||||
|
||||
def hash_file(method, path):
|
||||
"""Calculates an hash on a file by path.
|
||||
"""Calculate a hash on a file by path.
|
||||
@param method: callable hashing method
|
||||
@param path: file path
|
||||
@return: computed hash string
|
||||
|
||||
@@ -90,7 +90,7 @@ class Zip(Package):
|
||||
|
||||
|
||||
def _prepare_archive_at_path(filename):
|
||||
""" Verifies that there's a readable zip archive at the given path.
|
||||
""" Verify that there's a readable zip archive at the given path.
|
||||
|
||||
This function returns a new name for the archive (for most cases it's
|
||||
the same as the original one; but if an archive named "foo.zip" contains
|
||||
|
||||
@@ -31,7 +31,7 @@ class Package(object):
|
||||
return True
|
||||
|
||||
def execute(self, cmd):
|
||||
"""Starts an executable for analysis.
|
||||
"""Start an executable for analysis.
|
||||
@param path: executable path
|
||||
@param args: executable arguments
|
||||
@return: process pid
|
||||
|
||||
@@ -10,7 +10,7 @@ def sha256_file(path):
|
||||
return hash_file(hashlib.sha256, path)
|
||||
|
||||
def hash_file(method, path):
|
||||
"""Calculates an hash on a file by path.
|
||||
"""Calculate a hash on a file by path.
|
||||
@param method: callable hashing method
|
||||
@param path: file path
|
||||
@return: computed hash string
|
||||
|
||||
@@ -14,7 +14,7 @@ from lib.core.config import Config
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class STAP(Auxiliary):
|
||||
"""system-wide syscall trace with stap."""
|
||||
"""System-wide syscall trace with stap."""
|
||||
priority = -10 # low prio to wrap tightly around the analysis
|
||||
|
||||
def __init__(self):
|
||||
|
||||
@@ -46,11 +46,11 @@ class Files(object):
|
||||
self.dumped = []
|
||||
|
||||
def is_protected_filename(self, file_name):
|
||||
"""Do we want to inject into a process with this name?"""
|
||||
"""Return whether or not to inject into a process with this name."""
|
||||
return file_name.lower() in self.PROTECTED_NAMES
|
||||
|
||||
def add_pid(self, filepath, pid, verbose=True):
|
||||
"""Tracks a process identifier for this file."""
|
||||
"""Track a process identifier for this file."""
|
||||
if not pid or filepath.lower() not in self.files:
|
||||
return
|
||||
|
||||
@@ -150,7 +150,7 @@ class ProcessList(object):
|
||||
self.add_pid(pids)
|
||||
|
||||
def has_pid(self, pid, notrack=True):
|
||||
"""Is this process identifier being tracked?"""
|
||||
"""Return whether or not this process identifier being tracked."""
|
||||
if int(pid) in self.pids:
|
||||
return True
|
||||
|
||||
@@ -435,7 +435,7 @@ class Analyzer(object):
|
||||
self.reboot = []
|
||||
|
||||
def get_pipe_path(self, name):
|
||||
"""Returns \\\\.\\PIPE on Windows XP and \\??\\PIPE elsewhere."""
|
||||
"""Return \\\\.\\PIPE on Windows XP and \\??\\PIPE elsewhere."""
|
||||
version = sys.getwindowsversion()
|
||||
if version.major == 5 and version.minor == 1:
|
||||
return "\\\\.\\PIPE\\%s" % name
|
||||
@@ -509,7 +509,7 @@ class Analyzer(object):
|
||||
self.target = self.config.target
|
||||
|
||||
def stop(self):
|
||||
"""Allows an auxiliary module to stop the analysis."""
|
||||
"""Allow an auxiliary module to stop the analysis."""
|
||||
self.do_run = False
|
||||
|
||||
def complete(self):
|
||||
|
||||
@@ -127,7 +127,7 @@ class Process(object):
|
||||
|
||||
@staticmethod
|
||||
def set_config(config):
|
||||
"""Sets the analyzer configuration once."""
|
||||
"""Set the analyzer configuration once."""
|
||||
Process.config = config
|
||||
|
||||
def get_system_info(self):
|
||||
|
||||
@@ -107,7 +107,7 @@ class Package(object):
|
||||
return outpath
|
||||
|
||||
def init_regkeys(self, regkeys):
|
||||
"""Initializes the registry to avoid annoying popups, configure
|
||||
"""Initialize the registry to avoid annoying popups, configure
|
||||
settings, etc.
|
||||
@param regkeys: the root keys, subkeys, and key/value pairs.
|
||||
"""
|
||||
@@ -130,7 +130,7 @@ class Package(object):
|
||||
|
||||
def execute(self, path, args, mode=None, maximize=False, env=None,
|
||||
source=None, trigger=None):
|
||||
"""Starts an executable for analysis.
|
||||
"""Start an executable for analysis.
|
||||
@param path: executable path
|
||||
@param args: executable arguments
|
||||
@param mode: monitor mode - which functions to instrument
|
||||
@@ -169,7 +169,7 @@ class Package(object):
|
||||
return p.pid
|
||||
|
||||
def package_files(self):
|
||||
"""A list of files to upload to host.
|
||||
"""Return a list of files to upload to host.
|
||||
The list should be a list of tuples (<path on guest>, <name of file in package_files folder>).
|
||||
(package_files is a folder that will be created in analysis folder).
|
||||
"""
|
||||
|
||||
@@ -7,7 +7,7 @@ BUFSIZE = 1024*1024
|
||||
|
||||
|
||||
def hash_file(method, path):
|
||||
"""Calculates an hash on a file by path.
|
||||
"""Calculate a hash on a file by path.
|
||||
@param method: callable hashing method
|
||||
@param path: file path
|
||||
@return: computed hash string
|
||||
|
||||
@@ -21,8 +21,8 @@ log = logging.getLogger(__name__)
|
||||
BUFSIZE = 0x10000
|
||||
|
||||
class PipeForwarder(threading.Thread):
|
||||
"""The Pipe Forwarder forwards all data received from a local pipe to
|
||||
the Cuckoo server through a socket."""
|
||||
"""Forward all data received from a local pipe to the Cuckoo
|
||||
server through a socket."""
|
||||
sockets = {}
|
||||
active = {}
|
||||
|
||||
@@ -99,8 +99,8 @@ class PipeForwarder(threading.Thread):
|
||||
self.active[pid.value] = False
|
||||
|
||||
class PipeDispatcher(threading.Thread):
|
||||
"""Receives commands through a local pipe, forwards them to the
|
||||
dispatcher, and returns the response."""
|
||||
"""Receive commands through a local pipe, forward them to the
|
||||
dispatcher, and return the response."""
|
||||
|
||||
def __init__(self, pipe_handle, dispatcher):
|
||||
threading.Thread.__init__(self)
|
||||
@@ -146,8 +146,8 @@ class PipeDispatcher(threading.Thread):
|
||||
KERNEL32.CloseHandle(self.pipe_handle)
|
||||
|
||||
class PipeServer(threading.Thread):
|
||||
"""The Pipe Server accepts incoming pipe handlers and initializes
|
||||
them in a new thread."""
|
||||
"""Accept incoming pipe handlers and initialize them in
|
||||
a new thread."""
|
||||
|
||||
def __init__(self, pipe_handler, pipe_name, message=False, **kwargs):
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
@@ -66,7 +66,7 @@ class Disguise(Auxiliary):
|
||||
]
|
||||
|
||||
def change_productid(self):
|
||||
"""Randomizes Windows ProductId.
|
||||
"""Randomize Windows ProductId.
|
||||
The Windows ProductId is occasionally used by malware
|
||||
to detect public setups of Cuckoo, e.g., Malwr.com.
|
||||
"""
|
||||
|
||||
@@ -12,7 +12,7 @@ from lib.common.registry import set_regkey_full
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class Reboot(Auxiliary):
|
||||
"""Prepares the environment to behave as if the VM has been rebooted."""
|
||||
"""Prepare the environment to behave as if the VM has been rebooted."""
|
||||
|
||||
def start(self):
|
||||
if self.analyzer.config.package != "reboot":
|
||||
|
||||
@@ -17,7 +17,7 @@ from lib.common.registry import set_regkey_full
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class RecentFiles(Auxiliary):
|
||||
"""Populates the Desktop with recent files in order to combat recent
|
||||
"""Populate the Desktop with recent files in order to combat recent
|
||||
anti-sandbox measures."""
|
||||
|
||||
extensions = [
|
||||
|
||||
@@ -13,7 +13,7 @@ from lib.core.ioctl import driver_name as random_name
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class LoadZer0m0n(Auxiliary):
|
||||
"""Loads the zer0m0n kernel driver."""
|
||||
"""Load the zer0m0n kernel driver."""
|
||||
|
||||
def start(self):
|
||||
if self.options.get("analysis") not in ("both", "kernel"):
|
||||
|
||||
@@ -51,7 +51,7 @@ class Zip(Package):
|
||||
self.extract_zip(os.path.join(extract_path, name), extract_path, password)
|
||||
|
||||
def is_overwritten(self, zip_path):
|
||||
"""Checks if the ZIP file contains another file with the same name, so it is going to be overwritten.
|
||||
"""Check if the ZIP file contains another file with the same name, so it is going to be overwritten.
|
||||
@param zip_path: zip file path
|
||||
@return: comparison boolean
|
||||
"""
|
||||
|
||||
+11
-11
@@ -19,7 +19,7 @@ class Avd(Machinery):
|
||||
"""Virtualization layer for Android Emulator."""
|
||||
|
||||
def _initialize_check(self):
|
||||
"""Runs all checks when a machine manager is initialized.
|
||||
"""Run all checks when a machine manager is initialized.
|
||||
@raise CuckooMachineError: if the android emulator is not found.
|
||||
"""
|
||||
self.emulator_processes = {}
|
||||
@@ -76,7 +76,7 @@ class Avd(Machinery):
|
||||
self.start_agent(label)
|
||||
|
||||
def stop(self, label):
|
||||
"""Stops a virtual machine.
|
||||
"""Stop a virtual machine.
|
||||
@param label: virtual machine name.
|
||||
@raise CuckooMachineError: if unable to stop.
|
||||
"""
|
||||
@@ -84,20 +84,20 @@ class Avd(Machinery):
|
||||
self.stop_emulator(label)
|
||||
|
||||
def _list(self):
|
||||
"""Lists virtual machines installed.
|
||||
"""List virtual machines installed.
|
||||
@return: virtual machine names list.
|
||||
"""
|
||||
return self.options.avd.machines
|
||||
|
||||
def _status(self, label):
|
||||
"""Gets current status of a vm.
|
||||
"""Get current status of a vm.
|
||||
@param label: virtual machine name.
|
||||
@return: status string.
|
||||
"""
|
||||
log.debug("Getting status for %s" % label)
|
||||
|
||||
def duplicate_reference_machine(self, label):
|
||||
"""Creates a new emulator based on a reference one."""
|
||||
"""Create a new emulator based on a reference one."""
|
||||
reference_machine = self.options.avd.reference_machine
|
||||
log.debug("Duplicate Reference Machine '{0}'.".format(reference_machine))
|
||||
|
||||
@@ -127,7 +127,7 @@ class Avd(Machinery):
|
||||
# todo:will see
|
||||
|
||||
def delete_old_emulator(self, label):
|
||||
"""Deletes any trace of an emulator that would have the same name as
|
||||
"""Delete any trace of an emulator that would have the same name as
|
||||
the one of the current emulator."""
|
||||
old_emulator_config_file = os.path.join(self.options.avd.avd_path,
|
||||
"%s.ini" % label)
|
||||
@@ -142,7 +142,7 @@ class Avd(Machinery):
|
||||
shutil.rmtree(old_emulator_path)
|
||||
|
||||
def replace_content_in_file(self, fileName, contentToReplace, replacementContent):
|
||||
"""Replaces the specified motif by a specified value in the specified
|
||||
"""Replace the specified motif by a specified value in the specified
|
||||
file.
|
||||
"""
|
||||
|
||||
@@ -157,7 +157,7 @@ class Avd(Machinery):
|
||||
fd.writelines(newLines)
|
||||
|
||||
def start_emulator(self, label, task):
|
||||
"""Starts the emulator."""
|
||||
"""Start the emulator."""
|
||||
emulator_port = self.options.get(label)["emulator_port"]
|
||||
|
||||
cmd = [
|
||||
@@ -216,7 +216,7 @@ class Avd(Machinery):
|
||||
del self.emulator_processes[label]
|
||||
|
||||
def wait_for_device_ready(self, label):
|
||||
"""Analyzes the emulator and returns when it's ready."""
|
||||
"""Analyze the emulator and return when it's ready."""
|
||||
|
||||
emulator_port = str(self.options.get(label)["emulator_port"])
|
||||
adb = self.options.avd.adb_path
|
||||
@@ -294,7 +294,7 @@ class Avd(Machinery):
|
||||
time.sleep(10)
|
||||
|
||||
def check_adb_recognize_emulator(self, label):
|
||||
"""Checks that ADB recognizes the emulator. Returns True if device is
|
||||
"""Check that ADB recognizes the emulator. Return True if device is
|
||||
recognized by ADB, False otherwise.
|
||||
"""
|
||||
log.debug("Checking if ADB recognizes emulator...")
|
||||
@@ -311,7 +311,7 @@ class Avd(Machinery):
|
||||
return False
|
||||
|
||||
def restart_adb_server(self):
|
||||
"""Restarts ADB server. This function is not used because we have to
|
||||
"""Restart ADB server. This function is not used because we have to
|
||||
verify we don't have multiple devices.
|
||||
"""
|
||||
log.debug("Restarting ADB server...")
|
||||
|
||||
@@ -18,7 +18,7 @@ class ESX(LibVirtMachinery):
|
||||
"""Virtualization layer for ESXi/ESX based on python-libvirt."""
|
||||
|
||||
def _initialize_check(self):
|
||||
"""Runs all checks when a machine manager is initialized.
|
||||
"""Run all checks when a machine manager is initialized.
|
||||
@raise CuckooMachineError: if configuration is invalid
|
||||
"""
|
||||
if not self.options.esx.dsn:
|
||||
|
||||
@@ -30,7 +30,7 @@ class Physical(Machinery):
|
||||
ERROR = "error"
|
||||
|
||||
def _initialize_check(self):
|
||||
"""Ensures that credentials have been entered into the config file.
|
||||
"""Ensure that credentials have been entered into the config file.
|
||||
@raise CuckooCriticalError: if no credentials were provided or if
|
||||
one or more physical machines are offline.
|
||||
"""
|
||||
@@ -85,7 +85,7 @@ class Physical(Machinery):
|
||||
"%s (STATUS=%s)" % (label, status))
|
||||
|
||||
def stop(self, label):
|
||||
"""Stops a physical machine.
|
||||
"""Stop a physical machine.
|
||||
@param label: physical machine name.
|
||||
@raise CuckooMachineError: if unable to stop.
|
||||
"""
|
||||
@@ -119,7 +119,7 @@ class Physical(Machinery):
|
||||
continue
|
||||
|
||||
def _list(self):
|
||||
"""Lists physical machines installed.
|
||||
"""List physical machines installed.
|
||||
@return: physical machine names list.
|
||||
"""
|
||||
active_machines = []
|
||||
@@ -130,7 +130,7 @@ class Physical(Machinery):
|
||||
return active_machines
|
||||
|
||||
def _status(self, label):
|
||||
"""Gets current status of a physical machine.
|
||||
"""Get current status of a physical machine.
|
||||
@param label: physical machine name.
|
||||
@return: status string.
|
||||
"""
|
||||
@@ -239,7 +239,7 @@ class Physical(Machinery):
|
||||
)
|
||||
|
||||
def fog_queue_task(self, hostname):
|
||||
"""Queues a task with FOG to deploy the given machine after reboot."""
|
||||
"""Queue a task with FOG to deploy the given machine after reboot."""
|
||||
if hostname in self.fog_machines:
|
||||
macaddr, download = self.fog_machines[hostname]
|
||||
self.fog_query(download)
|
||||
|
||||
@@ -116,7 +116,7 @@ class QEMU(Machinery):
|
||||
self.state = {}
|
||||
|
||||
def _initialize_check(self):
|
||||
"""Runs all checks when a machine manager is initialized.
|
||||
"""Run all checks when a machine manager is initialized.
|
||||
@raise CuckooMachineError: if QEMU binary is not found.
|
||||
"""
|
||||
# VirtualBox specific checks.
|
||||
@@ -205,7 +205,7 @@ class QEMU(Machinery):
|
||||
raise CuckooMachineError("QEMU failed starting the machine: %s" % e)
|
||||
|
||||
def stop(self, label):
|
||||
"""Stops a virtual machine.
|
||||
"""Stop a virtual machine.
|
||||
@param label: virtual machine label.
|
||||
@raise CuckooMachineError: if unable to stop.
|
||||
"""
|
||||
@@ -235,7 +235,7 @@ class QEMU(Machinery):
|
||||
self.state[vm_info.name] = None
|
||||
|
||||
def _status(self, name):
|
||||
"""Gets current status of a vm.
|
||||
"""Get current status of a vm.
|
||||
@param name: virtual machine name.
|
||||
@return: status string.
|
||||
"""
|
||||
|
||||
@@ -30,7 +30,7 @@ class VirtualBox(Machinery):
|
||||
ERROR = "machete"
|
||||
|
||||
def _initialize_check(self):
|
||||
"""Runs all checks when a machine manager is initialized.
|
||||
"""Run all checks when a machine manager is initialized.
|
||||
@raise CuckooMachineError: if VBoxManage is not found.
|
||||
"""
|
||||
if not self.options.virtualbox.path:
|
||||
@@ -182,7 +182,7 @@ class VirtualBox(Machinery):
|
||||
return
|
||||
|
||||
def stop(self, label):
|
||||
"""Stops a virtual machine.
|
||||
"""Stop a virtual machine.
|
||||
@param label: virtual machine name.
|
||||
@raise CuckooMachineError: if unable to stop.
|
||||
"""
|
||||
@@ -235,7 +235,7 @@ class VirtualBox(Machinery):
|
||||
self._wait_status(label, self.POWEROFF, self.ABORTED, self.SAVED)
|
||||
|
||||
def _list(self):
|
||||
"""Lists virtual machines installed.
|
||||
"""List virtual machines installed.
|
||||
@return: virtual machine names list.
|
||||
"""
|
||||
try:
|
||||
@@ -268,8 +268,8 @@ class VirtualBox(Machinery):
|
||||
return machines
|
||||
|
||||
def vminfo(self, label, field):
|
||||
"""Returns False if invoking vboxmanage fails. Otherwise the VM
|
||||
information value, if any."""
|
||||
"""Return False if invoking vboxmanage fails. Otherwise return the
|
||||
VM information value, if any."""
|
||||
try:
|
||||
args = [
|
||||
self.options.virtualbox.path,
|
||||
@@ -314,7 +314,7 @@ class VirtualBox(Machinery):
|
||||
return line.split("=", 1)[1]
|
||||
|
||||
def _status(self, label):
|
||||
"""Gets current status of a vm.
|
||||
"""Get current status of a vm.
|
||||
@param label: virtual machine name.
|
||||
@return: status string.
|
||||
"""
|
||||
@@ -332,7 +332,7 @@ class VirtualBox(Machinery):
|
||||
)
|
||||
|
||||
def dump_memory(self, label, path):
|
||||
"""Takes a memory dump.
|
||||
"""Take a memory dump.
|
||||
@param path: path to where to store the memory dump.
|
||||
"""
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class VMware(Machinery):
|
||||
super(VMware, self)._initialize_check()
|
||||
|
||||
def _check_vmx(self, vmx_path):
|
||||
"""Checks whether a vmx file exists and is valid.
|
||||
"""Check whether a vmx file exists and is valid.
|
||||
@param vmx_path: path to vmx file
|
||||
@raise CuckooMachineError: if file not found or not ending with .vmx
|
||||
"""
|
||||
@@ -56,7 +56,7 @@ class VMware(Machinery):
|
||||
raise CuckooMachineError("Vm file %s not found" % vmx_path)
|
||||
|
||||
def _check_snapshot(self, vmx_path, snapshot):
|
||||
"""Checks snapshot existance.
|
||||
"""Check snapshot existence.
|
||||
@param vmx_path: path to vmx file
|
||||
@param snapshot: snapshot name
|
||||
@raise CuckooMachineError: if snapshot not found
|
||||
@@ -114,7 +114,7 @@ class VMware(Machinery):
|
||||
"mode: %s" % (vmx_path, mode, e))
|
||||
|
||||
def stop(self, vmx_path):
|
||||
"""Stops a virtual machine.
|
||||
"""Stop a virtual machine.
|
||||
@param vmx_path: path to vmx file
|
||||
@raise CuckooMachineError: if unable to stop.
|
||||
"""
|
||||
@@ -135,7 +135,7 @@ class VMware(Machinery):
|
||||
vmx_path)
|
||||
|
||||
def _revert(self, vmx_path, snapshot):
|
||||
"""Revets machine to snapshot.
|
||||
"""Revert machine to snapshot.
|
||||
@param vmx_path: path to vmx file
|
||||
@param snapshot: snapshot name
|
||||
@raise CuckooMachineError: if unable to revert
|
||||
@@ -154,7 +154,7 @@ class VMware(Machinery):
|
||||
"machine %s: %s" % (vmx_path, e))
|
||||
|
||||
def _is_running(self, vmx_path):
|
||||
"""Checks if virtual machine is running.
|
||||
"""Check if virtual machine is running.
|
||||
@param vmx_path: path to vmx file
|
||||
@return: running status
|
||||
"""
|
||||
|
||||
@@ -55,7 +55,7 @@ class vSphere(Machinery):
|
||||
random.seed()
|
||||
|
||||
def _initialize_check(self):
|
||||
"""Runs checks against virtualization software when a machine manager
|
||||
"""Run checks against virtualization software when a machine manager
|
||||
is initialized.
|
||||
@raise CuckooCriticalError: if a misconfiguration or unsupported state
|
||||
is found.
|
||||
|
||||
@@ -189,7 +189,7 @@ class XenServer(Machinery):
|
||||
return machine.snapshot
|
||||
|
||||
def _is_halted(self, vm):
|
||||
"""Checks if the virtual machine is running.
|
||||
"""Check if the virtual machine is running.
|
||||
@param uuid: vm uuid
|
||||
"""
|
||||
return vm["power_state"] == "Halted"
|
||||
@@ -262,7 +262,7 @@ class XenServer(Machinery):
|
||||
return vm_list
|
||||
|
||||
def _status(self, label):
|
||||
"""Gets current status of a vm.
|
||||
"""Get current status of a vm.
|
||||
@param label: virtual machine uuid
|
||||
@return: status string.
|
||||
"""
|
||||
|
||||
+4
-4
@@ -194,7 +194,7 @@ def cuckoo_main(max_analysis_count=0):
|
||||
@click.option("--cwd", help="Cuckoo Working Directory")
|
||||
@click.pass_context
|
||||
def main(ctx, debug, quiet, nolog, maxcount, user, cwd):
|
||||
"""Invokes the Cuckoo daemon or one of its subcommands.
|
||||
"""Invoke the Cuckoo daemon or one of its subcommands.
|
||||
|
||||
To be able to use different Cuckoo configurations on the same machine with
|
||||
the same Cuckoo installation, we use the so-called Cuckoo Working
|
||||
@@ -247,7 +247,7 @@ def main(ctx, debug, quiet, nolog, maxcount, user, cwd):
|
||||
@click.pass_context
|
||||
@click.option("--conf", type=click.Path(exists=True, file_okay=True, readable=True), help="Flat key/value configuration file")
|
||||
def init(ctx, conf):
|
||||
"""Initializes Cuckoo and its configuration."""
|
||||
"""Initialize Cuckoo and its configuration."""
|
||||
if conf and os.path.exists(conf):
|
||||
cfg = read_kv_conf(conf)
|
||||
else:
|
||||
@@ -398,7 +398,7 @@ def process(ctx, instance, report, maxcount, timeout):
|
||||
@click.option("--sudo", is_flag=True, help="Request superuser privileges")
|
||||
@click.pass_context
|
||||
def rooter(ctx, socket, group, service, iptables, ip, sudo):
|
||||
"""Instantiates the Cuckoo Rooter."""
|
||||
"""Instantiate the Cuckoo Rooter."""
|
||||
init_console_logging(level=ctx.parent.level)
|
||||
|
||||
if sudo:
|
||||
@@ -626,7 +626,7 @@ def migrate(revision):
|
||||
@click.argument("path", type=click.Path(file_okay=False, exists=True))
|
||||
@click.pass_context
|
||||
def import_(ctx, mode, path):
|
||||
"""Imports an older Cuckoo setup into a new CWD. The old setup should be
|
||||
"""Import an older Cuckoo setup into a new CWD. The old setup should be
|
||||
identified by PATH and the new CWD may be specified with the --cwd
|
||||
parameter, e.g., "cuckoo --cwd /tmp/cwd import old-cuckoo"."""
|
||||
if os.path.exists(os.path.join(path, ".cwd")):
|
||||
|
||||
+7
-7
@@ -41,7 +41,7 @@ def set_cwd(path, raw=None):
|
||||
_raw = raw
|
||||
|
||||
def cwd(*args, **kwargs):
|
||||
"""Returns absolute path to this file in the Cuckoo Working Directory or
|
||||
"""Return absolute path to this file in the Cuckoo Working Directory or
|
||||
optionally - when private=True has been passed along - to our private
|
||||
Cuckoo Working Directory which is not configurable."""
|
||||
if kwargs.get("private"):
|
||||
@@ -62,7 +62,7 @@ def cwd(*args, **kwargs):
|
||||
return os.path.join(_root, *args)
|
||||
|
||||
def decide_cwd(cwd=None, exists=False):
|
||||
"""Decides and sets the CWD, optionally checks if it's a valid CWD."""
|
||||
"""Decide and set the CWD, optionally check if it's a valid CWD."""
|
||||
if not cwd:
|
||||
cwd = os.environ.get("CUCKOO_CWD")
|
||||
|
||||
@@ -104,7 +104,7 @@ def getuser():
|
||||
return ""
|
||||
|
||||
def load_signatures():
|
||||
"""Loads additional Signatures from the Cuckoo Working Directory.
|
||||
"""Load additional Signatures from the Cuckoo Working Directory.
|
||||
|
||||
This method is quite hacky in the sense that it magically imports
|
||||
Signatures from an arbitrary directory - one that doesn't belong to the
|
||||
@@ -188,7 +188,7 @@ def is_macosx():
|
||||
return sys.platform == "darwin"
|
||||
|
||||
def Popen(*args, **kwargs):
|
||||
"""Drops the close_fds argument on Windows platforms in certain situations
|
||||
"""Drop the close_fds argument on Windows platforms in certain situations
|
||||
where it'd otherwise cause an exception from the subprocess module."""
|
||||
if is_windows() and "close_fds" in kwargs:
|
||||
if "stdin" in kwargs or "stdout" in kwargs or "stderr" in kwargs:
|
||||
@@ -197,7 +197,7 @@ def Popen(*args, **kwargs):
|
||||
return subprocess.Popen(*args, **kwargs)
|
||||
|
||||
def drop_privileges(username):
|
||||
"""Drops privileges to selected user.
|
||||
"""Drop privileges to selected user.
|
||||
@param username: drop privileges to this username
|
||||
"""
|
||||
if not HAVE_PWD:
|
||||
@@ -225,7 +225,7 @@ class Pidfile(object):
|
||||
self.pid = None
|
||||
|
||||
def create(self):
|
||||
"""Creates pidfile for the current process."""
|
||||
"""Create pidfile for the current process."""
|
||||
with open(self.filepath, "wb") as f:
|
||||
f.write(str(os.getpid()))
|
||||
|
||||
@@ -249,7 +249,7 @@ class Pidfile(object):
|
||||
return self.pid
|
||||
|
||||
def proc_exists(self, pid):
|
||||
"""Returns boolean if the process exists or None when unsupported."""
|
||||
"""Return boolean of process existence, or None when unsupported."""
|
||||
if not pid:
|
||||
return False
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class ApkInfo(Processing):
|
||||
return False
|
||||
|
||||
def _apk_files(self, apk):
|
||||
"""Returns a list of files in the APK."""
|
||||
"""Return a list of files in the APK."""
|
||||
ret = []
|
||||
for fname, filetype in apk.get_files_types().items():
|
||||
buf = apk.zip.read(fname)
|
||||
|
||||
@@ -12,7 +12,7 @@ from cuckoo.common.abstracts import Processing
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class Baseline(Processing):
|
||||
"""Reduces Baseline results from gathered information."""
|
||||
"""Reduce Baseline results from gathered information."""
|
||||
order = 2
|
||||
|
||||
def deep_tuple(self, o, bl=None):
|
||||
@@ -39,9 +39,9 @@ class Baseline(Processing):
|
||||
return self.deep_tuple(o, plugins.get(plugin))
|
||||
|
||||
def memory(self, baseline, report):
|
||||
"""Finds the differences between the analysis report and the baseline
|
||||
report. Puts the differences into the baseline part of the report and
|
||||
also marks the existing rows with a `class_` attribute."""
|
||||
"""Find the differences between the analysis report and the baseline
|
||||
report. Put the differences into the baseline part of the report and
|
||||
mark the existing rows with a `class_` attribute."""
|
||||
results = {}
|
||||
|
||||
for plugin in baseline.keys() + report.keys():
|
||||
|
||||
@@ -19,7 +19,7 @@ from .platform.linux import LinuxSystemTap
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class Summary(BehaviorHandler):
|
||||
"""Generates overview summary information (not split by process)."""
|
||||
"""Generate overview summary information (not split by process)."""
|
||||
|
||||
key = "summary"
|
||||
event_types = ["generic"]
|
||||
|
||||
@@ -14,7 +14,7 @@ from cuckoo.common.files import Files
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class Irma(Processing):
|
||||
"""Gets antivirus signatures from IRMA for various results.
|
||||
"""Get antivirus signatures from IRMA for various results.
|
||||
|
||||
Currently obtains IRMA results for the target sample.
|
||||
"""
|
||||
@@ -97,7 +97,7 @@ class Irma(Processing):
|
||||
)
|
||||
|
||||
def run(self):
|
||||
"""Runs IRMA processing
|
||||
"""Run IRMA processing
|
||||
@return: full IRMA report.
|
||||
"""
|
||||
self.key = "irma"
|
||||
@@ -123,13 +123,13 @@ class Irma(Processing):
|
||||
self._scan_file(self.file_path, self.force)
|
||||
results = self._get_results(sha256) or {}
|
||||
|
||||
""" FIXME! could use a proper fix here
|
||||
that probably needs changes on IRMA side aswell
|
||||
--
|
||||
related to https://github.com/elastic/elasticsearch/issues/15377
|
||||
entropy value is sometimes 0 and sometimes like 0.10191042566270775
|
||||
other issue is that results type changes between string and object :/
|
||||
"""
|
||||
# FIXME! could use a proper fix here
|
||||
# that probably needs changes on IRMA side aswell
|
||||
# --
|
||||
# related to https://github.com/elastic/elasticsearch/issues/15377
|
||||
# entropy value is sometimes 0 and sometimes like 0.10191042566270775
|
||||
# other issue is that results type changes between string and object :/
|
||||
|
||||
for idx, result in enumerate(results["probe_results"]):
|
||||
if result["name"] == "PE Static Analyzer":
|
||||
log.debug("Ignoring PE results at index {0}".format(idx))
|
||||
|
||||
@@ -90,7 +90,7 @@ class VolatilityAPI(object):
|
||||
return False
|
||||
|
||||
def init_config(self):
|
||||
"""Creates a volatility configuration."""
|
||||
"""Create a volatility configuration."""
|
||||
if self.config is not None and self.addr_space is not None:
|
||||
return
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ class Pcap(object):
|
||||
ssl_ports = 443,
|
||||
|
||||
def __init__(self, filepath, options):
|
||||
"""Creates a new instance.
|
||||
"""Create a new instance.
|
||||
@param filepath: path to PCAP file
|
||||
@param options: config options
|
||||
"""
|
||||
@@ -93,7 +93,7 @@ class Pcap(object):
|
||||
self.dns_servers = []
|
||||
|
||||
def _is_whitelisted(self, conn, hostname):
|
||||
"""Checks if whitelisting conditions are met"""
|
||||
"""Check if whitelisting conditions are met"""
|
||||
# Is whitelistng enabled?
|
||||
if not self.whitelist_enabled:
|
||||
return False
|
||||
@@ -217,7 +217,7 @@ class Pcap(object):
|
||||
pass
|
||||
|
||||
def _tcp_dissect(self, conn, data):
|
||||
"""Runs all TCP dissectors.
|
||||
"""Run all TCP dissectors.
|
||||
@param conn: connection.
|
||||
@param data: payload data.
|
||||
"""
|
||||
@@ -237,7 +237,7 @@ class Pcap(object):
|
||||
self._https_identify(conn, data)
|
||||
|
||||
def _udp_dissect(self, conn, data):
|
||||
"""Runs all UDP dissectors.
|
||||
"""Run all UDP dissectors.
|
||||
@param conn: connection.
|
||||
@param data: payload data.
|
||||
"""
|
||||
@@ -247,7 +247,7 @@ class Pcap(object):
|
||||
self._add_dns(conn, data)
|
||||
|
||||
def _check_icmp(self, icmp_data):
|
||||
"""Checks for ICMP traffic.
|
||||
"""Check for ICMP traffic.
|
||||
@param icmp_data: ICMP data flow.
|
||||
"""
|
||||
try:
|
||||
@@ -257,7 +257,7 @@ class Pcap(object):
|
||||
return False
|
||||
|
||||
def _icmp_dissect(self, conn, data):
|
||||
"""Runs all ICMP dissectors.
|
||||
"""Run all ICMP dissectors.
|
||||
@param conn: connection.
|
||||
@param data: payload data.
|
||||
"""
|
||||
@@ -282,7 +282,7 @@ class Pcap(object):
|
||||
self.icmp_requests.append(entry)
|
||||
|
||||
def _check_dns(self, udpdata):
|
||||
"""Checks for DNS traffic.
|
||||
"""Check for DNS traffic.
|
||||
@param udpdata: UDP data flow.
|
||||
"""
|
||||
try:
|
||||
@@ -293,7 +293,7 @@ class Pcap(object):
|
||||
return True
|
||||
|
||||
def _add_dns(self, conn, udpdata):
|
||||
"""Adds a DNS data flow.
|
||||
"""Add a DNS data flow.
|
||||
@param udpdata: UDP data flow.
|
||||
"""
|
||||
dns = dpkt.dns.DNS(udpdata)
|
||||
@@ -443,7 +443,7 @@ class Pcap(object):
|
||||
"ip": self._dns_gethostbyname(domain)})
|
||||
|
||||
def _check_http(self, tcpdata):
|
||||
"""Checks for HTTP traffic.
|
||||
"""Check for HTTP traffic.
|
||||
@param tcpdata: TCP data flow.
|
||||
"""
|
||||
try:
|
||||
@@ -459,7 +459,7 @@ class Pcap(object):
|
||||
return True
|
||||
|
||||
def _add_http(self, tcpdata, dport):
|
||||
"""Adds an HTTP flow.
|
||||
"""Add an HTTP flow.
|
||||
@param tcpdata: TCP data flow.
|
||||
@param dport: destination port.
|
||||
"""
|
||||
@@ -562,7 +562,7 @@ class Pcap(object):
|
||||
|
||||
def _check_irc(self, tcpdata):
|
||||
"""
|
||||
Checks for IRC traffic.
|
||||
Check for IRC traffic.
|
||||
@param tcpdata: tcp data flow
|
||||
"""
|
||||
try:
|
||||
@@ -574,7 +574,7 @@ class Pcap(object):
|
||||
|
||||
def _add_irc(self, tcpdata):
|
||||
"""
|
||||
Adds an IRC communication.
|
||||
Add an IRC communication.
|
||||
@param tcpdata: TCP data in flow
|
||||
@param dport: destination port
|
||||
"""
|
||||
@@ -732,7 +732,7 @@ class Pcap(object):
|
||||
return self.results
|
||||
|
||||
class Pcap2(object):
|
||||
"""Interprets the PCAP file through the httpreplay library which parses
|
||||
"""Interpret the PCAP file through the httpreplay library which parses
|
||||
the various protocols, decrypts and decodes them, and then provides us
|
||||
with the high level representation of it."""
|
||||
|
||||
@@ -936,7 +936,7 @@ def conn_from_flowtuple(ft):
|
||||
# it for the temp files
|
||||
# this code is mostly taken from some SO post, can't remember the url though
|
||||
def batch_sort(input_iterator, output_path, output_class):
|
||||
"""batch sort helper with temporary files, supports sorting large stuff"""
|
||||
"""Batch sort helper with temporary files, supports sorting large stuff."""
|
||||
chunks = []
|
||||
try:
|
||||
while True:
|
||||
@@ -1015,7 +1015,7 @@ class SortCap(object):
|
||||
return Keyed((flowtuple, ts, self.ctr), rpkt)
|
||||
|
||||
def sort_pcap(inpath, outpath):
|
||||
"""Use SortCap class together with batch_sort to sort a pcap"""
|
||||
"""Use SortCap class together with batch_sort to sort a pcap."""
|
||||
inc = SortCap(inpath)
|
||||
batch_sort(
|
||||
inc, outpath, lambda path: SortCap(path, linktype=inc.linktype)
|
||||
@@ -1023,7 +1023,7 @@ def sort_pcap(inpath, outpath):
|
||||
return 0
|
||||
|
||||
def flowtuple_from_raw(raw, linktype=1):
|
||||
"""Parse a packet from a pcap just enough to gain a flow description tuple"""
|
||||
"""Parse a packet from a pcap just enough to gain a flow description tuple."""
|
||||
ip = iplayer_from_raw(raw, linktype)
|
||||
|
||||
if isinstance(ip, dpkt.ip.IP):
|
||||
|
||||
@@ -52,7 +52,7 @@ class ProcessMemory(Processing):
|
||||
print>>o, "autoMark(%s, AU_CODE)" % region["addr"]
|
||||
|
||||
def _fixup_pe_header(self, pe):
|
||||
"""Fixes the PE header from an in-memory representation to an
|
||||
"""Fix the PE header from an in-memory representation to an
|
||||
on-disk representation."""
|
||||
for section in pe.sections:
|
||||
section.PointerToRawData = section.VirtualAddress
|
||||
|
||||
@@ -8,7 +8,7 @@ import xml.etree.ElementTree
|
||||
from cuckoo.common.abstracts import Processing
|
||||
|
||||
class ProcmonLog(list):
|
||||
"""Yields each API call event to the parent handler."""
|
||||
"""Yield each API call event to the parent handler."""
|
||||
|
||||
def __init__(self, filepath):
|
||||
list.__init__(self)
|
||||
@@ -32,7 +32,7 @@ class ProcmonLog(list):
|
||||
return True
|
||||
|
||||
class Procmon(Processing):
|
||||
"""Extracts events from procmon.exe output."""
|
||||
"""Extract events from procmon.exe output."""
|
||||
|
||||
key = "procmon"
|
||||
|
||||
|
||||
@@ -63,14 +63,14 @@ class PortableExecutable(object):
|
||||
self.pe = None
|
||||
|
||||
def _get_filetype(self, data):
|
||||
"""Gets filetype, uses libmagic if available.
|
||||
"""Get filetype, use libmagic if available.
|
||||
@param data: data to be analyzed.
|
||||
@return: file type or None.
|
||||
"""
|
||||
return sflock.magic.from_buffer(data)
|
||||
|
||||
def _get_peid_signatures(self):
|
||||
"""Gets PEID signatures.
|
||||
"""Get PEID signatures.
|
||||
@return: matched signatures or None.
|
||||
"""
|
||||
try:
|
||||
@@ -81,7 +81,7 @@ class PortableExecutable(object):
|
||||
return None
|
||||
|
||||
def _get_imported_symbols(self):
|
||||
"""Gets imported symbols.
|
||||
"""Get imported symbols.
|
||||
@return: imported symbols dict or None.
|
||||
"""
|
||||
imports = []
|
||||
@@ -105,7 +105,7 @@ class PortableExecutable(object):
|
||||
return imports
|
||||
|
||||
def _get_exported_symbols(self):
|
||||
"""Gets exported symbols.
|
||||
"""Get exported symbols.
|
||||
@return: exported symbols dict or None.
|
||||
"""
|
||||
exports = []
|
||||
@@ -122,7 +122,7 @@ class PortableExecutable(object):
|
||||
return exports
|
||||
|
||||
def _get_sections(self):
|
||||
"""Gets sections.
|
||||
"""Get sections.
|
||||
@return: sections dict or None.
|
||||
"""
|
||||
sections = []
|
||||
@@ -207,7 +207,7 @@ class PortableExecutable(object):
|
||||
return infos
|
||||
|
||||
def _get_imphash(self):
|
||||
"""Gets imphash.
|
||||
"""Get imphash.
|
||||
@return: imphash string or None.
|
||||
"""
|
||||
try:
|
||||
|
||||
@@ -18,7 +18,7 @@ from cuckoo.common.virustotal import (
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class VirusTotal(Processing):
|
||||
"""Gets antivirus signatures from VirusTotal.com for various results.
|
||||
"""Get antivirus signatures from VirusTotal.com for various results.
|
||||
|
||||
Currently obtains VirusTotal results for the target sample or URL and the
|
||||
dropped files.
|
||||
@@ -26,7 +26,7 @@ class VirusTotal(Processing):
|
||||
order = 2
|
||||
|
||||
def run(self):
|
||||
"""Runs VirusTotal processing
|
||||
"""Run VirusTotal processing
|
||||
@return: full VirusTotal report.
|
||||
"""
|
||||
self.key = "virustotal"
|
||||
@@ -94,7 +94,7 @@ class VirusTotal(Processing):
|
||||
"\"%s\": %s", url, e.message)
|
||||
|
||||
def should_scan_file(self, filetype):
|
||||
"""Determines whether a certain filetype should be scanned on
|
||||
"""Determine whether a certain filetype should be scanned on
|
||||
VirusTotal. For example, we're not interested in scanning text
|
||||
files.
|
||||
@param filetype: file type
|
||||
|
||||
@@ -21,7 +21,7 @@ logging.getLogger("elasticsearch.trace").setLevel(logging.WARNING)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class ElasticSearch(Report):
|
||||
"""Stores report in Elasticsearch."""
|
||||
"""Store report in Elasticsearch."""
|
||||
|
||||
@classmethod
|
||||
def init_once(cls):
|
||||
|
||||
@@ -6,7 +6,7 @@ from cuckoo.common.abstracts import Report
|
||||
from cuckoo.core.feedback import CuckooFeedbackObject, CuckooFeedback
|
||||
|
||||
class Feedback(Report):
|
||||
"""Reports feedback to the Cuckoo Feedback backend if required."""
|
||||
"""Report feedback to the Cuckoo Feedback backend if required."""
|
||||
|
||||
def run(self, results):
|
||||
# Nothing to see here.
|
||||
|
||||
@@ -19,10 +19,10 @@ def default(obj):
|
||||
raise TypeError("%r is not JSON serializable" % obj)
|
||||
|
||||
class JsonDump(Report):
|
||||
"""Saves analysis results in JSON format."""
|
||||
"""Save analysis results in JSON format."""
|
||||
|
||||
def erase_calls(self, results):
|
||||
"""Temporarily removes calls from the report by replacing them with
|
||||
"""Temporarily remove calls from the report by replacing them with
|
||||
empty lists."""
|
||||
if self.calls:
|
||||
self.calls = None
|
||||
@@ -34,7 +34,7 @@ class JsonDump(Report):
|
||||
process["calls"] = []
|
||||
|
||||
def restore_calls(self, results):
|
||||
"""Restores calls that were temporarily removed in the report by
|
||||
"""Restore calls that were temporarily removed in the report by
|
||||
replacing the calls with the original values."""
|
||||
if not self.calls:
|
||||
return
|
||||
|
||||
@@ -91,7 +91,7 @@ class MISP(Report):
|
||||
)
|
||||
|
||||
def run(self, results):
|
||||
"""Submits results to MISP.
|
||||
"""Submit results to MISP.
|
||||
@param results: Cuckoo results dict.
|
||||
"""
|
||||
url = self.options.get("url")
|
||||
|
||||
@@ -12,7 +12,7 @@ from cuckoo.common.mongo import mongo
|
||||
from cuckoo.common.objects import File
|
||||
|
||||
class MongoDB(Report):
|
||||
"""Stores report in MongoDB."""
|
||||
"""Store report in MongoDB."""
|
||||
order = 2
|
||||
|
||||
# Mongo schema version, used for data migration.
|
||||
@@ -77,7 +77,7 @@ class MongoDB(Report):
|
||||
return self.db.fs.files.find_one(to_find)["_id"]
|
||||
|
||||
def run(self, results):
|
||||
"""Writes report.
|
||||
"""Write report.
|
||||
@param results: analysis results dictionary.
|
||||
@raise CuckooReportError: if fails to connect or write to MongoDB.
|
||||
"""
|
||||
|
||||
@@ -18,7 +18,7 @@ def default(obj):
|
||||
raise TypeError("%r is not JSON serializable" % obj)
|
||||
|
||||
class Notification(Report):
|
||||
"""Notifies external service about finished analysis via URL."""
|
||||
"""Notify external service about finished analysis via URL."""
|
||||
order = 3
|
||||
|
||||
def run(self, results):
|
||||
|
||||
@@ -20,7 +20,7 @@ from cuckoo.misc import cwd
|
||||
logging.getLogger("weasyprint").setLevel(logging.ERROR)
|
||||
|
||||
class SingleFile(Report):
|
||||
"""Stores report in a single-file HTML and/or PDF format."""
|
||||
"""Store report in a single-file HTML and/or PDF format."""
|
||||
|
||||
fonts = [{
|
||||
"family": "Roboto",
|
||||
@@ -120,14 +120,14 @@ class SingleFile(Report):
|
||||
)
|
||||
|
||||
def combine_css(self):
|
||||
"""Scans the static/css/ directory and concatenates stylesheets"""
|
||||
"""Scan the static/css/ directory and concatenate stylesheets"""
|
||||
css_includes = []
|
||||
for filepath in glob.glob("%s/static/css/*.css" % self.path_base):
|
||||
css_includes.append(open(filepath, "rb").read().decode("utf8"))
|
||||
return "\n".join(css_includes)
|
||||
|
||||
def combine_js(self):
|
||||
"""Scans the static/js/ directory and concatenates js files"""
|
||||
"""Scan the static/js/ directory and concatenate js files"""
|
||||
js_includes = []
|
||||
# Note: jquery-2.2.4.min.js must be the first file.
|
||||
filepaths = sorted(glob.glob("%s/static/js/*.js" % self.path_base))
|
||||
|
||||
@@ -19,7 +19,7 @@ def mongo_id(value):
|
||||
|
||||
@register.filter
|
||||
def is_dict(value):
|
||||
"""Checks if value is an instance of dict"""
|
||||
"""Check if value is an instance of dict"""
|
||||
return isinstance(value, dict)
|
||||
|
||||
@register.filter
|
||||
|
||||
@@ -84,7 +84,7 @@ def chunk(request, task_id, pid, pagenum):
|
||||
|
||||
@require_safe
|
||||
def filtered_chunk(request, task_id, pid, category):
|
||||
"""Filters calls for call category.
|
||||
"""Filter calls for call category.
|
||||
@param task_id: cuckoo task id
|
||||
@param pid: pid you want calls
|
||||
@param category: call category type
|
||||
|
||||
@@ -34,7 +34,7 @@ class AnalysisController:
|
||||
|
||||
@staticmethod
|
||||
def _get_dnsinfo(report):
|
||||
"""Create DNS information dicts by domain and ip"""
|
||||
"""Create DNS information dicts by domain and ip."""
|
||||
|
||||
if "network" in report and "domains" in report["network"]:
|
||||
domainlookups = dict((i["domain"], i["ip"]) for i in report["network"]["domains"])
|
||||
|
||||
@@ -102,7 +102,7 @@ class AnalysisApi(object):
|
||||
@api_get
|
||||
def task_delete(request, task_id):
|
||||
"""
|
||||
Deletes a task
|
||||
Delete a task.
|
||||
:param body: required: task_id
|
||||
:return:
|
||||
"""
|
||||
@@ -126,7 +126,7 @@ class AnalysisApi(object):
|
||||
@api_get
|
||||
def tasks_reschedule(request, task_id, priority=None):
|
||||
"""
|
||||
Reschedules a task
|
||||
Reschedule a task.
|
||||
:param body: required: task_id, priority
|
||||
:return: new task_id
|
||||
"""
|
||||
@@ -363,7 +363,7 @@ class AnalysisApi(object):
|
||||
@api_post
|
||||
def tasks_stats(request, body):
|
||||
"""
|
||||
Fetches the number of analysis over a
|
||||
Fetch the number of analysis over a
|
||||
given period for the "failed" and
|
||||
"successful" states. Values are
|
||||
returned in months.
|
||||
|
||||
@@ -44,7 +44,7 @@ class ExportController:
|
||||
@staticmethod
|
||||
def create(task_id, taken_dirs, taken_files, report=None):
|
||||
"""
|
||||
Returns a zip file as a file like object.
|
||||
Return a zip file as a file like object.
|
||||
:param task_id: task id
|
||||
:param taken_dirs: directories to include
|
||||
:param taken_files: files to include
|
||||
|
||||
@@ -21,7 +21,7 @@ db = Database()
|
||||
updates = {}
|
||||
|
||||
def latest_updates():
|
||||
"""Updates the latest Cuckoo version & blogposts at maximum once a day."""
|
||||
"""Update the latest Cuckoo version & blogposts at maximum once a day."""
|
||||
next_check = datetime.datetime.now() - datetime.timedelta(days=1)
|
||||
if updates and updates["timestamp"] > next_check:
|
||||
return updates
|
||||
@@ -36,7 +36,7 @@ class CuckooApi(object):
|
||||
@api_get
|
||||
def status(request):
|
||||
"""
|
||||
Returns a variety of information about both
|
||||
Return a variety of information about both
|
||||
Cuckoo and the operating system.
|
||||
:return: Dictionary
|
||||
"""
|
||||
|
||||
@@ -13,7 +13,7 @@ class MachinesApi:
|
||||
@api_get
|
||||
def list(request):
|
||||
"""
|
||||
Returns a list of all machines currently registered in Cuckoo
|
||||
Return a list of all machines currently registered in Cuckoo
|
||||
:return:
|
||||
"""
|
||||
data = {}
|
||||
@@ -29,7 +29,7 @@ class MachinesApi:
|
||||
@api_get
|
||||
def view(request, name=None):
|
||||
"""
|
||||
Returns information about a machine
|
||||
Return information about a machine
|
||||
:param name: machine name
|
||||
:return: Machine information as a dictionary
|
||||
"""
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ from cuckoo.core.startup import init_rooter, init_routing
|
||||
SIOCGIFADDR = 0x8915
|
||||
|
||||
def get_ip_address(interface):
|
||||
"""Retrieves the local IP address of a network interface."""
|
||||
"""Retrieve the local IP address of a network interface."""
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
buf = fcntl.ioctl(s.fileno(), SIOCGIFADDR, struct.pack("256s", interface))
|
||||
return socket.inet_ntoa(buf[20:24])
|
||||
|
||||
@@ -17,7 +17,7 @@ from cuckoo.main import main, cuckoo_create
|
||||
from cuckoo.misc import set_cwd, cwd, mkdir
|
||||
|
||||
class DatabaseEngine(object):
|
||||
"""Tests database stuff."""
|
||||
"""Test database stuff."""
|
||||
URI = None
|
||||
|
||||
def setup_class(self):
|
||||
@@ -275,7 +275,7 @@ class TestMySQL(DatabaseEngine):
|
||||
|
||||
@pytest.mark.skipif("sys.platform != 'linux2'")
|
||||
class DatabaseMigrationEngine(object):
|
||||
"""Tests database migration(s)."""
|
||||
"""Test database migration(s)."""
|
||||
URI = None
|
||||
SRC = None
|
||||
|
||||
|
||||
+3
-3
@@ -60,7 +60,7 @@ class TestInit(object):
|
||||
write_supervisor_conf(None)
|
||||
|
||||
def test_cuckoo_init(self):
|
||||
"""Tests that 'cuckoo init' works with a new CWD."""
|
||||
"""Test that 'cuckoo init' works with a new CWD."""
|
||||
with pytest.raises(SystemExit):
|
||||
main.main(
|
||||
("--cwd", cwd(), "--nolog", "init"),
|
||||
@@ -77,7 +77,7 @@ class TestInit(object):
|
||||
assert os.path.exists(os.path.join(cwd(), "storage", "baseline"))
|
||||
|
||||
def test_cuckoo_init_main(self):
|
||||
"""Tests that 'cuckoo' works with a new CWD."""
|
||||
"""Test that 'cuckoo' works with a new CWD."""
|
||||
main.main(
|
||||
("--cwd", cwd(), "--nolog"),
|
||||
standalone_mode=False
|
||||
@@ -95,7 +95,7 @@ class TestInit(object):
|
||||
p.assert_not_called()
|
||||
|
||||
def test_cuckoo_init_no_resultserver(self):
|
||||
"""Tests that 'cuckoo init' doesn't launch the ResultServer."""
|
||||
"""Test that 'cuckoo init' doesn't launch the ResultServer."""
|
||||
with pytest.raises(SystemExit):
|
||||
main.main(
|
||||
("--cwd", cwd(), "--nolog", "init"),
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ from cuckoo.misc import set_cwd, cwd
|
||||
db = Database()
|
||||
|
||||
def reset_logging():
|
||||
"""Resets the logging module to its initial state so that we can
|
||||
"""Reset the logging module to its initial state so that we can
|
||||
re-register all kinds of logging logic for unit testing purposes."""
|
||||
logging.root = logging.RootLogger(logging.WARNING)
|
||||
logging.Logger.root = logging.root
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ def test_platforms():
|
||||
assert sys.platform in ("win32", "linux2", "darwin")
|
||||
|
||||
def test_popen():
|
||||
"""Ensures that Popen is working properly."""
|
||||
"""Ensure that Popen is working properly."""
|
||||
with mock.patch("subprocess.Popen") as p:
|
||||
p.return_value = None
|
||||
Popen(["foo", "bar"])
|
||||
|
||||
@@ -116,7 +116,7 @@ def test_empty_mattermost():
|
||||
|
||||
@responses.activate
|
||||
def test_empty_misp():
|
||||
"""Merely connects to MISP and creates the new event."""
|
||||
"""Merely connect to MISP and create the new event."""
|
||||
set_cwd(tempfile.mkdtemp())
|
||||
conf = {
|
||||
"misp": {
|
||||
|
||||
@@ -38,7 +38,7 @@ class TestSubmitManager(object):
|
||||
self.submit_manager = SubmitManager()
|
||||
|
||||
def test_pre_file(self):
|
||||
"""Tests the submission of a plaintext file"""
|
||||
"""Test the submission of a plaintext file"""
|
||||
assert self.submit_manager.pre(submit_type="files", data=[{
|
||||
"name": "foo.txt",
|
||||
"data": open("tests/files/foo.txt", "rb").read()
|
||||
@@ -54,7 +54,7 @@ class TestSubmitManager(object):
|
||||
assert filedata == open("tests/files/foo.txt", "rb").read()
|
||||
|
||||
def test_pre_url(self):
|
||||
"""Tests the submission of URLs (http/https)"""
|
||||
"""Test the submission of URLs (http/https)"""
|
||||
assert self.submit_manager.pre(submit_type="strings", data=[
|
||||
"http://theguardian.com/",
|
||||
"https://news.ycombinator.com/",
|
||||
@@ -83,7 +83,7 @@ class TestSubmitManager(object):
|
||||
|
||||
@responses.activate
|
||||
def test_pre_hash(self):
|
||||
"""Tests the submission of a VirusTotal hash."""
|
||||
"""Test the submission of a VirusTotal hash."""
|
||||
with responses.RequestsMock(assert_all_requests_are_fired=True) as rsps:
|
||||
rsps.add(
|
||||
responses.GET, VirusTotalAPI.HASH_DOWNLOAD, body="A"*1024*1024
|
||||
|
||||
+7
-7
@@ -26,19 +26,19 @@ class TestCreateFolders:
|
||||
self.tmp_dir = tempfile.gettempdir()
|
||||
|
||||
def test_root_folder(self):
|
||||
"""Tests a single folder creation based on the root parameter."""
|
||||
"""Test single folder creation based on the root parameter."""
|
||||
Folders.create(os.path.join(self.tmp_dir, "foo"))
|
||||
assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
|
||||
os.rmdir(os.path.join(self.tmp_dir, "foo"))
|
||||
|
||||
def test_single_folder(self):
|
||||
"""Tests a single folder creation."""
|
||||
"""Test single folder creation."""
|
||||
Folders.create(self.tmp_dir, "foo")
|
||||
assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
|
||||
os.rmdir(os.path.join(self.tmp_dir, "foo"))
|
||||
|
||||
def test_multiple_folders(self):
|
||||
"""Tests multiple folders creation."""
|
||||
"""Test multiple folder creation."""
|
||||
Folders.create(self.tmp_dir, ["foo", "bar"])
|
||||
assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
|
||||
assert os.path.exists(os.path.join(self.tmp_dir, "bar"))
|
||||
@@ -46,7 +46,7 @@ class TestCreateFolders:
|
||||
os.rmdir(os.path.join(self.tmp_dir, "bar"))
|
||||
|
||||
def test_copy_folder(self):
|
||||
"""Tests recursive folder copy"""
|
||||
"""Test recursive folder copy."""
|
||||
dirpath = tempfile.mkdtemp()
|
||||
set_cwd(dirpath)
|
||||
|
||||
@@ -54,21 +54,21 @@ class TestCreateFolders:
|
||||
assert os.path.isfile("%s/reports/report.json" % dirpath)
|
||||
|
||||
def test_duplicate_folder(self):
|
||||
"""Tests a duplicate folder creation."""
|
||||
"""Test a duplicate folder creation."""
|
||||
Folders.create(self.tmp_dir, "foo")
|
||||
assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
|
||||
Folders.create(self.tmp_dir, "foo")
|
||||
os.rmdir(os.path.join(self.tmp_dir, "foo"))
|
||||
|
||||
def test_delete_folder(self):
|
||||
"""Tests folder deletion #1."""
|
||||
"""Test folder deletion #1."""
|
||||
Folders.create(self.tmp_dir, "foo")
|
||||
assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
|
||||
Folders.delete(os.path.join(self.tmp_dir, "foo"))
|
||||
assert not os.path.exists(os.path.join(self.tmp_dir, "foo"))
|
||||
|
||||
def test_delete_folder2(self):
|
||||
"""Tests folder deletion #2."""
|
||||
"""Test folder deletion #2."""
|
||||
Folders.create(self.tmp_dir, "foo")
|
||||
assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
|
||||
Folders.delete(self.tmp_dir, "foo")
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ class chdir(object):
|
||||
os.chdir(self.origpath)
|
||||
|
||||
def init_analysis(task_id, package, *filename):
|
||||
"""Initializes an analysis with an "encrypted" binary from tests/files/."""
|
||||
"""Initialize an analysis with an "encrypted" binary from tests/files/."""
|
||||
mkdir(cwd(analysis=task_id))
|
||||
content = open(os.path.join("tests", "files", *filename), "rb").read()
|
||||
open(cwd("binary", analysis=task_id), "wb").write(content[::-1])
|
||||
|
||||
Reference in New Issue
Block a user