def test_options(self): assert parse_options("a=b") == {"a": "b"} assert parse_options("a=b,b=c") == {"a": "b", "b": "c"} assert parse_options("a,b") == {} assert emit_options({"a": "b"}) == "a=b" assert emit_options({"a": "b", "b": "c"}) == "a=b,b=c" assert parse_options(emit_options({"x": "y"})) == {"x": "y"}
def tasks_create_submit(): files = [] for f in request.files.getlist("file") + request.files.getlist("files"): files.append({ # The pseudo-file "f" has a read() method so passing it along to # the Submit Manager as-is should be fine. "name": f.filename, "data": f, }) if files: submit_type = "files" elif request.form.get("strings"): submit_type = "strings" strings = request.form["strings"].split("\n") else: return json_error(500, "No files or strings have been given!") # Default options. options = { "procmemdump": "yes", } options.update(parse_options(request.form.get("options", ""))) submit_id = sm.pre( submit_type, files or strings, sm.translate_options_to(options) ) if not submit_id: return json_error(500, "Error creating Submit entry") files, errors, options = sm.get_files(submit_id, astree=True) options["full-memory-dump"] = parse_bool( request.form.get("memory", config("cuckoo:cuckoo:memory_dump")) ) options["enforce-timeout"] = parse_bool( request.form.get("enforce_timeout", 0) ) def selected(files, arcname=None): ret = [] for entry in files: if entry.get("selected"): entry["arcname"] = arcname ret.append(entry) ret += selected(entry["children"], arcname or entry["filename"]) return ret task_ids = sm.submit(submit_id, { "global": { "timeout": request.form.get("timeout", ""), "priority": request.form.get("priority", 1), "tags": request.form.get("tags", None), "custom": request.form.get("custom", ""), "owner": request.form.get("owner", ""), "clock": request.form.get("clock", None), "options": options, }, "file_selection": selected(files), }) return jsonify(submit_id=submit_id, task_ids=task_ids, errors=errors)
def determine_analyzer_path(self): """Determine the path of the analyzer. Basically creating a temporary directory in the systemdrive, i.e., C:\\.""" systemdrive = self.determine_system_drive() options = parse_options(self.options["options"]) if options.get("analpath"): dirpath = systemdrive + options["analpath"] r = self.post("/mkdir", data={"dirpath": dirpath}) self.analyzer_path = dirpath else: r = self.post("/mkdtemp", data={"dirpath": systemdrive}) self.analyzer_path = r.json()["dirpath"]
def determine_analyzer_path(self): """Determine the path of the analyzer. Basically creating a temporary directory in the systemdrive, i.e., C:\\.""" systemdrive = "%s\\" % self.environ["SYSTEMDRIVE"] options = parse_options(self.options["options"]) if options.get("analpath"): dirpath = "%s\\%s" % (systemdrive, options["analpath"]) r = self.post("/mkdir", data={"dirpath": dirpath}) self.analyzer_path = dirpath else: r = self.post("/mkdtemp", data={"dirpath": systemdrive}) self.analyzer_path = r.json()["dirpath"]