Advertisement
BERKYT

task_1_v_2

May 27th, 2022 (edited)
686
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ======================================================================================================================
  2.  
  3. # Authors: BERKYT, Walgala, Александр Хаметзянов
  4.  
  5. # ======================================================================================================================
  6.  
  7. # Формат флага: XXX{}
  8. # Формат ссылки: https://task1.tasks.rubikoid.ru/md5(c3e97dd6e97fb5125688c97f36720cbe + secret + .php
  9.  
  10. import hashlib
  11. import random
  12. import re
  13. import threading
  14.  
  15. from rich.console import Console
  16. from selenium import webdriver
  17. from selenium.webdriver.common.by import By
  18.  
  19.  
  20. link = 'https://task1.tasks.rubikoid.ru/c3e97dd6e97fb5125688c97f36720cbe.php'
  21. path_to_browser = r"D:\Downloads\chromedriver.exe"
  22. console = Console()
  23. ignore_words = ['Approved! Use secret to create a link for next step! next Chain step secret is:', 'Lorem',
  24. 'gimmie a value whose MD5 ends with this 4 chars from captcha: ', 'Cmon Human!']
  25.  
  26.  
  27. def log(data: str):
  28.     with open('tmp_log.txt', 'a') as log_file:
  29.         log_file.write(str(data) + '\n')
  30.  
  31.  
  32. def generate_key(alphabet: str = '0123456789abcdefghijklmnopqrstuvwxyz', length: int = 4) -> str:
  33.     key = ''
  34.  
  35.     for _ in range(length):
  36.         key += random.choice(alphabet)
  37.  
  38.     return key
  39.  
  40.  
  41. def parse_html( responce: str, pattern: str = r'(?<=name="hash" value=").+?(?=")') -> list:
  42.     return re.findall(pattern, responce)
  43.  
  44.  
  45. def get_secret(sourse_code_site: list) -> str:
  46.     for line in sourse_code_site:
  47.         secret = parse_html(line, r'(?<=<br>).+?(?=<br>)')
  48.  
  49.         if secret:
  50.             console.print(f'Вариант секрета: {secret[0]=}')
  51.             if secret[0] not in ignore_words:
  52.                 return secret[0]
  53.  
  54.             console.print(f'Неверно!', style='bold underline red')
  55.  
  56.  
  57. def get_hash(sourse_code_site: list) -> str:
  58.     for line in sourse_code_site:
  59.         hash_capture = parse_html(line)
  60.  
  61.         if hash_capture:
  62.             return hash_capture[0]
  63.     else:
  64.         raise Exception('На сайте нет хеша.')
  65.  
  66.  
  67. def decrypt_md5(target_hash: str) -> str:
  68.     with console.status('[bold green]Waiting...[/bold green]'):
  69.         while True:
  70.             decrypt_hash = generate_key()
  71.             hash_object = hashlib.md5(decrypt_hash.encode('utf-8'))
  72.  
  73.             if hash_object.hexdigest() == target_hash:
  74.                 return decrypt_hash
  75.  
  76.  
  77. # создает хеш с 4 символами который совпадает с 4 последними символами капчи
  78. def find_target_hash(sub_line: str) -> tuple[str, str]:
  79.     with console.status('[bold green]Waiting...[/bold green]'):
  80.         while True:
  81.             target_decrypt_hash = generate_key()
  82.             hash_object = hashlib.md5(target_decrypt_hash.encode('utf-8'))
  83.             hash_str = str(hash_object.hexdigest())
  84.  
  85.             if hash_str[-4:] == sub_line:
  86.                 return hash_str, target_decrypt_hash
  87.  
  88.  
  89. def get_sourse_code_site() -> list:
  90.     global driver
  91.     return str(driver.page_source).split(r'\n')
  92.  
  93.  
  94. def find_secret():
  95.     while True:
  96.         global driver
  97.         #  гавно с открытием
  98.         options = webdriver.ChromeOptions()
  99.         driver = webdriver.Chrome(options=options, executable_path=path_to_browser)
  100.         driver.get(link)
  101.  
  102.         sourse_code_site = get_sourse_code_site()
  103.         hash_capture = get_hash(sourse_code_site)
  104.         decrypt_hash_capture = decrypt_md5(hash_capture)
  105.         new_hash, key = find_target_hash(decrypt_hash_capture)
  106.        
  107.         print(f'{hash_capture=}; {decrypt_hash_capture=}')
  108.         print(f'{new_hash=}; {key=}')
  109.        
  110.         driver.find_element(By.NAME, "ch").send_keys(key)
  111.         driver.find_element(By.NAME, "s").click()
  112.  
  113.         refreshed_sourse_code_site = get_sourse_code_site()
  114.         secret = get_secret(refreshed_sourse_code_site)
  115.         console.print(f'{secret=}', style='bold underline red')
  116.  
  117.         log([secret, new_hash, key, decrypt_hash_capture, hash_capture])
  118.  
  119.         if secret not in ignore_words and secret is not None:
  120.             break
  121.            
  122.     console.print('Секрет найден!', style='bold underline red')
  123.     print(get_sourse_code_site())
  124.     console.print(f'{secret=}', style='bold underline red')
  125.     log([secret, new_hash, key, decrypt_hash_capture, hash_capture, 'ЭТОТ ЛОГ С СЕКРЕТОМ!'])
  126.  
  127.  
  128. # for _ in range(10):
  129. #     thread = threading.Thread(
  130. #         target=find_secret
  131. #     )
  132. #     thread.start()
  133.  
  134. find_secret()
  135. input('Нажмите любую кнопку, чтобы закрыть...')
  136.  
Advertisement
RAW Paste Data Copied
Advertisement