def test_set_stub_module():
	
	test_obj = module_util.import_module("test_module")
	
	test_obj.override_class_name("test2")
	
	assert test_obj.get_class_name() == "test2"
	
	test_obj.set_name("test2")
	
	assert test_obj.name() == "test2"
	
	module_util.set_stub_module("test2", test_obj)
	
	assert module_util.module_exists("test2")
	module_list = module_util.get_module_list()
	assert "test2" in module_list

	module_util.remove_stub_module("test2")
	
	assert not module_util.module_exists("test2")
	module_list = module_util.get_module_list()
	assert not "test2" in module_list
Esempio n. 2
0
def test_set_stub_module():

    test_obj = module_util.import_module("test_module")

    test_obj.override_class_name("test2")

    assert test_obj.get_class_name() == "test2"

    test_obj.set_name("test2")

    assert test_obj.name() == "test2"

    module_util.set_stub_module("test2", test_obj)

    assert module_util.module_exists("test2")
    module_list = module_util.get_module_list()
    assert "test2" in module_list

    module_util.remove_stub_module("test2")

    assert not module_util.module_exists("test2")
    module_list = module_util.get_module_list()
    assert not "test2" in module_list
Esempio n. 3
0
	def add_module(self, module, forced=[]):
		
		if issubclass(module.__class__, base.module_base):
			module_name = module.get_class_name()
		elif cross_version.isstring(module):
			module_name = module
		else:
			raise ValueError("Invalid module to add. Must be module object or name")
		
		if module_util.module_exists(module_name):
			
			if self.__debug:
				print("Adding module " + module_name)
			
			self.__insert_module(module_name, module_util.import_module(module_name))
			self.__set_modules.append(module_name)
			
			if len(forced) > 0:
				self.__name_map[module_name].set_forced(forced)
			
		else:
			return
Esempio n. 4
0
    def add_module(self, module, forced=[]):

        if issubclass(module.__class__, base.module_base):
            module_name = module.get_class_name()
        elif cross_version.isstring(module):
            module_name = module
        else:
            raise ValueError(
                "Invalid module to add. Must be module object or name")

        if module_util.module_exists(module_name):

            if self.__debug:
                print("Adding module " + module_name)

            self.__insert_module(module_name,
                                 module_util.import_module(module_name))
            self.__set_modules.append(module_name)

            if len(forced) > 0:
                self.__name_map[module_name].set_forced(forced)

        else:
            return
Esempio n. 5
0
    def __module(self, options):

        if len(options) == 0:
            print("Incomplete command")
            print(
                "Valid sub-commands: add, remove, info, list, random, force, test"
            )
        else:
            subcommand = options[0]
            del options[0]

            if subcommand == "add":

                if not len(options) == 1:
                    print("module add: No module name")
                else:
                    module_name = options[0]

                    if module_util.module_exists(module_name):
                        if not module_name in self.__vars['to_run']['value']:
                            self.__vars['to_run']['value'].append(module_name)
                            print("Module added")
                        else:
                            print("Module is already set to be run")
                    else:
                        print("Module '" + module_name + "' does not exist")
            elif subcommand == "random":
                rand_list = []
                self.__vars['to_run']['value'] = []

                while len(rand_list) == 0:

                    mod_list = module_util.get_module_list()

                    set_level = self.__vars['level']['value']

                    for module in mod_list:
                        # Skip the test module
                        if module == "test_module":
                            continue

                        mod_obj = module_util.import_module(module)

                        if mod_obj:
                            if set_level == "any":
                                if ba_random().will_do():
                                    rand_list.append(module)
                            else:
                                if mod_obj.has_difficulty(
                                        set_level) and ba_random().will_do():
                                    rand_list.append(module)
                        else:
                            print("Could not import module " + module)

                for module_name in rand_list:
                    self.__vars['to_run']['value'].append(module_name)

            elif subcommand == "remove":
                if not len(options) == 1:
                    print("module add: No module set")
                else:
                    module_name = options[0]

                    if module_util.module_exists(module_name):
                        if module_name in self.__vars['to_run']['value']:
                            self.__vars['to_run']['value'].remove(module_name)
                            print("Module removed")
                        else:
                            print("Module is not set to run")
                    else:
                        print("Module '" + module_name + "' does not exist")
            elif subcommand == "info":

                if not len(options) == 1:
                    print("module info: No module name")
                else:
                    module_name = options[0]

                    if module_util.module_exists(module_name):
                        tmp_module = module_util.import_module(module_name)
                        print(tmp_module.info())

                        print("Vulnerabilities:")
                        for vuln in tmp_module.full_vulnerability_list():
                            print("    " + vuln)

                    else:
                        print("Module '" + module_name + "' does not exist")
            elif subcommand == "list":
                module_list = module_util.get_module_list()

                if len(module_list) > 0:
                    for item in module_list:
                        if item == "test_module":
                            continue
                        if item in self.__vars['to_run']['value']:
                            print("\t+ " + item)
                        else:
                            print("\t- " + item)
                else:
                    print("\nNo modules are set to run!")
            elif subcommand == "force":
                if not len(options) == 2:
                    print("Enter a module and vulnerability to force")
                else:
                    module = options[0]
                    vuln = options[1]

                    if module_util.module_exists(module):
                        if vuln in module_util.import_module(
                                module).full_vulnerability_list():
                            if not module in self.__vars['force']['value']:
                                self.__vars['force']['value'][module] = []

                            if not vuln in self.__vars['force']['value'][
                                    module]:
                                self.__vars['force']['value'][module].append(
                                    vuln)
                            else:
                                print(
                                    "That vulnerability is already being forced"
                                )
                        else:
                            print("Module '" + module +
                                  "' does not have the vulnerability '" +
                                  vuln + "'")
                    else:
                        print("Module '" + module + "' does not exist")
            elif subcommand == "test":
                if self.__debug_mode == False:
                    print("'module test' can only be used in debug mode")
                elif not len(options) == 2:
                    print("Enter a module and vulnerability to test")
                else:
                    module = options[0]
                    vuln = options[1]

                    if module_util.module_exists(module):
                        module_obj = module_util.import_module(module)

                        if vuln in module_obj.full_vulnerability_list():
                            result = module_obj.test(vuln)
                            if result == False:
                                print("Test failed")
                            else:
                                print("Test succeeded")
                        else:
                            print("Module '" + module +
                                  "' does not have the vulnerability '" +
                                  vuln + "'")
                    else:
                        print("Module '" + module + "' does not exist")
            else:
                print("module: invalid subcommand '" + subcommand + "'")
def test_module_exists():

	assert module_util.module_exists("test_module")
Esempio n. 7
0
	def __module(self, options):
		
		if len(options) == 0:
			print("Incomplete command")
			print("Valid sub-commands: add, remove, info, list, random, force, test")
		else:
			subcommand = options[0]
			del options[0]
			
			if subcommand == "add":
				
				if not len(options) == 1:
					print("module add: No module name")
				else:
					module_name = options[0]
					
					if module_util.module_exists(module_name):
						if not module_name in self.__vars['to_run']['value']:
							self.__vars['to_run']['value'].append(module_name)
							print("Module added")
						else:
							print("Module is already set to be run")
					else:
						print("Module '" + module_name + "' does not exist")
			elif subcommand == "random":	
				rand_list = []
				self.__vars['to_run']['value'] = []
				
				while len(rand_list) == 0:
				
					mod_list = module_util.get_module_list()
					
					set_level = self.__vars['level']['value']
					
					for module in mod_list:
						# Skip the test module
						if module == "test_module":
							continue
						
						mod_obj = module_util.import_module(module)
						
						if mod_obj:
							if set_level == "any":
								if ba_random().will_do():
									rand_list.append(module)
							else: 
								if mod_obj.has_difficulty(set_level) and ba_random().will_do():
									rand_list.append(module)
						else:
							print("Could not import module "+ module)
						
					
				for module_name in rand_list:
					self.__vars['to_run']['value'].append(module_name)		
						
			elif subcommand == "remove":
				if not len(options) == 1:
					print("module add: No module set")
				else:
					module_name = options[0]
					
					if module_util.module_exists(module_name):
						if module_name in self.__vars['to_run']['value']:
							self.__vars['to_run']['value'].remove(module_name)
							print("Module removed")
						else:
							print("Module is not set to run")
					else:
						print("Module '" + module_name + "' does not exist")			
			elif subcommand == "info":
				
				if not len(options) == 1:
					print("module info: No module name")
				else:
					module_name = options[0]
					
					if module_util.module_exists(module_name):
						tmp_module = module_util.import_module(module_name)
						print(tmp_module.info())
						
						print("Vulnerabilities:")
						for vuln in tmp_module.full_vulnerability_list():
							print("    " + vuln)
							
					else:
						print("Module '" + module_name + "' does not exist")	
			elif subcommand == "list":
				module_list = module_util.get_module_list()
				
				if len(module_list) > 0:
					for item in module_list:
						if item == "test_module":
							continue
						if item in self.__vars['to_run']['value']:
							print("\t+ " + item)
						else:
							print("\t- " + item)
				else:
					print("\nNo modules are set to run!")
			elif subcommand == "force":
				if not len(options) == 2:
					print("Enter a module and vulnerability to force")
				else:
					module = options[0]
					vuln = options[1]
					
					if module_util.module_exists(module):
						if vuln in module_util.import_module(module).full_vulnerability_list():
							if not module in self.__vars['force']['value']:
								self.__vars['force']['value'][module] = []
							
							if not vuln in self.__vars['force']['value'][module]:
								self.__vars['force']['value'][module].append(vuln)
							else:
								print("That vulnerability is already being forced")
						else:
							print("Module '" + module + "' does not have the vulnerability '" + vuln + "'")
					else:
						print("Module '" + module + "' does not exist")
			elif subcommand == "test":
				if self.__debug_mode == False:
					print("'module test' can only be used in debug mode")
				elif not len(options) == 2:
					print("Enter a module and vulnerability to test")
				else:
					module = options[0]
					vuln = options[1]
					
					if module_util.module_exists(module):
						module_obj = module_util.import_module(module)
						
						if vuln in module_obj.full_vulnerability_list():
							result = module_obj.test(vuln)
							if result == False:
								print("Test failed")
							else:
								print("Test succeeded")
						else:
							print("Module '" + module + "' does not have the vulnerability '" + vuln + "'")
					else:
						print("Module '" + module + "' does not exist")
			else:
				print("module: invalid subcommand '" + subcommand + "'")
Esempio n. 8
0
def test_module_exists():

    assert module_util.module_exists("test_module")