コード例 #1
0
ファイル: Vault.py プロジェクト: sylvanasbeta/VxVault
	def __init__(self, _base, _password="", _multipleSamplesAllowed = False, _logger=None):
		"""Initializes the Vault and the FileSystem objects.

		Creates a new Vault object which is used to interface
		with the file system of the operating system. 

		Args:
			_base: 
				The directory in which the filesystem of the vault will
				be created.
			_name:
				Optional name to identify the vault object.
			_logger: 
				Logger object to output information about program 
				execution. If none provided, it will use sys.stdout
				by default.

		Returns:
			None.

		Raises:
			None.
		"""	
		# Creates a new logger object.
		if _logger == None: self.logger = Logger(sys.stdout)
		else: self.logger = _logger
		# Initialize the FileSystem object with the given
		# base.
		self.file_system = FileSystem(_base, _logger=_logger)
		#
		# Initializes the database.
		#
		self.database = VaultDatabase(
			_file=self.file_system.get_db_file(),
			_logger=self.logger)
		#
		# Sets the archiver object for storing files in
		# the vault.
		#
		archive_program = SevenZipArchiver(
			_password = Vault.DefaultArchivePassword,
			_logger = self.logger
		)
		self.set_archiver(archive_program)
		self.multipleSamplesAllowed = _multipleSamplesAllowed
コード例 #2
0
ファイル: Vault.py プロジェクト: sylvanasbeta/VxVault
	def __init__(self, _base, _logger=None):
		#**********************************************************************
		# Creates a new logger object.
		#**********************************************************************
		if _logger == None: self.logger = Logger(sys.stdout)
		else: self.logger = _logger
		
		#**********************************************************************
		# Sets the base directory of the vault.
		#**********************************************************************
		self.set_base(_base)
		
		#**********************************************************************
		# Create the database of the vault.
		#**********************************************************************
		self.database = VaultDatabase(self.get_db_file)
		
		#**********************************************************************
		# Specify the first level of directories to create in the base
		# directory, i.e. list of operating systems.
		#**********************************************************************
		self.FileStructure[self.get_base()] = FileSystem.OperatingSystems
コード例 #3
0
ファイル: Vault.py プロジェクト: sylvanasbeta/VxVault
class Vault(object):

	# Password used to archive malware.
	# TODO: 
	#	[X] User-provided from command line.
	DefaultArchivePassword = DEFAULT_ARCHIVE_PASSWORD

	def __init__(self, _base, _password="", _multipleSamplesAllowed = False, _logger=None):
		"""Initializes the Vault and the FileSystem objects.

		Creates a new Vault object which is used to interface
		with the file system of the operating system. 

		Args:
			_base: 
				The directory in which the filesystem of the vault will
				be created.
			_name:
				Optional name to identify the vault object.
			_logger: 
				Logger object to output information about program 
				execution. If none provided, it will use sys.stdout
				by default.

		Returns:
			None.

		Raises:
			None.
		"""	
		# Creates a new logger object.
		if _logger == None: self.logger = Logger(sys.stdout)
		else: self.logger = _logger
		# Initialize the FileSystem object with the given
		# base.
		self.file_system = FileSystem(_base, _logger=_logger)
		#
		# Initializes the database.
		#
		self.database = VaultDatabase(
			_file=self.file_system.get_db_file(),
			_logger=self.logger)
		#
		# Sets the archiver object for storing files in
		# the vault.
		#
		archive_program = SevenZipArchiver(
			_password = Vault.DefaultArchivePassword,
			_logger = self.logger
		)
		self.set_archiver(archive_program)
		self.multipleSamplesAllowed = _multipleSamplesAllowed
		
	def __repr__(self):
		return "<Vault '{:s}' @{:s}>".format(
			self.get_name(), self.file_system.get_base())
		
	def create_vault(self, _overwrite=False):
		""" Creates the database and filesystem of the vault.
		
		This function will first create the database file and schema. It
		will then create the filesystem to store the files. 
		
		Args:
			_overwrite: Optional. If set to true, will create the
			database and filesystem even if it already exists.
		Returns:
			None.
		Raises:
			None.
		"""
		self.database.create_database(_overwrite)
		self.file_system.create_filesystem(_overwrite)
		
	def is_created(self):
		"""Verifies if this vault has already been created
		in the filesystem.

		This function will confirm if the vault has been created
		on the file system.

		Args:
			None.

		Returns:
			True if the vault has been created in the configured base
			directory provided at the creation of the engine. Returns 
			False otherwie.

		Raises:
			None.
		"""	
		fs_is_created = self.file_system.filesystem_exists()
		db_is_created = self.file_system.database_file_exists()
		return fs_is_created and db_is_created
		
	def get_pit(self):
		"""Retrieves the absolute path of the SUBFOLDER_PIT
		directory.

		This function will retrieves the absolute path of the SUBFOLDER_PIT
		directory.

		Args:
			None.

		Returns:
			Absolute path of the SUBFOLDER_PIT directory.

		Raises:
			None.
		"""	
		return self.file_system.get_pit()
		
	def archive_file(self, _vx):
		""" Archives the files held in the given Virus object into
		an archive in the Vault.

		This function is a shortcut function to FileSystem.archive_file.

		Args:
			_vx: Virus object containing metadata about the malware.

		Returns:
			None.

		Raises:
			Exception if the provided Virus object is null.
		"""	
		self.file_system.archive_file(_vx)
		self.database.add_malware(_vx)

	def file_is_archived(self, _file):
		""" Verifies if the given file is already stored in one of the
		archive in the vault.
		
		This function is a shortcut to VaultDatabase.file_exists.
		
		Args:
			_file: Absolute path of the file to verify.
			
		Returns:
			True if the SHA1 hash of the given file is found in the Files table
			of the database. False otherwise.
			
		Raises:
			Exception if null or empty arguments. Raise exception if given
			file is not found.
			
		"""
		self.logger.print_info("Verifying if file '{:s}' is already archived.".format(_file))
		if (_file and len(_file) > 0):
			return self.database.file_exists(_file)
		else:
			raise NullOrEmptyArgumentException()
		
	def set_archiver(self, _archiver):
		""" Sets the Archiver to be used by the Vault to archive and 
		compress malware into the filesystem.

		This function sets the Archiver to be used by the Vault to archive and 
		compress malware into the filesystem.

		Args:
			_archiver: An Archiver object.

		Returns:
			None.

		Raises:
			Exception if the provided Virus object is null.
		"""	
		self.file_system.set_archiver(_archiver)