예제 #1
0
파일: proxy.py 프로젝트: westlyou/Glass
def getProxy(country, files):
    logger.info("正在获取代理IP")
    proxyDatas = getPage(country)
    logger.info("总共获取{0}条IP".format(len(proxyDatas)))
    logger.info("正在验证高质量IP")
    threads = []
    sem = threading.Semaphore(threadNum)
    try:
        for i in proxyDatas:
            types = i[0]
            host = i[1]
            port = i[2]
            sem.acquire()
            t = ProxyInfo(types, host, port, sem)
            t.setDaemon(True)
            threads.append(t)
            t.start()
        for t in threads:
            t.join()
    except KeyboardInterrupt:
        pass
    if Proxys.proxyList:
        logger.info("获取{0}条高质量IP".format(len(Proxys.proxyList)))
        for p in Proxys.proxyList:
            with open(files, 'a', encoding="utf-8") as f:
                f.write(str(p))
                f.write('\n')
    else:
        logger.error("在线获取失败")
예제 #2
0
파일: proxy.py 프로젝트: westlyou/Glass
def getPage(country):
    s = requests.Session()
    s.headers = {
        "User-Agent": random.choice(USER_AGENTS),
    }
    s.keep_alive = False
    proxyGit = "https://raw.githubusercontent.com/fate0/proxylist/master/proxy.list"
    proxyPage = "http://proxylist.fatezero.org/proxy.list"
    try:
        target = s.get(proxyGit)
    except requests.exceptions.ConnectionError:
        try:
            target = s.get(proxyPage)
        except requests.exceptions.ConnectionError:
            logger.error("网络超时,获取失败,请重新获取")
            exit(0)
    datas = target.text.split('\n')
    proxyDatas = []
    for proxy_str in datas:
        if proxy_str:
            proxy_json = json.loads(proxy_str)
            if country == "cn":
                if proxy_json['country'] == "CN":
                    host = proxy_json['host']
                    port = proxy_json['port']
                    types = proxy_json['type']
                    proxyDatas.append([types, host, port])
            else:
                host = proxy_json['host']
                port = proxy_json['port']
                types = proxy_json['type']
                proxyDatas.append([types, host, port])
    return proxyDatas
예제 #3
0
파일: option.py 프로젝트: r4b3rt/Glass
def runmod():
    if Urls.ips:
        if confs.search:
            if confs.search == "fofa":
                logger.info("调用Fofa接口中")
                fmain(Urls.ips)
            if confs.search == "eye":
                logger.info("调用Zoomeye接口中")
                zmain(Urls.ips)
            if confs.search == "qk":
                logger.info("调用Quake接口中")
                qmain(Urls.ips)
        else:
            logger.error("参数错误,e.g.(-s fofa or -s eye or -s qk)")
            exit(0)
    if Urls.url:
        mwebs()
        if WebInfos:
            ruleMain()
        else:
            logger.info("获取信息失败")
    if OutInfos:
        if confs.outputTarget:
            outMain(confs.outputTarget)
        else:
            outMain("txt")
예제 #4
0
파일: tosay.py 프로젝트: westlyou/Glass
def todaySay():
    files = os.path.join(Paths.config, 'today.json')
    if os.path.isfile(files):
        fileTamp = os.stat(files).st_mtime  # 获取文件创建时间
        timeArray = time.localtime(fileTamp)
        fileTime = time.strftime("%Y%m%d", timeArray)
        osTime = time.strftime("%Y%m%d", time.localtime())
        if fileTime != osTime:
            getpage(files)
    else:
        getpage(files)
    try:
        with open(files, 'r', encoding="utf-8") as f:
            today = json.load(f)
            content = today['data']['content']
            translation = today['data']['translation']
            author = "--- {0}".format(today['data']['author'])
        todaySays = '''
{0}

{1}

\t\t\t\t\t\t{2}
'''.format(content, translation, author)
        return todaySays
    except FileNotFoundError:
        logger.error("未找到每日一说(today.json)文件")
예제 #5
0
def version_check():
    if pyVersion < "3.7.3":
        logger.error(
            "此Python版本 ('{0}') 不兼容,成功运行Glass你必须使用版本 >= 3.7.3 (访问 ‘https://www.python.org/downloads/’)"
            .format(pyVersion))
        exit(0)

    if urlVersion > "1.25.8" and pyVersion > "3.8":
        logger.error("urllib3库版本 ('{0}') 不兼容,代理容易出错".format(urlVersion))
        logger.info('运行 (python3 -m pip install -U "urllib3==1.25.8") 进行库降低版本')
        logger.info(
            "或者运行 (python3 -m pip install -r requirements.txt) 进行全部库的安装")
        exit(0)
예제 #6
0
파일: fofa.py 프로젝트: WhiteHSBG/Glass
    def run(self):
        keywordsBs = base64.b64encode(self.ip.encode('utf-8'))
        keywordsBs = keywordsBs.decode('utf-8')
        url = "https://fofa.so/api/v1/search/all?email={0}&key={1}&qbase64={2}&full=false&fields=ip,title,port,domain,protocol,host&size={3}".format(
            self.email, self.key, keywordsBs, fofaSize)
        try:
            req = requests.Session()
            req.keep_alive = False
            req.headers = self.headers
#            if Proxys.proxyList:
#                if pyVersion < "3.8":
#                    req.proxies = {'https': '{0}'.format(
#                        random.choice(Proxys.scheme))}
#                else:
#                    req.proxies = {
#                        "https": 'https://{0}'.format(random.choice(Proxys.scheme))}
            req.mount("https://", HTTPAdapter(max_retries=2))
            target = req.get(url, timeout=10)
            lock.acquire()
            logger.info("正在检测IP: {0}".format(self.ip))
            logger.info("正在通过API获取信息...")
            datas = json.loads(target.text)
            self.ipInfo(datas['results'])
            req.close()
            lock.release()
        except requests.exceptions.ReadTimeout:
            logger.error("请求超时")
        except requests.exceptions.ConnectionError:
            logger.error("网络超时")
        except json.decoder.JSONDecodeError:
            logger.error("获取失败,请重试")
            lock.release()
        self.sem.release()
예제 #7
0
파일: zoomeye.py 프로젝트: westlyou/Glass
    def run(self):
        if "/" in self.ip:
            self.ip = "cidr:{0}".format(self.ip)
        else:
            self.ip = "ip:{0}".format(self.ip)
        url = "https://api.zoomeye.org/host/search?query={0}".format(self.ip)

        try:
            req = requests.Session()
            req.headers = self.headers
            if Proxys.proxyList:
                if pyVersion < "3.8":
                    req.proxies = {
                        'https': '{0}'.format(random.choice(Proxys.scheme))
                    }
                else:
                    req.proxies = {
                        "https":
                        'https://{0}'.format(random.choice(Proxys.scheme))
                    }
            req.mount("https://", HTTPAdapter(max_retries=2))
            target = req.get(url, timeout=10)
            lock.acquire()
            logger.info("正在检测IP: {0}".format(self.ip))
            logger.info("正在通过API获取信息...")
            datas = json.loads(target.text)
            self.ipInfo(datas['matches'])
            req.close()
            lock.release()
        except requests.exceptions.ReadTimeout:
            logger.error("请求超时")
        except requests.exceptions.ConnectionError:
            logger.error("网络超时")
        except json.decoder.JSONDecodeError:
            logger.error("获取失败,请重试")
            lock.release()
        self.sem.release()
예제 #8
0
파일: quake.py 프로젝트: r4b3rt/Glass
 def run(self):
     try:
         req = requests.Session()
         req.keep_alive = False
         req.headers = self.headers
         if Proxys.proxyList:
             if pyVersion < "3.8":
                 req.proxies = {
                     'https': '{0}'.format(random.choice(Proxys.scheme))
                 }
             else:
                 req.proxies = {
                     "https":
                     'https://{0}'.format(random.choice(Proxys.scheme))
                 }
         req.mount("https://", HTTPAdapter(max_retries=2))
         target = req.post(self.url, json=self.jsonData)
         lock.acquire()
         logger.info("正在检测IP: {0}".format(self.ip))
         logger.info("正在通过API获取信息...")
         datas = json.loads(target.text)
         if datas['code'] == 1:
             logger.warning("接口积分不足")
         if datas['code'] == 2:
             logger.warning("限速了,请等待")
         self.ipInfo(datas['data'])
         req.close()
         lock.release()
     except requests.exceptions.ReadTimeout:
         logger.error("请求超时")
     except requests.exceptions.ConnectionError:
         logger.error("网络超时")
     except json.decoder.JSONDecodeError:
         logger.error("获取失败,请重试")
         lock.release()
     self.sem.release()
예제 #9
0
def set_confs():
    if confs.updateprogram:
        update()
    if confs.version:
        logger.info("Version: {0}".format(Version))
        exit(0)
    if confs.search:
        searchType = ["fofa", "eye"]
        if confs.search in set(searchType):
            pass
        else:
            logger.error("参数错误,e.g.(-s fofa or -s eye)")
            exit(0)
    if confs.outputTarget:
        outTypes = ["txt", "json", "html", "xls", "csv"]
        if confs.outputTarget in set(outTypes):
            pass
        else:
            logger.error("输出格式错误,只支持输出格式为:{0}".format(outTypes))
            exit(0)
    if confs.ip:
        Urls.ips.append(confs.ip)
    if confs.url:
        if not confs.url.startswith('http'):
            confs.url = "http://" + confs.url
        Urls.url.append(confs.url)
    if confs.file:
        with open(confs.file, 'r') as f:
            for ip in f.readlines():
                if len(ip) != 1:
                    Urls.ips.append(ip.strip())
    if confs.web:
        with open(confs.web, 'r') as f:
            for web in f.readlines():
                if len(web) != 1:
                    if not web.startswith('http'):
                        web = "http://" + web
                    Urls.url.append(web.strip())

    if isinstance(confs["proxy"], str):
        if ":" in confs["proxy"]:
            splits = confs["proxy"].split(":")
            try:
                if int(splits[2]):
                    confs["proxy"] = {
                        splits[0]:
                        "{0}:{1}:{2}".format(splits[0], splits[1], splits[2])
                    }
                    Proxys.proxyList.append(confs["proxy"])
            except ValueError:
                logger.error(
                    "代理地址错误,例如:http://127.0.0.1:8080 or https://127.0.0.1:8080"
                )
                exit(0)
        elif confs["proxy"] != "all" and confs["proxy"] != "cn":
            logger.error(
                "参数错误,all表示加载全部IP,cn加载国内IP,自定义例子为:http://127.0.0.1:8080 or https://127.0.0.1:8080"
            )
            exit(0)
        else:
            checkProxyFile(confs["proxy"])
        if len(Proxys.proxyList) == 0:
            logger.error("本地获取代理失败,请从新获取")
            message = input("是否不使用代理访问?[y/N]")
            if message != "y":
                exit(0)
        else:
            logger.info("分配IP中")
            getScheme()
    if confs.proxylist:
        if confs.proxylist == "all" or confs.proxylist == "cn":
            checkProxyFile(confs.proxylist)
            if len(Proxys.proxyList) == 0:
                logger.error("本地获取代理失败,请重新获取")
                exit(0)
            else:
                tb = pt.PrettyTable()
                tb.field_names = ['Protocol', 'Host']
                for p in Proxys.proxyList:
                    logger.info(p)
                    for i in p:
                        tb.add_row([i, p[i]])
                print(tb)
                logger.info("协议可切换,一般在代理插件里设置http协议,这样避免证书问题")
        else:
            exit(0)
예제 #10
0
파일: update.py 프로젝트: westlyou/Glass
def update():
    success = False

    if Version == getLatestRevision():
        logger.info("Version:{0} 已经是最新版本".format(Version))
        exit(0)
    elif Version < getLatestRevision():
        logger.info("当前版本 Version: {0},最新版本为 Version: {1}".format(
            Version, getLatestRevision()))
    else:
        logger.info("Version:{0} 已经是最新版本".format(Version))
        exit(0)
    message = input("是否更新?[y/N]")
    if message == "y":
        directory = os.path.abspath(Paths.root)
    else:
        exit(0)
    try:
        open(os.path.join(directory, "Glass.py"), "w+b")
    except Exception as ex:
        logger.error("无法更新目录的内容 '{0}'".format(ex))
    else:
        attrs = os.stat(os.path.join(directory, "Glass.py")).st_mode
        for wildcard in ('*', "."):
            for _ in glob.glob(os.path.join(directory, wildcard)):
                try:
                    if os.path.isdir(_):
                        shutil.rmtree(_)
                    else:
                        os.remove(_)
                except:
                    pass
        if glob.glob(os.path.join(directory, '*')):
            errMsg = "无法清除目录的内容 '{0}'".format(directory)
            logger.error(errMsg)
        else:
            try:
                archive = urllib.request.urlretrieve(ZIPBALL_PAGE)[0]

                with zipfile.ZipFile(archive) as f:
                    for info in f.infolist():
                        info.filename = re.sub(r"s7ckTeam-Glass[^/]+", "",
                                               info.filename)
                        if info.filename:
                            f.extract(info, directory)

                filepath = os.path.join(Paths.root, "config", "config.py")
                if os.path.isfile(filepath):
                    with open(filepath, 'r', encoding='utf-8') as f:
                        nowVersion = re.search(
                            r"(?m)^Version\s*=\s*['\"]([^'\"]+)",
                            f.read()).group(1)
                        logger.info("更新到最新版本:{0}".format(nowVersion))
                        os.remove(archive)
                        success = True
            except Exception as ex:
                logger.error("抱歉!!!更新无法完成 ('{0}')".format(ex))

    if not success:
        logger.info("请前往Github重新下载")
        logger.info("下载地址:{0}".format(GIT_REPOSITORY))
예제 #11
0
# /usr/bin/env python
# -*- coding: utf-8 -*-
'''
@File  :   Glass.py
@Time  :   2020/12/23 17:37:25
@Author:   Morker
@Blog  :   https://96.mk/
@Email :   [email protected]

If you don't go through the cold, you can't get the fragrant plum blossom.
'''

import sys
sys.dont_write_bytecode = True

try:
    from config.data import logger
    import console

    console.main()
except ModuleNotFoundError as ex:
    moduleName = str(ex).split("'")[1]
    logger.error("未找到相关模块 {0}".format(moduleName))
    logger.info(
        "输入:python3 -m pip install {0},或者:pip3 install {1} 进行安装".format(moduleName, moduleName))