1
2
3
4
5 import time
6 import json
7 import logging
8 from datetime import datetime
9
10 from lib.cuckoo.core.database import Database
11 from lib.cuckoo.common.abstracts import Processing
12 from lib.cuckoo.common.constants import CUCKOO_VERSION
13
14 log = logging.getLogger(__name__)
15
17 """General information about analysis session."""
18
20 """Run information gathering.
21 @return: information dict.
22 """
23 self.key = "info"
24
25 try:
26 started = time.strptime(self.task["started_on"], "%Y-%m-%d %H:%M:%S")
27 started = datetime.fromtimestamp(time.mktime(started))
28 ended = time.strptime(self.task["completed_on"], "%Y-%m-%d %H:%M:%S")
29 ended = datetime.fromtimestamp(time.mktime(ended))
30 except:
31 log.critical("Failed to get start/end time from Task.")
32 duration = -1
33 else:
34 duration = (ended - started).seconds
35
36 db = Database()
37
38 task = db.view_task(self.task["id"], details=True)
39 if task:
40 entry = task.to_dict()
41
42 machine = db.view_machine(name=entry["machine"])
43 if machine:
44 self.task["machine"] = machine.to_dict()
45 self.task["machine"]["id"] = int(self.task["machine"]["id"])
46 else:
47 self.task["machine"] = {}
48 else:
49 self.task["machine"] = {}
50
51 return dict(
52 version=CUCKOO_VERSION,
53 started=self.task["started_on"],
54 ended=self.task.get("completed_on", "none"),
55 duration=duration,
56 id=int(self.task["id"]),
57 category=self.task["category"],
58 custom=self.task["custom"],
59 machine=self.task["machine"],
60 package=self.task["package"]
61 )
62