■ ■ ■ ■ ■ ■
cve_2020_35489_checker.py
| 1 | + | import argparse |
| 2 | + | import asyncio |
| 3 | + | import os |
| 4 | + | import aiohttp |
| 5 | + | from packaging import version |
| 6 | + | |
| 7 | + | |
| 8 | + | def detecta_versao_plugin(texto_readme): |
| 9 | + | inicio_tag = "Stable tag:" |
| 10 | + | indice_inicio_versao = texto_readme.find(inicio_tag) |
| 11 | + | |
| 12 | + | if indice_inicio_versao != -1: |
| 13 | + | indice_fim_versao = texto_readme.find("\n", indice_inicio_versao) |
| 14 | + | |
| 15 | + | if indice_fim_versao != -1: |
| 16 | + | versao_detectada = texto_readme[indice_inicio_versao + len(inicio_tag):indice_fim_versao].split()[0] |
| 17 | + | return versao_detectada |
| 18 | + | |
| 19 | + | return None |
| 20 | + | |
| 21 | + | |
| 22 | + | async def verifica_site(cliente_http_sessao, dominio, arquivo_saida=''): |
| 23 | + | headers = { |
| 24 | + | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0" |
| 25 | + | } |
| 26 | + | url_readme_plugin = f'https://{dominio}/wp-content/plugins/contact-form-7/readme.txt' |
| 27 | + | |
| 28 | + | try: |
| 29 | + | async with cliente_http_sessao.get(url_readme_plugin, headers=headers, timeout=3.0, ssl=False) as resposta_http: |
| 30 | + | if resposta_http.status == 200: |
| 31 | + | try: |
| 32 | + | versao_detectada = detecta_versao_plugin(await resposta_http.text()) |
| 33 | + | except Exception as e: |
| 34 | + | print(f"\nSite: {dominio}\nOcorreu um erro ao obter a versão do plugin:\n{type(e).__name__}: {str(e)}") |
| 35 | + | return |
| 36 | + | |
| 37 | + | is_vulnerable = version.parse(versao_detectada) < version.parse("5.3.2") |
| 38 | + | print(f"\nSite: {dominio}\nVersão do Plugin \"Contact Form 7\": {versao_detectada}") |
| 39 | + | print(f"{dominio} {'-----------------------------------------------------------> ' if is_vulnerable else 'Não '}é vulnerável!\n") |
| 40 | + | if arquivo_saida and is_vulnerable: |
| 41 | + | with open(arquivo_saida, "a") as f: |
| 42 | + | f.write(f"{dominio}\n") |
| 43 | + | else: |
| 44 | + | print(f"\nSite: {dominio}\nFalha na requisição HTTP ao tentar obter a versão do plugin:\nStatus code: {resposta_http.status}") |
| 45 | + | except asyncio.TimeoutError: |
| 46 | + | print(f"\nSite: {dominio}\nFalha: A solicitação para obter a versão do plugin excedeu o tempo limite. (3 segundos para \"timeout\")\n") |
| 47 | + | except Exception as e: |
| 48 | + | print(f"\nSite: {dominio}\nOcorreu um erro ao obter a versão do plugin:\n{str(e)}\n") |
| 49 | + | |
| 50 | + | |
| 51 | + | async def main(): |
| 52 | + | parser = argparse.ArgumentParser( |
| 53 | + | description='Verifica se um site é vulnerável à CVE-2020-35489.' |
| 54 | + | ) |
| 55 | + | parser.add_argument('-d', '--domain', help='Verificar um único site (Exemplo: python cve_2020_35489_checker.py -d exemplo.com)') |
| 56 | + | parser.add_argument('-i', '--input-file', help='Verificar vários sites de um arquivo de texto (Exemplo: python cve_2020_35489_checker.py -i lista.txt -o vulneraveis.txt)') |
| 57 | + | parser.add_argument('-o', '--output-file', help='Arquivo de saída para a lista de sites vulneráveis') |
| 58 | + | args = parser.parse_args() |
| 59 | + | |
| 60 | + | if args.output_file and not os.path.exists(args.output_file): |
| 61 | + | open(args.output_file, 'w').close() |
| 62 | + | |
| 63 | + | if args.input_file: |
| 64 | + | if not os.path.exists(args.input_file): |
| 65 | + | open(args.input_file, 'w').close() |
| 66 | + | print(f"Arquivo de entrada '{args.input_file}' criado, mas está vazio. Por favor, preencha-o com uma lista de sites para testar.") |
| 67 | + | else: |
| 68 | + | async with aiohttp.ClientSession() as session: |
| 69 | + | with open(args.input_file, 'r') as f: |
| 70 | + | tasks = [ |
| 71 | + | verifica_site(session, line.strip().split(':')[0], args.output_file) |
| 72 | + | for line in f if line.strip() |
| 73 | + | ] |
| 74 | + | await asyncio.gather(*tasks) |
| 75 | + | elif args.domain: |
| 76 | + | async with aiohttp.ClientSession() as session: |
| 77 | + | await verifica_site(session, args.domain, args.output_file) |
| 78 | + | else: |
| 79 | + | parser.print_help() |
| 80 | + | |
| 81 | + | |
| 82 | + | if __name__ == "__main__": |
| 83 | + | asyncio.run(main()) |
| 84 | + | |