modules.auxiliary.reboot

Package modules :: Package auxiliary :: Module reboot |
[hide private]
[frames] | no frames]

# Source Code for Module modules.auxiliary.reboot

     1  # Copyright (C) 2016 Cuckoo Foundation.
     2  # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
     3  # See the file 'docs/LICENSE' for copying permission.
     4
     5  import json
     6  import logging
     7  import os.path
     8
     9  from lib.cuckoo.common.abstracts import Auxiliary
    10  from lib.cuckoo.common.constants import CUCKOO_ROOT
    11  from lib.cuckoo.common.exceptions import CuckooDisableModule
    12
    13  log = logging.getLogger(__name__)
    14
    15 -class Reboot(Auxiliary):
    16 -    def start(self):
    17          if self.task.package != "reboot":
    18              raise CuckooDisableModule
    19
    20 -    def cb_legacy_agent(self):
    21          log.error(
    22              "Reboot analysis is not backwards compatible with the Old Agent, "
    23              "please upgrade your target machine (%s) to the New Agent to use "
    24              "the reboot analysis capabilities.", self.machine
    25          )
    26          raise CuckooDisableModule
    27
    28 -    def _push_dropped_files(self, analysis_path):
    29          files_json = os.path.join(analysis_path, "files.json")
    30          if not os.path.exists(files_json):
    31              return
    32
    33          # Push dropped files through.
    34          for line in open(files_json, "rb"):
    35              entry = json.loads(line)
    36
    37              # Screenshots etc.
    38              if not entry["filepath"]:
    39                  continue
    40
    41              filepath = os.path.join(analysis_path, entry["path"])
    42
    43              data = {
    44                  "filepath": entry["filepath"],
    45              }
    46              files = {
    47                  "file": open(filepath, "rb"),
    48              }
    49              self.guest_manager.post("/store", files=files, data=data)
    50
    51 -    def cb_prepare_guest(self):
    52          log.info("Preparing task #%d for a reboot analysis..", self.task.id)
    53
    54          analysis_path = os.path.join(
    55              CUCKOO_ROOT, "storage", "analyses", self.task.custom
    56          )
    57
    58          self._push_dropped_files(analysis_path)
    59
    60          # Push the reboot.json file to the Analyzer.
    61          files = {
    62              "file": open(os.path.join(analysis_path, "reboot.json"), "rb"),
    63          }
    64          reboot_path = os.path.join(
    65              self.guest_manager.analyzer_path, "reboot.json"
    66          )
    67          data = {
    68              "filepath": reboot_path,
    69          }
    70          self.guest_manager.post("/store", files=files, data=data)
    71