本文整理汇总了Python中lib.cuckoo.core.database.Database.list_machines方法的典型用法代码示例。如果您正苦于以下问题:Python Database.list_machines方法的具体用法?Python Database.list_machines怎么用?Python Database.list_machines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.cuckoo.core.database.Database
的用法示例。
在下文中一共展示了Database.list_machines方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
def index(request):
if request.method == "POST":
package = request.POST.get("package", "")
timeout = force_int(request.POST.get("timeout"))
options = request.POST.get("options", "")
priority = force_int(request.POST.get("priority"))
machine = request.POST.get("machine", "")
custom = request.POST.get("custom", "")
memory = bool(request.POST.get("memory", False))
enforce_timeout = bool(request.POST.get("enforce_timeout", False))
tags = request.POST.get("tags", None)
if request.POST.get("free"):
if options:
options += ","
options += "free=yes"
if request.POST.get("process_memory"):
if options:
options += ","
options += "procmemdump=yes"
db = Database()
task_ids = []
task_machines = []
if machine.lower() == "all":
for entry in db.list_machines():
task_machines.append(entry.label)
else:
task_machines.append(machine)
if "sample" in request.FILES:
for sample in request.FILES.getlist("sample"):
if sample.size == 0:
return render_to_response("error.html",
{"error": "You uploaded an empty file."},
context_instance=RequestContext(request))
elif sample.size > settings.MAX_UPLOAD_SIZE:
return render_to_response("error.html",
{"error": "You uploaded a file that exceeds that maximum allowed upload size."},
context_instance=RequestContext(request))
# Moving sample from django temporary file to Cuckoo temporary storage to
# let it persist between reboot (if user like to configure it in that way).
path = store_temp_file(sample.read(),
sample.name)
for entry in task_machines:
task_id = db.add_path(file_path=path,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=entry,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags)
if task_id:
task_ids.append(task_id)
elif "url" in request.POST:
url = request.POST.get("url").strip()
if not url:
return render_to_response("error.html",
{"error": "You specified an invalid URL!"},
context_instance=RequestContext(request))
for entry in task_machines:
task_id = db.add_url(url=url,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=entry,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags)
if task_id:
task_ids.append(task_id)
tasks_count = len(task_ids)
if tasks_count > 0:
return render_to_response("submission/complete.html",
{"tasks": task_ids,
"tasks_count": tasks_count},
context_instance=RequestContext(request))
else:
return render_to_response("error.html",
{"error": "Error adding task to Cuckoo's database."},
context_instance=RequestContext(request))
else:
files = os.listdir(os.path.join(settings.CUCKOO_PATH, "analyzer", "windows", "modules", "packages"))
packages = []
for name in files:
name = os.path.splitext(name)[0]
if name == "__init__":
continue
#.........这里部分代码省略.........
示例2: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
def index(request, task_id=None, sha1=None):
if request.method == "GET":
return render_index(request)
package = request.POST.get("package", "")
timeout = force_int(request.POST.get("timeout"))
options = request.POST.get("options", "")
priority = force_int(request.POST.get("priority"))
machine = request.POST.get("machine", "")
custom = request.POST.get("custom", "")
memory = bool(request.POST.get("memory", False))
enforce_timeout = bool(request.POST.get("enforce_timeout", False))
tags = request.POST.get("tags", None)
options = parse_options(options)
# The following POST fields take precedence over the options field.
if request.POST.get("route"):
options["route"] = request.POST.get("route")
if request.POST.get("free"):
options["free"] = "yes"
if request.POST.get("process_memory"):
options["procmemdump"] = "yes"
if request.POST.get("services"):
options["services"] = "yes"
db = Database()
task_ids = []
task_machines = []
if machine.lower() == "all":
for entry in db.list_machines():
task_machines.append(entry.label)
else:
task_machines.append(machine)
# In case of resubmitting a file.
if request.POST.get("category") == "file":
task = Database().view_task(task_id)
for entry in task_machines:
task_id = db.add_path(file_path=task.target,
package=package,
timeout=timeout,
options=emit_options(options),
priority=priority,
machine=entry,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags)
if task_id:
task_ids.append(task_id)
elif request.FILES.getlist("sample"):
samples = request.FILES.getlist("sample")
for sample in samples:
# Error if there was only one submitted sample and it's empty.
# But if there are multiple and one was empty, just ignore it.
if not sample.size:
if len(samples) != 1:
continue
return render_to_response("error.html",
{"error": "You uploaded an empty file."},
context_instance=RequestContext(request))
elif sample.size > settings.MAX_UPLOAD_SIZE:
return render_to_response("error.html",
{"error": "You uploaded a file that exceeds that maximum allowed upload size."},
context_instance=RequestContext(request))
# Moving sample from django temporary file to Cuckoo temporary
# storage to let it persist between reboot (if user like to
# configure it in that way).
path = store_temp_file(sample.read(), sample.name)
for entry in task_machines:
task_id = db.add_path(file_path=path,
package=package,
timeout=timeout,
options=emit_options(options),
priority=priority,
machine=entry,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags)
if task_id:
task_ids.append(task_id)
# When submitting a dropped file.
elif request.POST.get("category") == "dropped_file":
filepath = dropped_filepath(task_id, sha1)
for entry in task_machines:
task_id = db.add_path(file_path=filepath,
package=package,
#.........这里部分代码省略.........
示例3: Machinery
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
#.........这里部分代码省略.........
is found.
"""
try:
configured_vms = self._list()
except NotImplementedError:
return
for machine in self.machines():
# If this machine is already in the "correct" state, then we
# go on to the next machine.
if machine.label in configured_vms and \
self._status(machine.label) in [self.POWEROFF, self.ABORTED]:
continue
# This machine is currently not in its correct state, we're going
# to try to shut it down. If that works, then the machine is fine.
try:
self.stop(machine.label)
except CuckooMachineError as e:
msg = "Please update your configuration. Unable to shut " \
"'{0}' down or find the machine in its proper state:" \
" {1}".format(machine.label, e)
raise CuckooCriticalError(msg)
if not self.options_globals.timeouts.vm_state:
raise CuckooCriticalError("Virtual machine state change timeout "
"setting not found, please add it to "
"the config file.")
def machines(self):
"""List virtual machines.
@return: virtual machines list
"""
return self.db.list_machines()
def availables(self):
"""How many machines are free.
@return: free machines count.
"""
return self.db.count_machines_available()
def acquire(self, machine_id=None, platform=None, tags=None):
"""Acquire a machine to start analysis.
@param machine_id: machine ID.
@param platform: machine platform.
@param tags: machine tags
@return: machine or None.
"""
if machine_id:
return self.db.lock_machine(label=machine_id)
elif platform:
return self.db.lock_machine(platform=platform, tags=tags)
else:
return self.db.lock_machine(tags=tags)
def release(self, label=None):
"""Release a machine.
@param label: machine name.
"""
self.db.unlock_machine(label)
def running(self):
"""Returns running virtual machines.
@return: running virtual machines list.
"""
return self.db.list_machines(locked=True)
示例4: MachineManager
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
class MachineManager(object):
"""Base abstract class for analysis machine manager."""
def __init__(self):
self.module_name = ""
self.options = None
self.options_globals = Config(os.path.join(CUCKOO_ROOT, "conf", "cuckoo.conf"))
# Database pointer.
self.db = Database()
# Machine table is cleaned to be filled from configuration file at each start.
self.db.clean_machines()
def set_options(self, options):
"""Set machine manager options.
@param options: machine manager options dict.
"""
self.options = options
def initialize(self, module_name):
"""Read and load machines configuration, try to check the configuration.
@param module_name: module name.
"""
# Load.
self._initialize(module_name)
# Run initialization checks.
self._initialize_check()
def _initialize(self, module_name):
"""Read configuration.
@param module_name: module name.
"""
self.module_name = module_name
mmanager_opts = self.options.get(module_name)
for machine_id in mmanager_opts["machines"].strip().split(","):
# Parse from configuration file.
try:
machine_opts = self.options.get(machine_id.strip())
machine = Dictionary()
machine.id = machine_id.strip()
machine.label = machine_opts["label"].strip()
machine.platform = machine_opts["platform"].strip()
machine.ip = machine_opts["ip"].strip()
# Insert in db.
self.db.add_machine(name=machine.id,
label=machine.label,
ip=machine.ip,
platform=machine.platform)
except (AttributeError, CuckooOperationalError):
log.warning("Configuration details about machine %s are "
"missing. Continue" % machine_id)
continue
def _initialize_check(self):
"""Runs checks against virtualization software when a machine manager
is initialized.
@note: in machine manager modules you may override or superclass
his method.
@raise CuckooMachineError: if a misconfiguration or a unkown vm state
is found.
"""
try:
configured_vm = self._list()
except NotImplementedError:
return
for machine in self.machines():
if machine.label not in configured_vm:
raise CuckooCriticalError("Configured machine %s was not "
"detected or it's not in proper state" % machine.label)
# Options check.
if not self.options_globals.timeouts.vm_state:
raise CuckooCriticalError("Virtual machine state change timeout setting not found, please add it to the config file")
def machines(self):
"""List virtual machines.
@return: virtual machines list
"""
return self.db.list_machines()
def availables(self):
"""How many machines are free.
@return: free machines count.
"""
return self.db.count_machines_available()
def acquire(self, machine_id=None, platform=None):
"""Acquire a machine to start analysis.
@param machine_id: machine ID.
@param platform: machine platform.
@return: machine or None.
"""
if machine_id:
return self.db.lock_machine(name=machine_id)
elif platform:
return self.db.lock_machine(platform=platform)
else:
#.........这里部分代码省略.........
示例5: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
def index(request):
if request.method == "POST":
package = request.POST.get("package", "")
timeout = min(force_int(request.POST.get("timeout")), 60 * 60 * 24)
options = request.POST.get("options", "")
priority = force_int(request.POST.get("priority"))
machine = request.POST.get("machine", "")
gateway = request.POST.get("gateway", None)
clock = request.POST.get("clock", None)
custom = request.POST.get("custom", "")
memory = bool(request.POST.get("memory", False))
enforce_timeout = bool(request.POST.get("enforce_timeout", False))
referer = validate_referer(request.POST.get("referer", None))
tags = request.POST.get("tags", None)
task_gateways = []
ipaddy_re = re.compile(r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$")
if referer:
if options:
options += ","
options += "referer=%s" % (referer)
if request.POST.get("free"):
if options:
options += ","
options += "free=yes"
if request.POST.get("nohuman"):
if options:
options += ","
options += "nohuman=yes"
if request.POST.get("tor"):
if options:
options += ","
options += "tor=yes"
if request.POST.get("process_memory"):
if options:
options += ","
options += "procmemdump=yes"
if request.POST.get("kernel_analysis"):
if options:
options += ","
options += "kernel_analysis=yes"
orig_options = options
if gateway and gateway.lower() == "all":
for e in settings.GATEWAYS:
if ipaddy_re.match(settings.GATEWAYS[e]):
task_gateways.append(settings.GATEWAYS[e])
elif gateway and gateway in settings.GATEWAYS:
if "," in settings.GATEWAYS[gateway]:
if request.POST.get("all_gw_in_group"):
tgateway = settings.GATEWAYS[gateway].split(",")
for e in tgateway:
task_gateways.append(settings.GATEWAYS[e])
else:
tgateway = random.choice(settings.GATEWAYS[gateway].split(","))
task_gateways.append(settings.GATEWAYS[tgateway])
else:
task_gateways.append(settings.GATEWAYS[gateway])
if not task_gateways:
# To reduce to the default case
task_gateways = [None]
db = Database()
task_ids = []
task_machines = []
if machine.lower() == "all":
for entry in db.list_machines():
task_machines.append(entry.label)
else:
task_machines.append(machine)
if "sample" in request.FILES:
samples = request.FILES.getlist("sample")
for sample in samples:
# Error if there was only one submitted sample and it's empty.
# But if there are multiple and one was empty, just ignore it.
if not sample.size:
if len(samples) != 1:
continue
return render(request, "error.html",
{"error": "You uploaded an empty file."})
elif sample.size > settings.MAX_UPLOAD_SIZE:
return render(request, "error.html",
{"error": "You uploaded a file that exceeds the maximum allowed upload size specified in web/web/local_settings.py."})
# Moving sample from django temporary file to Cuckoo temporary storage to
# let it persist between reboot (if user like to configure it in that way).
path = store_temp_file(sample.read(),
sample.name)
#.........这里部分代码省略.........
示例6: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
def index(request):
if request.method == "POST":
package = request.POST.get("package", "")
timeout = min(force_int(request.POST.get("timeout")), 60 * 60 * 24)
options = request.POST.get("options", "")
priority = force_int(request.POST.get("priority"))
machine = request.POST.get("machine", "")
gateway = request.POST.get("gateway", None)
clock = request.POST.get("clock", None)
custom = request.POST.get("custom", "")
memory = bool(request.POST.get("memory", False))
enforce_timeout = bool(request.POST.get("enforce_timeout", False))
tags = request.POST.get("tags", None)
if request.POST.get("free"):
if options:
options += ","
options += "free=yes"
if request.POST.get("nohuman"):
if options:
options += ","
options += "nohuman=yes"
if request.POST.get("tor"):
if options:
options += ","
options += "tor=yes"
if request.POST.get("process_memory"):
if options:
options += ","
options += "procmemdump=yes"
if request.POST.get("kernel_analysis"):
if options:
options += ","
options += "kernel_analysis=yes"
if gateway and gateway in settings.GATEWAYS:
if "," in settings.GATEWAYS[gateway]:
tgateway = random.choice(settings.GATEWAYS[gateway].split(","))
ngateway = settings.GATEWAYS[tgateway]
else:
ngateway = settings.GATEWAYS[gateway]
if options:
options += ","
options += "setgw=%s" % (ngateway)
db = Database()
task_ids = []
task_machines = []
if machine.lower() == "all":
for entry in db.list_machines():
task_machines.append(entry.label)
else:
task_machines.append(machine)
if "sample" in request.FILES:
for sample in request.FILES.getlist("sample"):
if sample.size == 0:
return render_to_response("error.html",
{"error": "You uploaded an empty file."},
context_instance=RequestContext(request))
elif sample.size > settings.MAX_UPLOAD_SIZE:
return render_to_response("error.html",
{"error": "You uploaded a file that exceeds that maximum allowed upload size."},
context_instance=RequestContext(request))
# Moving sample from django temporary file to Cuckoo temporary storage to
# let it persist between reboot (if user like to configure it in that way).
path = store_temp_file(sample.read(),
sample.name)
for entry in task_machines:
task_ids_new = db.demux_sample_and_add_to_db(file_path=path, package=package, timeout=timeout, options=options, priority=priority,
machine=entry, custom=custom, memory=memory, enforce_timeout=enforce_timeout, tags=tags, clock=clock)
task_ids.extend(task_ids_new)
elif "url" in request.POST and request.POST.get("url").strip():
url = request.POST.get("url").strip()
if not url:
return render_to_response("error.html",
{"error": "You specified an invalid URL!"},
context_instance=RequestContext(request))
for entry in task_machines:
task_id = db.add_url(url=url,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=entry,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags,
clock=clock)
if task_id:
#.........这里部分代码省略.........
示例7: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
def index(request):
if request.method == "POST":
package = request.POST.get("package", "")
# Timeout is in minute, but we handle seconds in the backend
timeout = force_int(request.POST.get("timeout")) * 60
options = request.POST.get("options", "")
priority = force_int(request.POST.get("priority"))
machine = request.POST.get("machine", "")
custom = request.POST.get("custom", "")
memory = bool(request.POST.get("memory", False))
enforce_timeout = bool(request.POST.get("enforce_timeout", False))
tags = request.POST.get("tags", "")
recurring = request.POST.get("recurring", None)
experiment_name = request.POST.get("experiment_name", "")
if request.POST.get("free"):
if options:
options += ","
options += "free=yes"
if request.POST.get("process_memory"):
if options:
options += ","
options += "procmemdump=yes"
recurring = TASK_SINGLE
if request.POST.get("recurring"):
recurring = TASK_RECURRENT
tags = "longterm,%s" % tags
db = Database()
task_ids = []
task_machines = []
if machine.lower() == "all":
for entry in db.list_machines(locked=False):
task_machines.append(entry.label)
else:
task_machines.append(machine)
if "sample" in request.FILES:
if request.FILES["sample"].size == 0:
return render_to_response("error.html",
{"error": "You uploaded an empty file."},
context_instance=RequestContext(request))
elif request.FILES["sample"].size > settings.MAX_UPLOAD_SIZE:
return render_to_response("error.html",
{"error": "You uploaded a file that exceeds that maximum allowed upload size."},
context_instance=RequestContext(request))
# Moving sample from django temporary file to Cuckoo temporary storage to
# let it persist between reboot (if user like to configure it in that way).
path = store_temp_file(request.FILES["sample"].read(),
request.FILES["sample"].name)
for entry in task_machines:
task_id = db.add_path(file_path=path,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=entry,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags,
name=experiment_name,
repeat=recurring)
if task_id:
task_ids.append(task_id)
elif "url" in request.POST:
url = request.POST.get("url").strip()
if not url:
return render_to_response("error.html",
{"error": "You specified an invalid URL!"},
context_instance=RequestContext(request))
for entry in task_machines:
task_id = db.add_url(url=url,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=entry,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags,
name=experiment_name)
if task_id:
task_ids.append(task_id)
tasks_count = len(task_ids)
if tasks_count > 0:
if tasks_count == 1:
message = "The analysis task was successfully added with ID {0}.".format(task_ids[0])
else:
message = "The analysis task were successfully added with IDs {0}.".format(", ".join(str(i) for i in task_ids))
return render_to_response("success.html",
#.........这里部分代码省略.........
示例8: HealthStatistics
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
#.........这里部分代码省略.........
if self.simple:
return name
else:
return filename
def task_analysis_pie(self):
""" Showing a pie chart for the task analysis. Viewing problems and issues like Anti-VM, crashes, ...
"""
name = "analysis_issues_pie.svg"
filename = os.path.join(self.datadir, name)
status_list = [("Few API calls", TASK_ISSUE_SHORT_API_CALL_LIST),
("Crash", TASK_ISSUE_CRASH),
("Anti*", TASK_ISSUE_ANTI),
("Timed out", TASK_TIMEDOUT),
("Ok", TASK_ISSUE_NONE),
("Perfect", TASK_ISSUE_PERFECT)]
status_pie = pygal.Pie(fill=self.style["fill"],
interpolate=self.style["interpolate"],
style=self.style["style"])
status_pie.title = 'Detailed analysis issues'
for human, stat in status_list:
status_pie.add(human, self.db.task_analysis_issues(stat))
status_pie.render_to_file(filename)
if self.simple:
return name
else:
return filename
def task_analysis_by_machine_bar(self):
""" Showing a pie chart for the task analysis. Viewing problems and issues like Anti-VM, crashes, ...
"""
name = "analysis_issues_by_machine_bar.svg"
filename = os.path.join(self.datadir, name)
machines = self.db.list_machines()
status_list = [("Few API calls", TASK_ISSUE_SHORT_API_CALL_LIST),
("Crash", TASK_ISSUE_CRASH),
("Anti*", TASK_ISSUE_ANTI),
("Timed out", TASK_TIMEDOUT),
("Ok", TASK_ISSUE_NONE),
("Perfect", TASK_ISSUE_PERFECT)]
analysis_bar = pygal.StackedBar(fill=self.style["fill"],
interpolate=self.style["interpolate"],
style=self.style["style"])
analysis_bar.title = 'Detailed analysis issues'
lshort = []
lcrash = []
lanti = []
lok = []
lperfect = []
ltimedout = []
label_list = []
for m in machines:
label_list.append(m.name)
lshort.append(self.db.task_analysis_issues(TASK_ISSUE_SHORT_API_CALL_LIST, mid=m.id))
lcrash.append(self.db.task_analysis_issues(TASK_ISSUE_CRASH, mid=m.id))
lanti.append(self.db.task_analysis_issues(TASK_ISSUE_ANTI, mid=m.id))
ltimedout.append(self.db.task_analysis_issues(TASK_TIMEDOUT, mid=m.id))
lok.append(self.db.task_analysis_issues(TASK_ISSUE_NONE, mid=m.id))
lperfect.append(self.db.task_analysis_issues(TASK_ISSUE_PERFECT, mid=m.id))
analysis_bar.x_labels = label_list
analysis_bar.add("Few API calls", lshort)
analysis_bar.add("Crash", lcrash)
analysis_bar.add("Anti*", lanti)
analysis_bar.add("Timed out", ltimedout)
analysis_bar.add("Ok", lok)
示例9: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
def index(request):
if request.method == "POST":
package = request.POST.get("package", "")
timeout = force_int(request.POST.get("timeout"))
options = request.POST.get("options", "")
priority = force_int(request.POST.get("priority"))
machine = request.POST.get("machine", "")
gateway = request.POST.get("gateway",None)
custom = request.POST.get("custom", "")
memory = bool(request.POST.get("memory", False))
enforce_timeout = bool(request.POST.get("enforce_timeout", False))
tags = request.POST.get("tags", None)
if request.POST.get("free"):
if options:
options += ","
options += "free=yes"
if request.POST.get("process_memory"):
if options:
options += ","
options += "procmemdump=yes"
if gateway:
if "," in settings.GATEWAYS[gateway]:
tgateway = random.choice(settings.GATEWAYS[gateway].split(","))
ngateway = settings.GATEWAYS[tgateway]
else:
ngateway = settings.GATEWAYS[gateway]
if options:
options += ","
options += "setgw=%s" % (ngateway)
db = Database()
task_ids = []
task_machines = []
if machine.lower() == "all":
for entry in db.list_machines():
task_machines.append(entry.label)
else:
task_machines.append(machine)
if "sample" in request.FILES:
if request.FILES["sample"].size == 0:
return render_to_response("error.html",
{"error": "You uploaded an empty file."},
context_instance=RequestContext(request))
elif request.FILES["sample"].size > settings.MAX_UPLOAD_SIZE:
return render_to_response("error.html",
{"error": "You uploaded a file that exceeds that maximum allowed upload size."},
context_instance=RequestContext(request))
# Moving sample from django temporary file to Cuckoo temporary storage to
# let it persist between reboot (if user like to configure it in that way).
path = store_temp_file(request.FILES["sample"].read(),
request.FILES["sample"].name)
for entry in task_machines:
task_id = db.add_path(file_path=path,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=entry,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags)
if task_id:
task_ids.append(task_id)
elif "url" in request.POST and request.POST.get("url").strip():
url = request.POST.get("url").strip()
if not url:
return render_to_response("error.html",
{"error": "You specified an invalid URL!"},
context_instance=RequestContext(request))
for entry in task_machines:
task_id = db.add_url(url=url,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=entry,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags)
if task_id:
task_ids.append(task_id)
elif settings.VTDL_ENABLED and "vtdl" in request.POST:
vtdl = request.POST.get("vtdl").strip()
if settings.VTDL_KEY == None or settings.VTDL_PATH == None:
return render_to_response("error.html",
{"error": "You specified VirusTotal but must edit the file and specify your VTDL_KEY variable and VTDL_PATH base directory"},
context_instance=RequestContext(request))
#.........这里部分代码省略.........
示例10: index
# 需要导入模块: from lib.cuckoo.core.database import Database [as 别名]
# 或者: from lib.cuckoo.core.database.Database import list_machines [as 别名]
def index(request):
if request.method == "POST":
package = request.POST.get("package", "")
timeout = force_int(request.POST.get("timeout"))
options = request.POST.get("options", "")
priority = force_int(request.POST.get("priority"))
machine = request.POST.get("machine", "")
custom = request.POST.get("custom", "")
memory = bool(request.POST.get("memory", False))
enforce_timeout = bool(request.POST.get("enforce_timeout", False))
tags = request.POST.get("tags", None)
if request.POST.get("free"):
if options:
options += "&"
options += "free=yes"
if request.POST.get("process_memory"):
if options:
options += "&"
options += "procmemdump=yes"
if "sample" in request.FILES:
# Preventive checks.
if request.FILES["sample"].size == 0:
return render_to_response("error.html",
{"error": "You uploaded an empty file."},
context_instance=RequestContext(request))
elif request.FILES["sample"].size > settings.MAX_UPLOAD_SIZE:
return render_to_response("error.html",
{"error": "You uploaded a file that exceeds that maximum allowed upload size."},
context_instance=RequestContext(request))
path = request.FILES["sample"].temporary_file_path()
db = Database()
task_ids = []
if machine == 'ALL':
for m in db.list_machines():
task_ids.append(db.add_path(file_path=path,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=m,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags))
else:
task_ids.append(db.add_path(file_path=path,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=machine,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags))
if len(task_ids) == 1:
return render_to_response("success.html",
{"message": "The analysis task was successfully added with ID {0}.".format(task_ids[0])},
context_instance=RequestContext(request))
elif len(task_ids) > 1:
return render_to_response("success.html",
{"message": "The analysis task were successfully added with IDs {0}.".format(', '.join(str(i) for i in task_ids))},
context_instance=RequestContext(request))
else:
return render_to_response("error.html",
{"error": "Error adding task to Cuckoo's database."},
context_instance=RequestContext(request))
elif "url" in request.POST:
url = request.POST.get("url").strip()
if not url:
return render_to_response("error.html",
{"error": "You specified an invalid URL!"},
context_instance=RequestContext(request))
db = Database()
task_ids = []
if machine == "ALL":
for m in db.list_machines():
task_ids.append(db.add_url(url=url,
package=package,
timeout=timeout,
options=options,
priority=priority,
machine=m,
custom=custom,
memory=memory,
enforce_timeout=enforce_timeout,
tags=tags))
else:
task_ids.append(db.add_url(url=url,
package=package,
timeout=timeout,
options=options,
priority=priority,
#.........这里部分代码省略.........