def __fill_sections(self, root_node):
     groups = root_node.getElementsByTagName("groups")[0].getElementsByTagName("group")
     nmapOptions = NmapOptions(Path.options)
     for group in groups:
         name = group.getAttribute("name")
         element = root_node.getElementsByTagName(name)[0]
         dic = {}
         dic[name] = dict(label=element.getAttribute("label"), options=[])
         
         for node in element.childNodes:
             if node.__class__ is minidom.Element:
                 option = dict(label=node.getAttribute("label"))
                 if node.tagName == "option_list":
                     option["type"] = "list"
                     option["options"] = []
                     for opt in node.childNodes:
                         if opt.__class__ == minidom.Element:
                             option_name = opt.getAttribute("name").replace("'", "\\'")
                             x = {"name": option_name, "command": nmapOptions.get_option(option_name)['option']}
                             option["options"].append(x)
                 elif node.tagName == "option_check":
                     option["type"] = "check"
                     option["option"] = node.getAttribute("option")
                     option["command"] = nmapOptions.get_option(node.getAttribute("option"))["option"]
                     if node.getAttribute("arg_type"):
                         option["arg_type"] = node.getAttribute("arg_type")
                 dic[name]['options'].append(option)
         self.sections.append(dic)
Exemplo n.º 2
0
def get_options(req):
    options = NmapOptions(Path.options)
    opt_list = [options.get_option(id) for id in options.get_options_list() \
            if req.POST.get("search", "").lower() in id.lower()]
    str_opt = []
    for option in opt_list:
        data = ["'%s': '%s'" % item for item in option.items()]
        str_opt.append("{%s}" % ",".join(data))
    return HttpResponse("[%s]" % ",".join(str_opt))
Exemplo n.º 3
0
def get_options(req):
    options = NmapOptions(Path.options)
    opt_list = [options.get_option(id) for id in options.get_options_list() \
            if req.POST.get("search", "").lower() in id.lower()]
    str_opt = []
    for option in opt_list:
        data = ["'%s': '%s'" % item for item in option.items()]
        str_opt.append("{%s}" % ",".join(data))
    return HttpResponse("[%s]" % ",".join(str_opt))
Exemplo n.º 4
0
    def __fill_sections(self, root_node):
        groups = root_node.getElementsByTagName(
            "groups")[0].getElementsByTagName("group")
        nmapOptions = NmapOptions(Path.options)
        for group in groups:
            name = group.getAttribute("name")
            element = root_node.getElementsByTagName(name)[0]
            dic = {}
            dic[name] = dict(label=element.getAttribute("label"), options=[])

            for node in element.childNodes:
                if node.__class__ is minidom.Element:
                    option = dict(label=node.getAttribute("label"))
                    if node.tagName == "option_list":
                        option["type"] = "list"
                        option["options"] = []
                        for opt in node.childNodes:
                            if opt.__class__ == minidom.Element:
                                option_name = opt.getAttribute("name").replace(
                                    "'", "\\'")
                                x = {
                                    "name":
                                    option_name,
                                    "command":
                                    nmapOptions.get_option(option_name)
                                    ['option']
                                }
                                option["options"].append(x)
                    elif node.tagName == "option_check":
                        option["type"] = "check"
                        option["option"] = node.getAttribute("option")
                        option["command"] = nmapOptions.get_option(
                            node.getAttribute("option"))["option"]
                        if node.getAttribute("arg_type"):
                            option["arg_type"] = node.getAttribute("arg_type")
                    dic[name]['options'].append(option)
            self.sections.append(dic)
class CommandConstructor:
    def __init__(self, options = {}):
        self.options = {}
        self.option_profile = NmapOptions(options_file)
        for k, v in options.items():
            self.add_option(k, v, False) # TODO: check this place further

    def add_option(self, option_name, args=[], level=False):
        if (not option_name) or \
           (option_name == "None" and not args and not level):
            # this certainly shouldn't be added
            return
        self.options[option_name] = (args, level)
        

    def remove_option(self, option_name):
        if option_name in self.options.keys():
            self.options.pop(option_name)

    def get_command(self, target):
        splited = ['%s' % nmap_command_path]

        for option_name in self.options:
            option = self.option_profile.get_option(option_name)
            args, level = self.options[option_name]

            if type(args) in StringTypes:
                args = [args]

            if level:
                splited.append((option['option']+' ')*level)
            elif args:
                args = tuple (args)
                splited.append(option['option'] % args[0])
            else:
                splited.append(option['option'])
            
        splited.append(target)
        return ' '.join(splited)

    def get_options(self):
        return dict([(k, v[0]) for k, v in self.options.items()])
Exemplo n.º 6
0
class CommandConstructor:
    def __init__(self, options={}):
        self.options = {}
        self.option_profile = NmapOptions(options_file)
        for k, v in options.items():
            self.add_option(k, v, False)  # TODO: check this place further

    def add_option(self, option_name, args=[], level=False):
        if (not option_name) or \
           (option_name == "None" and not args and not level):
            # this certainly shouldn't be added
            return
        self.options[option_name] = (args, level)

    def remove_option(self, option_name):
        if option_name in self.options.keys():
            self.options.pop(option_name)

    def get_command(self, target):
        splited = ['%s' % nmap_command_path]

        for option_name in self.options:
            option = self.option_profile.get_option(option_name)
            args, level = self.options[option_name]

            if type(args) in StringTypes:
                args = [args]

            if level:
                splited.append((option['option'] + ' ') * level)
            elif args:
                args = tuple(args)
                splited.append(option['option'] % args[0])
            else:
                splited.append(option['option'])

        splited.append(target)
        return ' '.join(splited)

    def get_options(self):
        return dict([(k, v[0]) for k, v in self.options.items()])
Exemplo n.º 7
0
 def __init__(self, options={}):
     self.options = {}
     self.option_profile = NmapOptions(options_file)
     for k, v in options.items():
         self.add_option(k, v, False)  # TODO: check this place further
 def __init__(self, options = {}):
     self.options = {}
     self.option_profile = NmapOptions(options_file)
     for k, v in options.items():
         self.add_option(k, v, False) # TODO: check this place further