Skip to content

Commit

Permalink
* Add som helper methods
Browse files Browse the repository at this point in the history
* some tiny bugfixes
  • Loading branch information
f-froehlich committed Dec 12, 2020
1 parent b435304 commit ce7f11d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
3 changes: 3 additions & 0 deletions nmap_scan/Host/HostAddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def is_ipv4(self):
def is_ipv6(self):
return 'ipv6' == self.__type

def is_ip(self):
return self.is_ipv4() or self.is_ipv6()

def is_mac(self):
return 'mac' == self.__type

Expand Down
8 changes: 4 additions & 4 deletions nmap_scan/Host/Port.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ def get_owner(self):
return self.__owner

def is_open(self):
return 'open' in self.__state
return 'open' in self.__state.get_state()

def is_filtered(self):
return 'filtered' in self.__state
return 'filtered' in self.__state.get_state()

def is_open_filtered(self):
return self.is_open() and self.is_filtered()

def is_unfiltered(self):
return 'unfiltered' in self.__state
return 'unfiltered' in self.__state.get_state()

def is_closed(self):
return 'closed' in self.__state
return 'closed' in self.__state.get_state()

def is_closed_filtered(self):
return self.is_closed() and self.is_filtered()
Expand Down
6 changes: 3 additions & 3 deletions nmap_scan/NmapArgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

class NmapArgs:

def __init__(self, hosts, num_hosts=None, exclude_hosts=[], dns_servers=[], system_dns=False, traceroute=False,
def __init__(self, hosts=[], num_hosts=None, exclude_hosts=[], dns_servers=[], system_dns=False, traceroute=False,
ports=[], exclude_ports=[], fast_mode=False, scan_consecutively=False, top_ports=None, port_ratio=None,
service_discovery=False, version_intensity=None, version_light=None, version_all=False,
version_trace=False, default_script=False, scripts=[], script_args=[], script_trace=False,
Expand Down Expand Up @@ -324,7 +324,7 @@ def get_arg_list(self):

return [str(a) for a in args]

def add_cli_args(self, argpaser=None):
def add_args(self, argpaser=None):

if None == argpaser:
argpaser = argparse.ArgumentParser(description='Nmap scan with python')
Expand Down Expand Up @@ -415,7 +415,7 @@ def add_cli_args(self, argpaser=None):
self.__add_boolean_arg(argpaser, '--unprivileged', 'Assume the user lacks raw socket privilegesd',
self.__unprivileged)

def parse_args(self, args=None):
def configure(self, args=None):
if None == args:
if None == self.__argpaser:
raise LogicException('You must call NmapArgs.add_cli_args() first')
Expand Down
68 changes: 46 additions & 22 deletions nmap_scan/Scripts/SSLEnumCiphers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SSLEnumCiphers(Script):
def __init__(self, xml):
Script.__init__(self, xml)
self.__xml = xml
self.__protocols = []
self.__protocols = {}
self.__least_strength = None
self.__parse_xml()

Expand All @@ -48,6 +48,9 @@ def get_xml(self):
def get_protocols(self):
return self.__protocols

def get_protocol(self, version):
return self.__protocols.get(version, None)

def get_least_strength(self):
return self.__least_strength

Expand All @@ -58,7 +61,7 @@ def __parse_xml(self):

xml_tables = self.__xml.findall('table')
for xml_table in xml_tables:
self.__protocols.append(SSLEnumCiphersProtocol(xml_table))
self.__protocols[xml_table.attrib['key'].lower()] = SSLEnumCiphersProtocol(xml_table)

for xml_elements in self.__xml.findall('elem'):
if 'least strength' == xml_elements.attrib['key']:
Expand Down Expand Up @@ -147,9 +150,46 @@ def is_worse_than(self, cipher):

def is_worse_than_strength(self, strength):

return self.map_strength(self.__strength) > self.map_strength(strength)
return CipherCompare.a_lower_b(self.__strength, strength)

def __parse_xml(self):
if None == self.__xml:
raise LogicException('No valid xml is set.')
logging.info('Parsing SSLEnumCiphersCiphers')

for xml_element in self.__xml.findall('elem'):
key = xml_element.attrib['key']
if 'strength' == key:
self.__strength = xml_element.text
elif 'name' == key:
self.__name = xml_element.text
elif 'kex_info' == key:
self.__key_info = xml_element.text

logging.debug('Cipher: "{name}" ({key_info}) - "{strength}"'.format(name=self.__name, strength=self.__strength,
key_info=self.__key_info))


class CipherCompare:

@staticmethod
def a_lower_b(a, b):
return CipherCompare.map_strength(a) < CipherCompare.map_strength(b)

def map_strength(self, strength):
@staticmethod
def a_lower_equals_b(a, b):
return CipherCompare.map_strength(a) <= CipherCompare.map_strength(b)

@staticmethod
def a_grater_b(a, b):
return CipherCompare.map_strength(a) > CipherCompare.map_strength(b)

@staticmethod
def a_grater_equals_b(a, b):
return CipherCompare.map_strength(a) >= CipherCompare.map_strength(b)

@staticmethod
def map_strength(strength):
logging.debug('Map strength "{strength}"'.format(strength=strength))
all_strength = {
'A': 1,
Expand All @@ -167,7 +207,8 @@ def map_strength(self, strength):

return mapped_strength

def reverse_map_strength(self, strength):
@staticmethod
def reverse_map_strength(strength):
logging.debug('Reverse map strength "{strength}"'.format(strength=strength))
all_strength = {
1: 'A',
Expand All @@ -184,20 +225,3 @@ def reverse_map_strength(self, strength):
raise LogicException('Invalid strength "{strength}" detected. Must be A-F'.format(strength=strength))

return mapped_strength

def __parse_xml(self):
if None == self.__xml:
raise LogicException('No valid xml is set.')
logging.info('Parsing SSLEnumCiphersCiphers')

for xml_element in self.__xml.findall('elem'):
key = xml_element.attrib['key']
if 'strength' == key:
self.__strength = xml_element.text
elif 'name' == key:
self.__name = xml_element.text
elif 'kex_info' == key:
self.__key_info = xml_element.text

logging.debug('Cipher: "{name}" ({key_info}) - "{strength}"'.format(name=self.__name, strength=self.__strength,
key_info=self.__key_info))
2 changes: 1 addition & 1 deletion nmap_scan/Scripts/Script.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def __parse_xml(self):
logging.info('Parsing Script')
attr = self.__xml.attrib
self.__id = attr['id']
self.__output = attr['output']
self.__output = attr.get('output', None)
logging.debug('ID: "{name}"'.format(name=self.__id))
logging.debug('Output: "{output}"'.format(output=self.__output))

0 comments on commit ce7f11d

Please sign in to comment.