1
2
3
4
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
20 """General information about analysis session."""
21
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
35 if os.path.isfile(self.taskinfo_path):
36
37 task = json_decode(open(self.taskinfo_path).read())
38 else:
39
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
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
138