Package modules :: Package processing :: Module analysisinfo
[hide private]
[frames] | no frames]

Source Code for Module modules.processing.analysisinfo

  1  # Copyright (C) 2010-2013 Claudio Guarnieri. 
  2  # Copyright (C) 2014-2016 Cuckoo Foundation. 
  3  # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org 
  4  # See the file 'docs/LICENSE' for copying permission. 
  5   
  6  import os 
  7  import logging 
  8   
  9  from lib.cuckoo.core.database import Database, Task 
 10  from lib.cuckoo.common.abstracts import Processing 
 11  from lib.cuckoo.common.constants import CUCKOO_VERSION 
 12  from lib.cuckoo.common.constants import CUCKOO_ROOT 
 13  from lib.cuckoo.common.config import emit_options 
 14  from lib.cuckoo.common.objects import File 
 15  from lib.cuckoo.common.utils import json_decode 
 16   
 17  log = logging.getLogger(__name__) 
 18   
19 -class AnalysisInfo(Processing):
20 """General information about analysis session.""" 21
22 - def run(self):
23 """Run information gathering. 24 @return: information dict. 25 """ 26 self.key = "info" 27 28 db = Database() 29 dbtask = db.view_task(self.task["id"], details=True) 30 31 if dbtask: 32 task = dbtask.to_dict() 33 else: 34 # task is gone from the database 35 if os.path.isfile(self.taskinfo_path): 36 # we've got task.json, so grab info from there 37 task = json_decode(open(self.taskinfo_path).read()) 38 else: 39 # we don't have any info on the task :( 40 emptytask = Task() 41 emptytask.id = self.task["id"] 42 task = emptytask.to_dict() 43 44 filepath = os.path.join( 45 CUCKOO_ROOT, ".git", "refs", "heads", "master" 46 ) 47 48 if os.path.exists(filepath) and os.access(filepath, os.R_OK): 49 git_head = open(filepath, "rb").read().strip() 50 else: 51 git_head = None 52 53 filepath = os.path.join(CUCKOO_ROOT, ".git", "FETCH_HEAD") 54 55 if os.path.exists(filepath) and os.access(filepath, os.R_OK): 56 git_fetch_head = open(filepath, "rb").read().strip() 57 58 # Only obtain the hash. 59 if git_fetch_head: 60 git_fetch_head = git_fetch_head.split()[0] 61 else: 62 git_fetch_head = None 63 64 monitor = os.path.join( 65 CUCKOO_ROOT, "data", "monitor", 66 task["options"].get("monitor", "latest") 67 ) 68 69 if os.path.islink(monitor): 70 monitor = os.readlink(monitor) 71 elif os.path.isfile(monitor): 72 monitor = open(monitor, "rb").read().strip() 73 elif os.path.isdir(monitor): 74 monitor = os.path.basename(monitor) 75 else: 76 monitor = None 77 78 return dict( 79 version=CUCKOO_VERSION, 80 git={ 81 "head": git_head, 82 "fetch_head": git_fetch_head, 83 }, 84 monitor=monitor, 85 started=task["started_on"], 86 ended=task.get("completed_on", "none"), 87 duration=task.get("duration", -1), 88 id=int(task["id"]), 89 category=task["category"], 90 custom=task["custom"], 91 owner=task["owner"], 92 machine=task["guest"], 93 package=task["package"], 94 platform=task["platform"], 95 options=emit_options(task["options"]), 96 route=task["route"], 97 )
98
99 -class MetaInfo(Processing):
100 """General information about the task and output files (memory dumps, etc).""" 101
102 - def run(self):
103 """Run information gathering. 104 @return: information dict. 105 """ 106 self.key = "metadata" 107 108 def reformat(x): 109 # kinda ugly absolute -> relative 110 relpath = x[len(self.analysis_path):].lstrip("/") 111 112 dirname = os.path.dirname(relpath) 113 basename = os.path.basename(relpath) 114 return dict(dirname=dirname or "", 115 basename=basename, 116 sha256=File(x).get_sha256())
117 118 meta = { 119 "output": {}, 120 } 121 122 if os.path.exists(self.pcap_path): 123 meta["output"]["pcap"] = reformat(self.pcap_path) 124 125 infos = [ 126 (self.pmemory_path, "memdumps"), 127 (self.buffer_path, "buffers"), 128 (self.dropped_path, "dropped"), 129 ] 130 131 for path, key in infos: 132 if os.path.exists(path): 133 contents = os.listdir(path) 134 if contents: 135 meta["output"][key] = [reformat(os.path.join(path, i)) for i in contents] 136 137 return meta
138