def machineList(self): api = cuckooapi.Api() result = api.machinesList() if result is "TO" or result is None: print "Error - Connection timeout" elif result is "SE": print "Error - Server Error" elif result is "KO": print "Error - Non controlled error" else: machineslist = result["machines"] if len(machineslist) == 0: print "Error - Machines list is empty" else: print "-------------------------------------------" for m in machineslist: print "Machine ID: ", m.get("id") print "Name: ", m.get("name") print "Label: ", m.get("label") print "Platform: ", m.get("platform") print "IP: ", m.get("ip") print "Status: ", m.get("status") print "Status changed on: ", m.get("status_changed_on") print "Locked: ", m.get("locked") print "Locked changed on: ", m.get("locked_changed_on") print "-------------------------------------------"
def machineView(self,name): api = cuckooapi.Api() result = api.machinesView(name=name) if result is "NF": print "Error - Machine not found" elif result is "TO" or result is None: print "Error - Connection timeout" elif result is "KO": print "Error - Non controlled error" elif result is "SE": print "Error - Machine not found" elif result is "ILT": print "Error - Machine not found" else: print "-------------------------------------------" print "Machine ID: ", result["machine"].get("id") print "Name: ", result["machine"].get("name") print "Label: ", result["machine"].get("label") print "Platform: ", result["machine"].get("platform") print "IP: ", result["machine"].get("ip") print "Status: ", result["machine"].get("status") print "Status changed on: ", result["machine"].get("status_changed_on") print "Locked: ", result["machine"].get("locked") print "Locked changed on: ", result["machine"].get("locked_changed_on") print "-------------------------------------------"
def taskView(self, id): api = cuckooapi.Api() result = api.taskView(id=id) if result is "NF": print "Error - Task not found" elif result is "TO" or result is None: print "Error - Connection timeout" elif result is "KO": print "Error - Non controlled error" else: print "-------------------------------------------" print "Task ID: ", result["task"].get("id") print "Target: ", result["task"].get("target") print "Category: ", result["task"].get("category") print "Priority: ", result["task"].get("priority") print "Package: ", result["task"].get("package") print "Memory: ", result["task"].get("memory") print "Custom: ", result["task"].get("custom") print "Machine: ", result["task"].get("machine") print "Platform: ", result["task"].get("platform") print "Added on: ", result["task"].get("added_on") print "Started on: ", result["task"].get("started_on") print "Shutdown on: ", result["task"].get("guest").get("shutdown_on") print "Completed on: ", result["task"].get("completed_on") print "Enforce timeout: ", result["task"].get("enforce_timeout") print "Timeout: ", result["task"].get("timeout") print "Options: ", result["task"].get("options") print "Manager: ", result["task"].get("guest").get("manager") print "Name: ", result["task"].get("guest").get("name") print "Status: ", result["task"].get("status") if len(result["task"].get("errors")) > 0: print "Errors: ", result["task"].get("errors").pop() print "-------------------------------------------"
def taskFilesView(self, md5=None, sha256=None, id=None): api = cuckooapi.Api() if md5 is not None: result = api.fileView(value=md5, type="md5") if sha256 is not None: result = api.fileView(value=sha256, type="sha256") if id is not None: result = api.fileView(value=id, type="id") if result is "NF": print "Error - File not found" elif result is "ILT": print "Error - Invalid lookup term" elif result is "TO" or result is None: print "Error - Operation timeout" elif result is "KO": print "Error - Non controlled error" else: print "-------------------------------------------" print "Sample ID: ", result["sample"].get("id") print "SHA1: ", result["sample"].get("sha1") print "SHA256: ", result["sample"].get("sha256") print "SHA512: ", result["sample"].get("sha512") print "MD5: ", result["sample"].get("md5") print "CRC32: ", result["sample"].get("crc32") print "SSDeep: ", result["sample"].get("ssdeep") print "File type: ", result["sample"].get("file_type") print "File size: ", result["sample"].get("file_size") print "-------------------------------------------"
def taskReport(self, id): api = cuckooapi.Api() result = api.taskReport(id) if result is "TO" or result is None: print "Error - Connection timeout" elif result is "SE": print "Error - Server Error" elif result is "KO": print "Error - Non controlled error" elif result is "NF": print "Error - Report not found" else: print "-------------------------------------------" print "-- Info --" print "Report ID: ", result["info"].get("id") print "Category: ", result["info"].get("category") print "Started: ", result["info"].get("started") print "Ended: ", result["info"].get("ended") print "Version: ", result["info"].get("version") print "Duration: ", result["info"].get("duration") print "" print "Signatures: ", result["signatures"] print "Static: ", result["static"] print "Dropped: ", result["dropped"] print "" print "-- Behavior --" print "Processes: ", result["behavior"].get("processes") print "Processtree: ", result["behavior"].get("processtree") print "Files: ", result["behavior"].get("summary").get("files") print "Keys: ", result["behavior"].get("summary").get("keys") print "Mutexes: ", result["behavior"].get("summary").get("mutexes") print "" print "-- Target --" print "Category: ", result["target"].get("category") print "Name: ", result["target"].get("file").get("name") print "Type: ", result["target"].get("file").get("type") print "Path: ", result["target"].get("file").get("path") print "Size: ", result["target"].get("file").get("size") print "SHA1: ", result["target"].get("file").get("sha1") print "SHA256: ", result["target"].get("file").get("sha256") print "SHA512: ", result["target"].get("file").get("sha512") print "CRC32: ", result["target"].get("file").get("crc32") print "SSDeep: ", result["target"].get("file").get("ssdeep") print "MD5: ", result["target"].get("file").get("md5") print "Yara: ", result["target"].get("file").get("yara") print "" print "-- Debug --" print "Errors: ", result["debug"].get("errors") print "Log: ", result["debug"].get("log") print "" print "Strings: ", result["strings"] print "" print "Network: ", result["network"]
def taskDelete(self, id): api = cuckooapi.Api() result = api.taskDelete(id=id) if result is "NF": print "Error - Unable to delete the task" elif result is "TO" or result is None: print "Error - Connection timeout" elif result is "KO": print "Error - Non controlled error" else: print "-------------------------------------------" print "Task ID:", id, "removed", result print "-------------------------------------------"
def submitURL(self, url, package=None, timeout=None, options=None, machine=None, platform=None, custom=None, memory=None, enforce_timeout=None): api = cuckooapi.Api() task_id = api.taskCreateURL(url=url, package=package, timeout=timeout, options=options, machine=machine, platform=platform, custom=custom, memory=memory, enforce_timeout=enforce_timeout) if task_id is "TO" or task_id is None: print "Error - Connection timeout" elif task_id is "SE": print "Error - Review parameters" elif task_id is "KO": print "Error - Non Controlled error" else: print "-------------------------------------------" print "URL:", url print "Submit OK - Task ID:", task_id print "-------------------------------------------"
def isavailablePlatform(self,platform): api = cuckooapi.Api() result = api.machinesList() if result is "TO" or result is None: print "Error - Connection timeout" elif result is "SE": print "Error - Server Error" elif result is "KO": print "Error - Non controlled error" else: machineslist = result["machines"] valid = False if len(machineslist) == 0: return valid else: for m in machineslist: name = m.get("platform") if name == platform: valid = True return valid
def getFile(self,sha256): try: api = cuckooapi.Api() result = api.fileGet(sha256=sha256) if result is "TO" or result is None: print "Error - Connection timeout" elif result is "SE": print "Error - Server Error" elif result is "KO": print "Error - Non controlled error" elif result is "NF": print "Error - File not found" else: name = sha256 + ".bin" file = open(name,"wb") file.write(result) file.close() print "File is saved as: ", name except Exception: print "Error - Getting File", e
def taskList(self): api = cuckooapi.Api() result = api.taskList() if result is "TO" or result is None: print "Error - Connection timeout" elif result is "SE": print "Error - Server Error" elif result is "KO": print "Error - Non controlled error" else: tasklist = result["tasks"] if len(tasklist) == 0: print "Error - Task list is empty" else: print "-------------------------------------------" for t in tasklist: print "Task ID: ", t.get("id") print "Target: ", t.get("target") print "Category: ", t.get("category") print "Priority: ", t.get("priority") print "Package: ", t.get("package") print "Memory: ", t.get("memory") print "Custom: ", t.get("custom") print "Machine: ", t.get("machine") print "Platform: ", t.get("platform") print "Added_on: ", t.get("added_on") print "Started on: ", t.get("started_on") print "Shutdown on: ", t.get("guest").get("shutdown_on") print "Completed on: ", t.get("completed_on") print "Enforce timeout: ", t.get("enforce_timeout") print "Timeout: ", t.get("timeout") print "Options: ", t.get("options") print "Manager: ", t.get("guest").get("manager") print "Name: ", t.get("guest").get("name") print "Status: ", t.get("status") if len(t.get("errors")) > 0: print "Errors: ", t.get("errors").pop() print "-------------------------------------------"
def submitDir(self, dir, package=None, timeout=None, options=None, machine=None, platform=None, custom=None, memory=None, enforce_timeout=None): if dir[-1] is not "/": dir = dir + "/" api = cuckooapi.Api() print "-------------------------------------------" print "Directory:", dir print "-------------------------------------------" files = os.listdir(dir) for f in files: file = dir + f task_id = api.taskCreateFile(file=file, package=package, timeout=timeout, options=options, machine=machine, platform=platform, custom=custom, memory=memory, enforce_timeout=enforce_timeout) if task_id is "TO" or task_id is None: print "Error - Connection timeout" sys.exit(1) elif task_id is "SE": print "Error - Review parameters" sys.exit(1) elif task_id is "KO": print "Error - Non Controlled error" sys.exit(1) else: print "File:", file print "Submit OK - Task ID:", task_id print "-------------------------------------------"