Пример #1
0
    def read_next_message(self):
        # read until newline for file path
        # e.g. shots/0001.jpg or files/9498687557/libcurl-4.dll.bin

        buf = self.handler.read_newline().strip().replace('\\', '/')
        log.debug("File upload request for {0}".format(buf))

        if '../' in buf:
            raise CuckooOperationalError("FileUpload failure, banned path.")

        dir_part, filename = os.path.split(buf)

        if dir_part:
            try:
                create_folder(self.storagepath, dir_part)
            except CuckooOperationalError:
                log.error("Unable to create folder %s" % folder)
                return False

        file_path = os.path.join(self.storagepath, buf.strip())

        fd = open(file_path, "wb")
        chunk = self.handler.read_any()
        while chunk:
            fd.write(chunk)

            if fd.tell() >= self.upload_max_size:
                fd.write('... (truncated)')
                break

            chunk = self.handler.read_any()

        log.debug("Uploaded file length: {0}".format(fd.tell()))
        fd.close()
Пример #2
0
    def read_next_message(self):
        # read until newline for file path
        # e.g. shots/0001.jpg or files/9498687557/libcurl-4.dll.bin

        buf = self.handler.read_newline().strip().replace('\\', '/')
        log.debug("File upload request for {0}".format(buf))

        if '../' in buf:
            raise CuckooOperationalError("FileUpload failure, banned path.")

        dir_part, filename = os.path.split(buf)

        if dir_part:
            try: create_folder(self.storagepath, dir_part)
            except CuckooOperationalError:
                log.error("Unable to create folder %s" % folder)
                return False

        file_path = os.path.join(self.storagepath, buf.strip())

        fd = open(file_path, "wb")
        chunk = self.handler.read_any()
        while chunk:
            fd.write(chunk)

            if fd.tell() >= self.upload_max_size:
                fd.write('... (truncated)')
                break

            chunk = self.handler.read_any()

        log.debug("Uploaded file length: {0}".format(fd.tell()))
        fd.close()
Пример #3
0
    def create_folders(self):
        folders = ["shots", "files", "logs"]

        for folder in folders:
            try:
                create_folder(self.storagepath, folder=folder)
            except CuckooOperationalError:
                log.error("Unable to create folder %s" % folder)
                return False
Пример #4
0
    def create_folders(self):
        folders = ["shots", "files", "logs"]

        for folder in folders:
            try:
                create_folder(self.storagepath, folder=folder)
            except CuckooOperationalError:
                log.error("Unable to create folder %s" % folder)
                return False
Пример #5
0
    def set_path(self, analysis_path):
        """Set analysis folder path.
        @param analysis_path: analysis folder path.
        """
        self.analysis_path = analysis_path
        self.conf_path = os.path.join(self.analysis_path, "analysis.conf")
        self.file_path = os.path.realpath(
            os.path.join(self.analysis_path, "binary"))
        self.reports_path = os.path.join(self.analysis_path, "reports")
        self.shots_path = os.path.join(self.analysis_path, "shots")
        self.pcap_path = os.path.join(self.analysis_path, "dump.pcap")

        try:
            create_folder(folder=self.reports_path)
        except CuckooOperationalError as e:
            CuckooReportError(e)
Пример #6
0
    def set_path(self, analysis_path):
        """Set analysis folder path.
        @param analysis_path: analysis folder path.
        """
        self.analysis_path = analysis_path
        self.conf_path = os.path.join(self.analysis_path, "analysis.conf")
        self.file_path = os.path.realpath(os.path.join(self.analysis_path,
                                                       "binary"))
        self.reports_path = os.path.join(self.analysis_path, "reports")
        self.shots_path = os.path.join(self.analysis_path, "shots")
        self.pcap_path = os.path.join(self.analysis_path, "dump.pcap")

        try:
            create_folder(folder=self.reports_path)
        except CuckooOperationalError as e:
            CuckooReportError(e)
Пример #7
0
    def init_storage(self):
        """Initialize analysis storage folder."""
        self.storage = os.path.join(CUCKOO_ROOT, "storage", "analyses",
                                    str(self.task.id))

        # If the analysis storage folder already exists, we need to abort the
        # analysis or previous results will be overwritten and lost.
        if os.path.exists(self.storage):
            log.error(
                "Analysis results folder already exists at path \"%s\","
                " analysis aborted", self.storage)
            return False

        # If we're not able to create the analysis storage folder, we have to
        # abort the analysis.
        try:
            create_folder(folder=self.storage)
        except CuckooOperationalError:
            log.error("Unable to create analysis folder %s", self.storage)
            return False

        return True
Пример #8
0
    def __init__(self, dsn=None):
        """@param dsn: database connection string."""
        cfg = Config()

        if dsn:
            self.engine = create_engine(dsn, poolclass=NullPool)
        elif cfg.database.connection:
            self.engine = create_engine(cfg.database.connection,
                                        poolclass=NullPool)
        else:
            db_file = os.path.join(CUCKOO_ROOT, "db", "cuckoo.db")
            if not os.path.exists(db_file):
                db_dir = os.path.dirname(db_file)
                if not os.path.exists(db_dir):
                    try:
                        create_folder(folder=db_dir)
                    except CuckooOperationalError as e:
                        raise CuckooDatabaseError("Unable to create database "
                                                  "directory: %s" % e)
            self.engine = create_engine("sqlite:///%s" % db_file,
                                        poolclass=NullPool)

        # Disable SQL logging. Turn it on for debugging.
        self.engine.echo = False
        # Connection timeout.
        if cfg.database.timeout:
            self.engine.pool_timeout = cfg.database.timeout
        else:
            self.engine.pool_timeout = 60
        # Create schema.
        try:
            Base.metadata.create_all(self.engine)
        except SQLAlchemyError as e:
            raise CuckooDatabaseError("Unable to create or connect to "
                                      "database: %s" % e)

        # Get db session.
        self.Session = sessionmaker(bind=self.engine)
Пример #9
0
    def init_storage(self):
        """Initialize analysis storage folder."""
        self.storage = os.path.join(CUCKOO_ROOT,
                                    "storage",
                                    "analyses",
                                    str(self.task.id))

        # If the analysis storage folder already exists, we need to abort the
        # analysis or previous results will be overwritten and lost.
        if os.path.exists(self.storage):
            log.error("Analysis results folder already exists at path \"%s\","
                      " analysis aborted", self.storage)
            return False

        # If we're not able to create the analysis storage folder, we have to
        # abort the analysis.
        try:
            create_folder(folder=self.storage)
        except CuckooOperationalError:
            log.error("Unable to create analysis folder %s", self.storage)
            return False

        return True
Пример #10
0
    def __init__(self, dsn=None):
        """@param dsn: database connection string."""
        cfg = Config()

        if dsn:
            self.engine = create_engine(dsn, poolclass=NullPool)
        elif cfg.database.connection:
            self.engine = create_engine(cfg.database.connection, poolclass=NullPool)
        else:
            db_file = os.path.join(CUCKOO_ROOT, "db", "cuckoo.db")
            if not os.path.exists(db_file):
                db_dir = os.path.dirname(db_file)
                if not os.path.exists(db_dir):
                    try:
                        create_folder(folder=db_dir)
                    except CuckooOperationalError as e:
                        raise CuckooDatabaseError("Unable to create database "
                                                  "directory: %s" % e)
            self.engine = create_engine("sqlite:///%s" % db_file, poolclass=NullPool)

        # Disable SQL logging. Turn it on for debugging.
        self.engine.echo = False
        # Connection timeout.
        if cfg.database.timeout:
            self.engine.pool_timeout = cfg.database.timeout
        else:
            self.engine.pool_timeout = 60
        # Create schema.
        try:
            Base.metadata.create_all(self.engine)
        except SQLAlchemyError as e:
            raise CuckooDatabaseError("Unable to create or connect to "
                                      "database: %s" % e)

        # Get db session.
        self.Session = sessionmaker(bind=self.engine)
Пример #11
0
 def test_single_folder(self):
     """Tests a single folder creation."""
     utils.create_folder(self.tmp_dir, "foo")
     assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
     utils.create_folder(self.tmp_dir, "foo")
     os.rmdir(os.path.join(self.tmp_dir, "foo"))
Пример #12
0
 def test_single_folder(self):
     """Tests a single folder creation."""
     utils.create_folder(self.tmp_dir, "foo")
     assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
     utils.create_folder(self.tmp_dir, "foo")
     os.rmdir(os.path.join(self.tmp_dir, "foo"))