Ejemplo n.º 1
0
 def __init__(self, irc):
     self.__parent = super(Ndoc, self)
     self.__parent.__init__(irc)
     self.ndir = self.registryValue('nmapDir')
     self.nbin = self.registryValue('nmapBin')
     self.nsrc = self.registryValue('nmapSrc')
     sys.path.append(os.path.join(self.nsrc,'ndiff'))
     from ndiff import Scan
     self.Scan = Scan
     sys.path.append(os.path.join(self.nsrc, 'zenmap'))
     from zenmapCore.ScriptMetadata import ScriptMetadata, get_script_entries
     from zenmapCore.NmapCommand import NmapCommand
     self.NmapCommand = NmapCommand
     from zenmapCore.NmapOptions import NmapOptions
     self.NmapOptions = NmapOptions
     from zenmapCore.UmitConf import PathsConfig
     paths = PathsConfig()
     paths.set_nmap_command_path(self.nbin)
     self.meta = dict( (e.filename, e) for e in get_script_entries(
         os.path.join(self.ndir, 'scripts'),
         os.path.join(self.ndir, 'nselib') )
     )
     self.libs = map(lambda x: os.path.basename(x).split('.')[0], glob.glob(os.path.join(self.ndir, 'nselib', '*.lua*')))
     if have_pytags:
         self.tags = EtagFile()
         self.tags.parse_from_file(os.path.join(self.nsrc, 'TAGS'))
     findproc = Popen("find . -type f \\( -name '*.c' -o -name '*.cc' -o -name '*.h' \\) -print0 | xargs -0 egrep -Hn " +
             "-e '(fatal|error) *\\(' " +
             "-e 'warn(ing)? *\\(' " +
             "-e 'fprintf *\\( *stderr' " +
             "-e '\\<(die|bye|loguser|report|printf) *\\(' ", cwd=self.ndir, shell=True, stdout=PIPE)
     errs, _ = findproc.communicate()
     self.errs = {}
     for line in errs.splitlines():
         m = reErr.match(line)
         if m:
             n = Node()
             n.file = m.group('file')
             n.line = m.group('line')
             n.text = m.group('text')
             for errstr in n.text.split('"')[1::2]: #simple string finder
                 if len(errstr) > 8 and reInteresting.match(errstr):
                     if errstr in self.errs:
                         self.errs[errstr].append(n)
                     else:
                         self.errs[errstr] = [n]
     #TODO: try-catch
     luaman = open(self.registryValue('luaManualTerms'),"r")
     self.luaterms = {}
     for term in map(string.strip, luaman):
         t = term.split("-")
         if t[0] == "pdf":
             self.luaterms[t[1]] = term
         else:
             self.luaterms[term] = term
     luaman.close()
     svnproc = Popen("svn info | awk '$1==\"Revision:\"{print $2}'", cwd=self.nsrc, shell=True, stdout=PIPE)
     self.svnrev, _ = svnproc.communicate()
     self.svnrev = self.svnrev.strip()
     self.lastload = datetime.utcnow()
Ejemplo n.º 2
0
import sys
import tempfile
# Prevent loading PyXML
import xml
xml.__path__ = [x for x in xml.__path__ if "_xmlplus" not in x]

import xml.sax

from zenmapCore.Name import APP_NAME
from zenmapCore.NmapParser import NmapParserSAX
from zenmapCore.UmitConf import PathsConfig
from zenmapCore.UmitLogging import log
import zenmapCore.Paths

# The [paths] configuration from zenmap.conf, used to get ndiff_command_path.
paths_config = PathsConfig()


class NdiffParseException(Exception):
    pass


def get_path():
    """Return a value for the PATH environment variable that is appropriate
    for the current platform. It will be the PATH from the environment plus
    possibly some platform-specific directories."""
    path_env = os.getenv("PATH")
    if path_env is None:
        search_paths = []
    else:
        search_paths = path_env.split(os.pathsep)
# This variable is used in the call to Popen. It determines whether the
# subprocess invocation uses the shell or not. If it is False on Unix, the nmap
# process is started with execve and a list of arguments, which is what we want.
# (Indeed it fails when shell_state = True because it tries to exec
# ['sh', '-c', 'nmap', '-v', ...], which is wrong.) So normally we would want
# shell_state = False. But if shell_state = False on Windows, a big ugly black
# shell window opens whenever a scan is run, at least under py2exe. So we define
# shell_state = True on Windows only. Windows doesn't have exec, so it runs the
# command basically the same way regardless of shell_state.
shell_state = (sys.platform == "win32")

# The path to the nmap executable as used by Popen.
# Find the value from configuation file paths nmap_command_path
# to use for the location of the nmap executable.
nmap_paths = PathsConfig()
nmap_command_path = nmap_paths.nmap_command_path

log.debug(">>> Platform: %s" % sys.platform)
log.debug(">>> Nmap command path: %s" % nmap_command_path)


def split_quoted(s):
    """Like str.split, except that no splits occur inside quoted strings, and
    quoted strings are unquoted."""
    return [
        x.replace("\"", "") for x in re.findall('((?:"[^"]*"|[^"\s]+)+)', s)
    ]


def wrap_file_in_preferred_encoding(f):