def test_os_not_match():
	data = os_data.os_info()

	if platform.system() == 'Linux':
		
		just_linux = os_data.os_match('linux')
		
		assert data.matches(just_linux) == True
		
		plat_data = platform.linux_distribution()
		
		if 'ubuntu' in plat_data[0].lower():
			
			ubuntu_match = os_data.os_match('linux', 'centos')
			
			assert data.matches(ubuntu_match) == False
			
			ubuntu_match = os_data.os_match('linux', 'ubuntu', "<" + plat_data[1]) 
			
			assert data.matches(ubuntu_match) == False
			
		elif 'centos' in plat_data[0].lower():
			
			centos_match = os_data.os_match('linux', 'ubuntu')
			assert data.matches(centos_match) == False
			centos_match = os_data.os_match('linux', 'centos', "<" + plat_data[1])
			assert data.matches(centos_match) == False
def test_os_not_match():
    data = os_data.os_info()

    if platform.system() == 'Linux':

        just_linux = os_data.os_match('linux')

        assert data.matches(just_linux) == True

        plat_data = platform.linux_distribution()

        if 'ubuntu' in plat_data[0].lower():

            ubuntu_match = os_data.os_match('linux', 'centos')

            assert data.matches(ubuntu_match) == False

            ubuntu_match = os_data.os_match('linux', 'ubuntu',
                                            "<" + plat_data[1])

            assert data.matches(ubuntu_match) == False

        elif 'centos' in plat_data[0].lower():

            centos_match = os_data.os_match('linux', 'ubuntu')
            assert data.matches(centos_match) == False
            centos_match = os_data.os_match('linux', 'centos',
                                            "<" + plat_data[1])
            assert data.matches(centos_match) == False
Beispiel #3
0
def test_get_network():
	test_obj = networking()
	if os_data.os_info().matches(os_data.os_match('linux')):
		value = test_obj.get_networks("lo")
		assert value[0] == "127.0.0.0"
		assert value[1] == "0:0:0:0:0:0:0:1"
		value = test_obj.get_networks("eth0")
Beispiel #4
0
	def check_os_support(self):
		system_info = os_data.os_info()
		if len(self.__supported_os_list) == 0:
			return True

		for supported_os in self.__supported_os_list:
			if system_info.matches(supported_os):
				return True
		return False
Beispiel #5
0
    def check_os_support(self):
        system_info = os_data.os_info()
        if len(self.__supported_os_list) == 0:
            return True

        for supported_os in self.__supported_os_list:
            if system_info.matches(supported_os):
                return True
        return False
def test_get_package_manager():
	test = simple_packages()
	my_os = os_data.os_info()
	
	ubuntu_match = os_data.os_match('linux', 'ubuntu')
	centos_match = os_data.os_match('linux', 'centos')
	
	if my_os.matches(ubuntu_match):
		assert test.get_package_manager() == "apt"
	elif my_os.matches(centos_match):
		assert test.get_package_manager() == "yum"
def test_os_info_obj():

    data = os_data.os_info()

    if platform.system() == 'Linux':
        assert data.os_type() == 'linux'

        plat_data = platform.linux_distribution()

        if 'ubuntu' in plat_data[0].lower():
            assert data.flavor() == 'ubuntu'
            assert data.version() == plat_data[1]
        elif 'centos' in plat_data[0].lower():
            assert data.flavor() == 'centos'
            assert data.version() == plat_data[1]
def test_os_info_obj():

	data = os_data.os_info()

	if platform.system() == 'Linux':
		assert data.os_type() == 'linux'

		plat_data = platform.linux_distribution()
		
		if 'ubuntu' in plat_data[0].lower():
			assert data.flavor() == 'ubuntu'
			assert data.version() == plat_data[1]
		elif 'centos' in plat_data[0].lower():
			assert data.flavor() == 'centos'
			assert data.version() == plat_data[1]
def test_version_restriction_os():
    test_obj = module_util.import_module("test_module")

    vuln = test_obj.new_vulnerability("Restrict_Test_OS", "Test", "restrict", "1.0.0")

    test_obj.add_vulnerability(vuln)

    assert len(test_obj.get_vulnerabilities(force=True)) == 1

    if os_data.os_info().matches(os_data.os_match("linux", "ubuntu")):
        vuln.add_supported_os("linux", "centos")
    else:
        vuln.add_supported_os("linux", "ubuntu")

    assert len(test_obj.get_vulnerabilities(force=True)) == 0
Beispiel #10
0
def test_version_restriction_os():
    test_obj = module_util.import_module('test_module')

    vuln = test_obj.new_vulnerability("Restrict_Test_OS", "Test", "restrict",
                                      "1.0.0")

    test_obj.add_vulnerability(vuln)

    assert len(test_obj.get_vulnerabilities(force=True)) == 1

    if os_data.os_info().matches(os_data.os_match('linux', 'ubuntu')):
        vuln.add_supported_os('linux', 'centos')
    else:
        vuln.add_supported_os('linux', 'ubuntu')

    assert len(test_obj.get_vulnerabilities(force=True)) == 0
Beispiel #11
0
def test_get_addresses():
	test_obj = networking()
	if os_data.os_info().matches(os_data.os_match('linux')):
		value = test_obj.get_addresses("lo")
		assert 'mac' in value
		assert 'ipv4' in value
		assert 'ipv6' in value
		
		assert value['mac']['address'] == "00:00:00:00:00:00"
		assert value['mac']['broadcast'] == "00:00:00:00:00:00"
		
		assert value['ipv4']['address'] == "127.0.0.1"
		assert value['ipv4']['mask'] == "8"
		
		assert value['ipv6']['address'] == "::1"
		assert value['ipv6']['mask'] == "128"
Beispiel #12
0
    def __init__(self):
        current_system = os_data.os_info()

        if not current_system.os_type() == 'linux':
            print(NAME + " can currently only be run on Linux")

        if not os.geteuid() == 0:
            print("\nYou need to be root to run " + NAME)
            sys.exit()

        self.__running = True
        self.__debug_mode = False

        self.__vars = {
            "to_run": {
                "type": "list",
                "value": [],
                "description": "Modules to be run"
            },
            "base64": {
                "type": "bool",
                "value": True,
                "description": "Sets if module output is Base64 encoded"
            },
            "verbose": {
                "type": "bool",
                "value": False,
                "description": "Sets if BadAdmin should be verbose"
            },
            "force": {
                "type":
                "map",
                "value": {},
                "description":
                "Maps a module to vulnerabilities that will be forced to be run"
            },
            "level": {
                "type": "string",
                "value": 'any',
                "description":
                "Sets a limit to the difficulty level of modules",
                "limit": ['easy', 'medium', 'hard', 'any']
            }
        }
Beispiel #13
0
	def __init__(self):
		current_system = os_data.os_info()
		
		if not current_system.os_type() == 'linux':
			print(NAME + " can currently only be run on Linux")
		
		if not os.geteuid() == 0:
			print ("\nYou need to be root to run " + NAME)
			sys.exit()
		
		self.__running = True
		self.__debug_mode = False
		
		self.__vars = {
			"to_run": {"type": "list", "value": [], "description": "Modules to be run"},
			"base64": {"type": "bool", "value": True, "description": "Sets if module output is Base64 encoded"},
			"verbose": {"type": "bool", "value": False, "description": "Sets if BadAdmin should be verbose"},
			"force": {"type": "map", "value": {}, "description": "Maps a module to vulnerabilities that will be forced to be run"},
			"level": {"type": "string", "value": 'any', "description": "Sets a limit to the difficulty level of modules", "limit": ['easy', 'medium', 'hard', 'any']}
		}
Beispiel #14
0
def test_available_ports():
	test_obj = networking()
	
	port_list = []
	
	if os_data.os_info().matches(os_data.os_match('linux')):
		code, output, error = simple_command().run('netstat -tunap | grep LISTEN')
		
		for line in output:
			line_list = line.split(" ")
			
			new_line = []
			
			for item in line_list:
				if item != "":
					new_line.append(item)
			
			listen_section = new_line[3]
			
			listen_split = listen_section.split(":")
			
			port = listen_split[len(listen_split) - 1]
			
			port_list.append(int(port))
	
		for port in port_list:
			assert test_obj.is_port_available(port) == False

		i = 1
		for j in range(5): 
			while i in port_list and i <= 65535:
				i += 5
			
			if i == 65535:
				assert False
			
			assert test_obj.is_port_available(i) == True
			i += 5
Beispiel #15
0
 def os_info(self):
     return os_data.os_info()
Beispiel #16
0
	def __fill(self):
		
		if os_data.os_info().matches(os_data.os_match('linux')):
			cmd = simple_command.simple_command()
			code, output, errors = cmd.run("ip addr")
			
			if code == 0:
			
				output = "\n".join(output)
				
				raw_interfaces = re.split("\n[0-9]+: ", "\n" + output)
				
				for interface in raw_interfaces:
					if interface == "":
						continue
						
					data_split = interface.split(": ")
					
					interface_name = data_split[0]
					del data_split[0]
					interface_info = ": ".join(data_split)
					
					self.__interfaces[interface_name] = {}
					info_split = interface_info.split("\n")
					for line in info_split:
						if line.startswith("  "):
							line = line.strip()
							line_split = line.split(" ")
							if line.startswith("link"):
								if len(line_split) == 4:
									
									if not 'mac' in self.__interfaces[interface_name]:
										self.__interfaces[interface_name]['mac'] = {}
									
									self.__interfaces[interface_name]['mac']['address'] = line_split[1]
									self.__interfaces[interface_name]['mac']['broadcast'] = line_split[3]
									
							elif line.startswith("inet "):
								if len(line_split) >= 4:
									ipv4_data = line_split[1]
									ip_split = ipv4_data.split("/")
									
									addr = ip_split[0]
									mask = ip_split[1]
									
									if not 'ipv4' in self.__interfaces[interface_name]:
										self.__interfaces[interface_name]['ipv4'] = {}
									
									self.__interfaces[interface_name]['ipv4']['address'] = addr
									self.__interfaces[interface_name]['ipv4']['mask'] = mask
									if "brd" in line:
										self.__interfaces[interface_name]['ipv4']['broadcast'] = line_split[3]
									
							elif line.startswith("inet6 "):
								if len(line_split) >= 4:
									ipv6_data = line_split[1]
									ip_split = ipv6_data.split("/")
									
									addr = ip_split[0]
									mask = ip_split[1]
									
									if not 'ipv6' in self.__interfaces[interface_name]:
										self.__interfaces[interface_name]['ipv6'] = {}
									
									self.__interfaces[interface_name]['ipv6']['address'] = addr
									self.__interfaces[interface_name]['ipv6']['mask'] = mask
									if "brd" in line:
										self.__interfaces[interface_name]['ipv6']['broadcast'] = line_split[3]
					
				#~ print(self.__interfaces)
			else:
				print("Error running ip addr")
		elif os_data.os_info().matches(os_data.os_match('windows')):
			pass
Beispiel #17
0
def test_get_interfaces():
	test_obj = networking()
	if os_data.os_info().matches(os_data.os_match('linux')):
		value = test_obj.get_interfaces()
		assert "lo" in value
Beispiel #18
0
	def os_info(self):
		return os_data.os_info()