Guest User

Untitled

a guest
Dec 27th, 2024
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.74 KB | None | 0 0
  1.  
  2. import requests
  3. import json
  4. import base64    
  5. from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
  6. from cryptography.hazmat.primitives.hashes import SHA256
  7. from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  8. from cryptography.hazmat.backends import default_backend
  9.  
  10. headers = {
  11.     'authority': 'www.oddsportal.com',
  12.     'method': 'GET',
  13.     'scheme': 'https',
  14.     'accept': 'application/json, text/plain, */*',
  15.     'accept-encoding': 'deflate',
  16.     'accept-language': 'en-US,en;q=0.9,fi-FI;q=0.8,fi;q=0.7',
  17.     'content-type': 'application/json',
  18.     'referer': 'https://www.oddsportal.com/matches/hockey/20240109',
  19.     'sec-ch-ua-platform': '"Windows"',
  20.     'sec-fetch-dest': 'empty',
  21.     'sec-fetch-mode': 'cors',
  22.     'sec-fetch-site': 'same-origin',
  23.     'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
  24.     'x-requested-with': 'XMLHttpRequest'
  25.     }
  26.  
  27. version_id=1
  28. sport_id=1
  29. unique_id='82qTWLi3'
  30. xhash='yjdca'
  31.  
  32.  
  33. # URL for fetching the data
  34. url = f'https://www.oddsportal.com/feed/match-event/{version_id}-{sport_id}-{unique_id}-1-2-{xhash}.dat'
  35.  
  36. # Send the GET request and retrieve the response text
  37. response = requests.get(url, headers=headers)
  38. data = response.text
  39.  
  40. # Decode the base64 encoded data
  41. decoded_data = base64.b64decode(data).decode()
  42.  
  43. # Separate the encrypted data and key
  44. encrypted, key = decoded_data.split(":")
  45.  
  46. # Decode the encrypted part and the key
  47. encrypted_bytes = base64.urlsafe_b64decode(encrypted)
  48. key_bytes = bytes.fromhex(key)
  49.  
  50. # Define the password and salt used for key derivation
  51. password = b"%RtR8AB&nWsh=AQC+v!=pgAe@dSQG3kQ"
  52. salt = b"orieC_jQQWRmhkPvR6u2kzXeTube6aYupiOddsPortal"
  53.  
  54. # Derive the AES key using PBKDF2 with SHA256
  55. kdf = PBKDF2HMAC(
  56.     algorithm=SHA256(),
  57.     length=32,  # 256 bits
  58.     salt=salt,
  59.     iterations=1000,
  60.     backend=default_backend()
  61. )
  62.  
  63. aes_key = kdf.derive(password)
  64.  
  65. # Set up the AES decryption cipher in CBC mode
  66. cipher = Cipher(
  67.     algorithms.AES(aes_key),
  68.     modes.CBC(key_bytes),
  69.     backend=default_backend()
  70. )
  71. decryptor = cipher.decryptor()
  72.  
  73. # Decrypt the data
  74. decrypted_bytes = decryptor.update(encrypted_bytes) + decryptor.finalize()
  75.  
  76. # Decode the decrypted bytes into a string
  77. decrypted_data = decrypted_bytes.decode('utf-8')
  78.  
  79. # Find the end of the JSON data
  80. end_of_json = decrypted_data.rfind('}')
  81.  
  82. # If a valid JSON end is found, trim the data to that point
  83. if end_of_json != -1:
  84.     decrypted_data = decrypted_data[:end_of_json + 1]
  85.  
  86. # Parse the decrypted data as JSON
  87. try:
  88.     parsed_data = json.loads(decrypted_data)
  89.     print(parsed_data)
  90. except json.JSONDecodeError as e:
  91.     print("Error parsing JSON:", e)
  92.  
  93.  
Add Comment
Please, Sign In to add comment