Пример #1
0
 def __new__(cls, engine):
     configFile = os.path.join("plugin","config","searchengine.yaml")
     try:
         with open(configFile, "r") as fd:
             config = yaml.load(fd)[engine]
     except IOError:
         raise SearchEngineError("read searchengine configuration file 'searchengine.yaml' failed")
     else:
         return config
Пример #2
0
 def __new__(cls, engine):
     configFile = os.path.join(sys.path[0], "script", "data", "search_engine.yaml")
     try:
         with open(configFile, "r") as _file:
             config = yaml.load(_file)[engine]
     except IOError:
         raise SearchEngineError("read searchengine configuration file 'searchengine.yaml' failed")
     else:
         return config
Пример #3
0
    def __init__(self, log=True):
        super(SubnetScanPlugin, self).__init__(log=log)

        try:
            with open(os.path.join("plugin","config","portmapping.yaml"), "r") as fd:
                self.portDict = yaml.load(fd)
        except IOError:
            raise PluginError("cannot load portmapping configure file 'portmapping.yaml'")
        self.portList = [key for key in self.portDict]
Пример #4
0
 def __new__(cls, engine):
     configFile = os.path.join("plugin", "config", "searchengine.yaml")
     try:
         with open(configFile, "r") as fd:
             config = yaml.load(fd)[engine]
     except IOError:
         raise SearchEngineError(
             "read searchengine configuration file 'searchengine.yaml' failed"
         )
     else:
         return config
Пример #5
0
    def __init__(self, log=True):
        super(SubnetScanPlugin, self).__init__(log=log)

        try:
            with open(os.path.join("plugin", "config", "portmapping.yaml"),
                      "r") as fd:
                self.portDict = yaml.load(fd)
        except IOError:
            raise PluginError(
                "cannot load portmapping configure file 'portmapping.yaml'")
        self.portList = [key for key in self.portDict]
 def __new__(cls, engine):
     configFile = "search_engine.yaml"
     try:
         with open(configFile, "r") as _file:
             config = yaml.load(_file)[engine]
     except IOError:
         raise SearchEngineError(
             "read searchengine configuration file 'searchengine.yaml' failed"
         )
     else:
         return config
Пример #7
0
    def __new__(cls, path):
        try:
            _file = open(path,"r")
            result = yaml.load(_file)
        except IOError:
            raise PenError("Loading yaml file '{0}' failed, read file failed".format(path))
        except yaml.YAMLError as error:
            raise PenError("Loading yaml file '{0}' failed, yaml error, reason: '{1}'".format(path,str(error)))
        except Exception as error:
            raise PenError("Loading yaml file '{0}' failed, reason: {1}".format(path,str(error)))

        return result
Пример #8
0
 def __new__(cls, engine):
     configFile = os.path.join(sys.path[0], "script", "data",
                               "search_engine.yaml")
     try:
         with open(configFile, "r") as _file:
             config = yaml.load(_file)[engine]
     except IOError:
         raise SearchEngineError(
             "read searchengine configuration file 'searchengine.yaml' failed"
         )
     else:
         return config
Пример #9
0
    def __new__(cls, path):
        try:
            _file = open(path,"r")
            result = yaml.load(_file)
        except IOError:
            raise PenError("Loading yaml file '{0}' failed, read file failed".format(path))
        except yaml.YAMLError as error:
            raise PenError("Loading yaml file '{0}' failed, yaml error, reason: '{1}'".format(path,str(error)))
        except Exception as error:
            raise PenError("Loading yaml file '{0}' failed, reason: {1}".format(path,str(error)))

        return result
Пример #10
0
    def __new__(cls):
        configFile = os.path.join("plugin","config","useragent.yaml")
        try:
            with open(configFile, "r") as fd:
                config = yaml.load(fd)
        except IOError:
            userAgents = ["Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
                "Mozilla/5.0 (Windows; U; Windows NT 5.2)Gecko/2008070208 Firefox/3.0.1",
                "Opera/9.27 (Windows NT 5.2; U; zh-cn)",
                "Mozilla/5.0 (Macintosh; PPC Mac OS X; U; en)Opera 8.0)"]
        else:
            userAgents = [x['User-Agent'] for x in config]

        return userAgents
Пример #11
0
def yaml2object(filename):
	"""
	parse yaml file to python object
	>>> yaml2object(config.yaml)
	'{logger:{file:'xxx.log',level:'3',verbose:Fasle}}'
	"""
	try:
		fp = codecs.open(filename, "rb", UNICODE_ENCODING)
		yaml_object = yaml.load(fp)
		fp.close()
	except Exception,e:
		yaml_object = None
		err_msg = "incorrect format of yaml file:%s" %filename
		logger.error(err_msg)
Пример #12
0
    def __new__(cls):
        configFile = os.path.join("plugin", "config", "useragent.yaml")
        try:
            with open(configFile, "r") as fd:
                config = yaml.load(fd)
        except IOError:
            userAgents = [
                "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
                "Mozilla/5.0 (Windows; U; Windows NT 5.2)Gecko/2008070208 Firefox/3.0.1",
                "Opera/9.27 (Windows NT 5.2; U; zh-cn)",
                "Mozilla/5.0 (Macintosh; PPC Mac OS X; U; en)Opera 8.0)"
            ]
        else:
            userAgents = [x['User-Agent'] for x in config]

        return userAgents
Пример #13
0
    def __init__(self):
        confFile = self._confFile
        if not os.path.exists(confFile):
            confFile = os.path.join("data","config.sample.yaml")
            if not os.path.exists(confFile):
                raise WIPError("cannot find configure file, 'config.yaml' or 'config.sample.yaml'")

        try:
            with open(confFile,'r') as fd:
                confDict = yaml.load(fd)
        except IOError:
            raise WIPError("open configure file '{0}' error".format(confFile))
        except yaml.scanner.ScannerError:
            raise WIPError("configure file '{0}' format error, should be yaml format".format(confFile))

        for key,value in confDict.iteritems():
            if isinstance(value, dict):
                confDict[key] = Dict(**value)

        super(Config,self).__init__(**confDict)
Пример #14
0
 def get_available_plugins(cls):
     """
     返回plugins目录下所有enable为true的plugin名称
     """
     plugin_list = os.listdir(paths.PLUGINS_PATH)
     for plugin in plugin_list:
         plugin_config_path = os.path.join(paths.PLUGINS_PATH, plugin,
                                           'config.yaml')
         if os.path.exists(plugin_config_path):
             with open(plugin_config_path) as f:
                 try:
                     plugin_config = yaml.load(f)
                 except Exception:
                     api.logger.exception('load %s\'s config fail!' %
                                          plugin)
                 else:
                     if plugin_config['enable']:
                         # 在conf中载入plugin的配置信息
                         conf.plugins_available[plugin] = plugin_config
     return conf.plugins_available
Пример #15
0
 def get_available_plugins(cls):
     """
     返回plugins目录下所有enable为true的plugin名称
     """
     plugin_list = os.listdir(paths.PLUGINS_PATH)
     for plugin in plugin_list:
         plugin_config_path = os.path.join(
             paths.PLUGINS_PATH, plugin, 'config.yaml'
         )
         if os.path.exists(plugin_config_path):
             with open(plugin_config_path) as f:
                 try:
                     plugin_config = yaml.load(f)
                 except Exception:
                     api.logger.exception('load %s\'s config fail!' % plugin)
                 else:
                     if plugin_config['enable']:
                         # 在conf中载入plugin的配置信息
                         conf.plugins_available[plugin] = plugin_config
     return conf.plugins_available
Пример #16
0
    def __init__(self, ptype=0, **kwargs):
        try:
            with open(os.path.join("plugin", "config", "portmapping.yaml"),
                      "r") as fd:
                self.portDict = yaml.load(fd)
        except IOError:
            raise PluginError(
                "cannot load portmapping configure file 'portmapping.yaml'")

        if ptype == 1:
            self.cmd = ""
        elif ptype == 2:
            self.cmd = "nmap -n -Pn -oX - "
        elif ptype == 3:
            self.cmd = "nmap -n -Pn -p1-65535 -oX - "
        else:
            portList = [key for key in self.portDict]
            portStr = ",".join([str(x) for x in portList])
            self.cmd = "nmap -n -Pn -p{ports} -oX - ".format(ports=portStr)

        self.type = ptype
        self.host = Dict(**kwargs)
        #requests.packages.urllib3.disable_warnings()
        self.httpTimeout = CONF.http.timeout