Пример #1
0
def main():
    """
    Main function of w9scan when running from command line.
    """
    checkEnvironment()  # 检测环境
    setPaths(modulePath())  # 为一些目录和文件设置了绝对路径

    parser = argparse.ArgumentParser(description="w9scan scanner")
    parser.add_argument("--update", help="update w9scan", action="store_true")
    parser.add_argument("--guide", help="w9scan to guide", action="store_true")
    parser.add_argument(
        "--banner", help="output the banner", action="store_true")
    parser.add_argument("-u", help="url")
    parser.add_argument("-p", "--plugin", help="plugins")
    parser.add_argument("-s", "--search", help="find infomation of plugin")
    parser.add_argument("--debug", help="output debug info",
                        action="store_true", default=False)
    args = parser.parse_args()

    if IS_WIN:
        winowsColorInit()
    Banner()

    try:
        configFileParser(os.path.join(paths.w9scan_ROOT_PATH, "config.conf"))
        initOption(args)
        pluginScan()
        webScan()

    except ToolkitMissingPrivileges, e:
        logger.error(e)
        systemQuit(EXIT_STATUS.ERROR_EXIT)
Пример #2
0
 def import_script_dir(self, scriptDir, store):
     """Import  scripts from a directory"""
     try:
         if scriptDir and os.path.isdir(scriptDir):
             for sname in os.listdir(scriptDir):
                 sname = os.path.join(scriptDir, sname)
                 self.import_script(sname, store)
         else:
             logger.error("script's directory error")
             systemQuit(EXIT_STATUS.ERROR_EXIT)
     except Exception:
         logger.warning("Import script dir error!")
Пример #3
0
Файл: cli.py Проект: liusn/sheep
def main():
    """
    Main function of sheep when running from command line.
    :return:
    """
    try:
        paths.SHEEP_ROOT_PATH = modulePath()
        setPaths()
        mainC = mainCmd()
        mainC.cmdloop()
    except KeyboardInterrupt:
        systemQuit(EXIT_STATUS.USER_QUIT)
    except Exception:
        systemQuit(EXIT_STATUS.ERROR_EXIT)
Пример #4
0
def main():
    """
    Main function of POC-T when running from command line.
    """
    try:
        paths.ROOT_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
        try:
            os.path.isdir(paths.ROOT_PATH)
        except UnicodeEncodeError:
            errMsg = "your system does not properly handle non-ASCII paths. "
            errMsg += "Please move the project root directory to another location"
            logger.error(errMsg)
            raise SystemExit
        setPaths()

        cmdLineOptions.update(cmdLineParser().__dict__)
        initOptions(cmdLineOptions)

        if IS_WIN:
            winowsColorInit()
        banner()

        loadModule()
        loadPayloads()

        run()

        if conf.OPEN_BROWSER:
            openBrowser()

        systemQuit(EXIT_STATUS.SYSETM_EXIT)

    except ToolkitMissingPrivileges as e:
        logger.error(e)
        systemQuit(EXIT_STATUS.ERROR_EXIT)

    except ToolkitSystemException as e:
        logger.error(e)
        systemQuit(EXIT_STATUS.ERROR_EXIT)

    except ToolkitUserQuitException:
        systemQuit(EXIT_STATUS.USER_QUIT)
    except KeyboardInterrupt:
        systemQuit(EXIT_STATUS.USER_QUIT)

    except Exception:
        print(traceback.format_exc())
        logger.warning('It seems like you reached a unhandled exception, please report it to author\'s mail:<*****@*****.**>.')
Пример #5
0
def loadModule():
    _name = conf.MODULE_NAME
    infoMsg = 'Loading custom script: %s' % _name
    logger.log(CUSTOM_LOGGING.SUCCESS, infoMsg)

    fp, pathname, description = imp.find_module(os.path.splitext(_name)[0], [paths.SCRIPT_PATH])
    try:
        th.module_obj = imp.load_module("_", fp, pathname, description)
        for each in ESSENTIAL_MODULE_METHODS:
            if not hasattr(th.module_obj, each):
                errorMsg = "Can't find essential method:'%s()' in current script,Please modify your script/PoC."
                logger.log(CUSTOM_LOGGING.ERROR, errorMsg)
                systemQuit(EXIT_STATUS.ERROR_EXIT)
    except ImportError, e:
        errorMsg = "Your current scipt [%s.py] caused this exception\n%s\n%s" \
                   % (_name, '[Error Msg]: ' + str(e), 'Maybe you can download this module from pip or easy_install')
        logger.log(CUSTOM_LOGGING.ERROR, errorMsg)
        systemQuit(EXIT_STATUS.ERROR_EXIT)
Пример #6
0
def main():
    try:
        paths.ROOT_PATH = os.path.dirname(
            os.path.dirname(os.path.realpath(__file__)))
        #得到当前py文件所在文件夹上一个文件夹目录赋值给paths.ROOT_PATH,也就是Sepia的根目录
        try:
            os.path.isdir(paths.ROOT_PATH)  #此处判断path.ROOT_PATH得到的路径编码是否正常
        except UnicodeEncodeError:  #出现编码错误就退出
            errMsg = "Your system does not properly handle non-ASCII paths. "
            errMsg += "Please move the project root directory to another location"
            logger.error(errMsg)
            raise SystemExit
        setPaths()  #设置Sepia的文件路径和目录
        banner()  #打印Sepia的logo
        '''
        print "########以下为paths字典#########"
        print paths
        '''
        #存储原始命令行选项,以备恢复
        '''
        print "########以下为原始命令行参数#########"
        print cmdLineParser().__dict__
        '''
        #cmdLineParser().__dict__获得命令行参数数据字典并赋值给cmdLineOptions字典对象
        cmdLineOptions.update(cmdLineParser().__dict__)
        initOptions(cmdLineOptions)
        '''
        print "########以下为cmdLineOption字典#########"
        print cmdLineOptions
        '''

        if IS_WIN:  #如果是Windows使用Colorama插件并初始化
            winowsColorInit()

        loadModule()  #加载poc脚本
        loadPayloads()  #配置扫描模式

        run()  #开始扫描

        systemQuit(EXIT_STATUS.SYSETM_EXIT)

    except ToolkitMissingPrivileges, e:
        logger.error(e)
        systemQuit(EXIT_STATUS.ERROR_EXIT)
Пример #7
0
def main():
    """
    Main function of POC-T when running from command line.
    """
    try:
        paths.ROOT_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
        try:
            os.path.isdir(paths.ROOT_PATH)
        except UnicodeEncodeError:
            errMsg = "your system does not properly handle non-ASCII paths. "
            errMsg += "Please move the project root directory to another location"
            logger.error(errMsg)
            raise SystemExit
        setPaths()

        cmdLineOptions.update(cmdLineParser().__dict__)
        initOptions(cmdLineOptions)

        if IS_WIN:
            winowsColorInit()
        banner()

        if conf.DEBUG:
            showDebugData()

        loadModule()
        loadPayloads()

        if conf.ENGINE is 't':
            from lib.controller.threads import ThreadsEngine
            ThreadsEngine().run()
        elif conf.ENGINE is 'c':
            from lib.controller.coroutine import CoroutineEngine
            CoroutineEngine().run()

        if conf.OPEN_BROWSER:
            openBrowser()

        systemQuit(EXIT_STATUS.SYSETM_EXIT)

    except ToolkitMissingPrivileges, e:
        logger.error(e)
        systemQuit(EXIT_STATUS.ERROR_EXIT)
Пример #8
0
def loadModule():
    _name = conf.MODULE_NAME
    infoMsg = 'Loading custom script: %s.py' % _name
    logger.log(CUSTOM_LOGGING.SUCCESS, infoMsg)

    fp, pathname, description = imp.find_module(_name, [paths.SCRIPT_PATH])
    try:
        th.module_obj = imp.load_module("_", fp, pathname, description)
        for each in ESSENTIAL_MODULE_METHODS:
            if not hasattr(th.module_obj, each):
                errorMsg = "Can't find essential method:'%s()' in current script:'module/%s.py'\n%s" \
                           % (each, _name, 'Please modify your script/PoC.')
                logger.log(CUSTOM_LOGGING.ERROR, errorMsg)
                systemQuit(EXIT_STATUS.ERROR_EXIT)
    except ImportError, e:
        errorMsg = "Your current scipt [%s.py] caused this exception\n%s\n%s" \
                   % (_name, '[Error Msg]: ' + str(e), 'Maybe you can download this module from pip or easy_install')
        logger.log(CUSTOM_LOGGING.ERROR, errorMsg)
        systemQuit(EXIT_STATUS.ERROR_EXIT)
Пример #9
0
def main():
    """
    Main function of POC-T when running from command line.
    """
    try:
        paths['ROOT_PATH'] = os.path.dirname(
            os.path.dirname(os.path.realpath(__file__)))
        try:
            os.path.isdir(paths['ROOT_PATH'])
        except UnicodeEncodeError:
            errMsg = "your system does not properly handle non-ASCII paths. "
            errMsg += "Please move the project root directory to another location"
            logger.error(errMsg)
            raise SystemExit
        setPaths()

        parseArgs()

        if IS_WIN:
            winowsColorInit()
        banner()

        if conf['DEBUG']:
            showDebugData()

        loadModule()
        loadPayloads()

        if conf['ENGINE'] is 't':
            from lib.controller.threads import ThreadsEngine
            ThreadsEngine().run()
        elif conf['ENGINE'] is 'c':
            from lib.controller.coroutine import CoroutineEngine
            CoroutineEngine().run()

        if conf['OPEN_BROWSER']:
            openBrowser()

        systemQuit(EXIT_STATUS.SYSETM_EXIT)

    except KeyboardInterrupt, e:
        systemQuit(EXIT_STATUS.USER_QUIT)
Пример #10
0
def main():
    """
    Main function of POC-T when running from command line.
    """
    try:
        paths['ROOT_PATH'] = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
        try:
            os.path.isdir(paths['ROOT_PATH'])
        except UnicodeEncodeError:
            errMsg = "your system does not properly handle non-ASCII paths. "
            errMsg += "Please move the project root directory to another location"
            logger.error(errMsg)
            raise SystemExit
        setPaths()

        parseArgs()

        if IS_WIN:
            winowsColorInit()
        banner()

        if conf['DEBUG']:
            showDebugData()

        loadModule()
        loadPayloads()

        if conf['ENGINE'] is 't':
            from lib.controller.threads import ThreadsEngine
            ThreadsEngine().run()
        elif conf['ENGINE'] is 'c':
            from lib.controller.coroutine import CoroutineEngine
            CoroutineEngine().run()

        if conf['OPEN_BROWSER']:
            openBrowser()

        systemQuit(EXIT_STATUS.SYSETM_EXIT)

    except KeyboardInterrupt, e:
        systemQuit(EXIT_STATUS.USER_QUIT)
Пример #11
0
def main():
    """
    Main function of POC-T when running from command line.
    """
    try:
        paths.ROOT_PATH = os.path.dirname(
            os.path.dirname(os.path.realpath(__file__)))
        try:
            os.path.isdir(paths.ROOT_PATH)
        except UnicodeEncodeError:
            errMsg = "your system does not properly handle non-ASCII paths. "
            errMsg += "Please move the project root directory to another location"
            logger.error(errMsg)
            raise SystemExit
        # 设置全局路径paths
        setPaths()
        # 解析參數到cmdLineOptions字典
        cmdLineOptions.update(cmdLineParser().__dict__)
        initOptions(cmdLineOptions)

        if IS_WIN:
            winowsColorInit()
        banner()
        # 遍历所有conf.MODULE_USE,根据模块名动态加载到conf.MODULE_PLUGIN字典
        loadModule(cmdLineOptions.script_name, cmdLineOptions.batch)
        # 加载target到队列
        loadPayloads()
        # 多线程运行
        run()

        if conf.OPEN_BROWSER:
            openBrowser()

        systemQuit(EXIT_STATUS.SYSETM_EXIT)

    except ToolkitMissingPrivileges, e:
        logger.error(e)
        systemQuit(EXIT_STATUS.ERROR_EXIT)
Пример #12
0
def _initial():
    z = ZoomEye()
    token_path = os.path.join(os.path.expanduser('~'), '.zoomeye-token')
    if not os.path.isfile(token_path):
        msg = 'ZoomEye API authorization failed, Please input ZoomEye Email and Password.'
        logger.log(CUSTOM_LOGGING.SUCCESS, msg)
        token = z.login()
        if token:
            open(token_path, 'w').write(token)
            msg = 'Save ZoomEye access token to: ' + token_path
            logger.log(CUSTOM_LOGGING.SUCCESS, msg)
        else:
            msg = 'Invalid ZoomEye username or password.'
            logger.log(CUSTOM_LOGGING.ERROR, msg)
            systemQuit(EXIT_STATUS.ERROR_EXIT)

    else:
        msg = 'Load ZoomEye access token from: ' + token_path
        logger.log(CUSTOM_LOGGING.SUCCESS, msg)
        z.setToken(open(token_path).read())
    try:
        info = z.resources_info()['resources']
    except TypeError:
        msg = 'Token invalid or expired, please re-run it to get a new token.'
        logger.log(CUSTOM_LOGGING.WARNING, msg)
        os.remove(token_path)
        systemQuit(EXIT_STATUS.ERROR_EXIT)

    if info:
        msg = 'Available ZoomEye search, web-search:{}, host-search:{}'.format(
            info['web-search'], info['host-search'])
        logger.log(CUSTOM_LOGGING.SYSINFO, msg)
    else:
        os.remove(token_path)
        msg = 'ZoomEye API authorization failed, Please re-run it and enter a new token.'
        logger.log(CUSTOM_LOGGING.ERROR, msg)
        systemQuit(EXIT_STATUS.ERROR_EXIT)

    return z
Пример #13
0
def _initial():
    z = ZoomEye()
    token_path = os.path.join(os.path.expanduser('~'), '.zoomeye-token')
    if not os.path.isfile(token_path):
        msg = 'ZoomEye API authorization failed, Please input ZoomEye Email and Password.'
        logger.log(CUSTOM_LOGGING.SUCCESS, msg)
        token = z.login()
        if token:
            open(token_path, 'w').write(token)
            msg = 'Save ZoomEye access token to: ' + token_path
            logger.log(CUSTOM_LOGGING.SUCCESS, msg)
        else:
            msg = 'Invalid ZoomEye username or password.'
            logger.log(CUSTOM_LOGGING.ERROR, msg)
            systemQuit(EXIT_STATUS.ERROR_EXIT)

    else:
        msg = 'Load ZoomEye access token from: ' + token_path
        logger.log(CUSTOM_LOGGING.SUCCESS, msg)
        z.setToken(open(token_path).read())
    try:
        info = z.resources_info()['resources']
    except TypeError:
        msg = 'Token invalid or expired, please re-run it to get a new token.'
        logger.log(CUSTOM_LOGGING.WARNING, msg)
        os.remove(token_path)
        systemQuit(EXIT_STATUS.ERROR_EXIT)

    if info:
        msg = 'Available ZoomEye search, web-search:{}, host-search:{}'.format(info['web-search'], info['host-search'])
        logger.log(CUSTOM_LOGGING.SYSINFO, msg)
    else:
        os.remove(token_path)
        msg = 'ZoomEye API authorization failed, Please re-run it and enter a new token.'
        logger.log(CUSTOM_LOGGING.ERROR, msg)
        systemQuit(EXIT_STATUS.ERROR_EXIT)

    return z
Пример #14
0
        loadModule()
        loadPayloads()

        if conf.ENGINE is 't':
            from lib.controller.threads import ThreadsEngine
            ThreadsEngine().run()
        elif conf.ENGINE is 'c':
            from lib.controller.coroutine import CoroutineEngine
            CoroutineEngine().run()

        if conf.OPEN_BROWSER:
            openBrowser()

        systemQuit(EXIT_STATUS.SYSETM_EXIT)

    except ToolkitMissingPrivileges, e:
        logger.error(e)
        systemQuit(EXIT_STATUS.ERROR_EXIT)
    except ToolkitSystemException, e:
        logger.error(e)
        systemQuit(EXIT_STATUS.ERROR_EXIT)

    except ToolkitUserQuitException:
        systemQuit(EXIT_STATUS.USER_QUIT)
    except KeyboardInterrupt:
        systemQuit(EXIT_STATUS.USER_QUIT)


if __name__ == "__main__":
    main()