Example #1
0
  def print_tool(self, opts):
    """ print tool and a description of it """

    tools = []

    m = Module(MOD_PATH)
    m.get_docstrings()

    if 'all' in opts.keys():
      for tool in m.docstrings.keys():
        tools.append(tool)
    else:
      for moddir, module in opts.items():
        if module:
          for mod in module:
            for tool in m.docstrings:
              if m.docstrings[tool]['moddir'] == moddir and \
                m.docstrings[tool]['module'] == mod:
                  tools.append(tool)
        else:
          for k, v in m.docstrings.items():
            if moddir in v['moddir']:
              tools.append(k)

    tools = sorted(list(set(tools)))
    for tool in tools:
      self.log(m.docstrings[tool]['moddir'] + '/' +
        m.docstrings[tool]['module'] + '/' + tool + ' - ' +
        m.docstrings[tool]['descr'], end='\n', _type='vmsg')

    return
Example #2
0
    def check_tools(self):
        """ check for missing tools on the system (-C) """

        tools = []
        missing_tools = []
        found_files = []
        suffixes = ('', '.py', '.pl', '.rb', '.php', '.jar', '.sh', '.bin',
                    '.exe')

        # get docstrings
        m = Module(MOD_PATH)
        m.get_docstrings()

        # get paths from PATH to search for tools
        paths = list(filter(None, os.environ.get('PATH').split(':')))
        paths.extend(['/opt', '/usr/share'])

        # search for files in given paths and unique+append them
        for rootdir in paths:
            for root, dirs, files in os.walk(rootdir):
                if 'nmap/scripts/vulscan' in root:
                    files.append('vulscan')
                found_files.append(files)
        found_files = list(set(itertools.chain.from_iterable(found_files)))

        # get defined tools list out of doscstrings
        for key in m.docstrings.keys():
            for tool in m.docstrings[key]['tools']:
                if tool not in tools:
                    tools.append(tool)

        # message if not found
        for tool in tools:
            for suffix in suffixes:
                if '.' in tool:
                    tool = tool.split('.')[0]
                if tool + suffix in found_files:
                    break
            else:
                self.log(f'{tool} not found\n', _type='vmsg')
                missing_tools.append(tool)

        # one-liner for parsing
        if len(missing_tools) > 0:
            self.log('\n')
            self.log('One-liner for parsing\n\n', _type='msg')
            self.log(f"    {' '.join(missing_tools)}\n")
        else:
            self.log('All tools are available\n', _type='msg')

        return