tracerouted

Untitled

Oct 30th, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.55 KB | None | 0 0
  1. import websocket
  2. import requests
  3. import json
  4. import ssl
  5. import threading
  6. import time
  7.  
  8. VOTE_COUNT = 0
  9.  
  10. class TokenManager:
  11. @staticmethod
  12. def extract_w3t(headers):
  13. set_cookie = headers.get('set-cookie', '')
  14. cookies = set_cookie.split(', ')
  15. for cookie in cookies:
  16. if cookie.startswith('w3t='):
  17. return cookie.split(';')[0].split('=', 1)[1]
  18. return None
  19.  
  20. @staticmethod
  21. def extract_w3k(headers):
  22. set_cookie = headers.get('set-cookie', '')
  23. cookies = set_cookie.split(', ')
  24. for cookie in cookies:
  25. if cookie.startswith('w3k='):
  26. return cookie.split(';')[0].split('=', 1)[1]
  27. return None
  28.  
  29. @staticmethod
  30. def get_token():
  31. headers = {
  32. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0"
  33. }
  34.  
  35. while True:
  36. req = requests.get("https://nsk.kp.ru/media/984186/", headers=headers)
  37. entity = TokenManager.extract_w3t(req.headers)
  38. cookie_w3k = TokenManager.extract_w3k(req.headers)
  39.  
  40. if entity and cookie_w3k:
  41. headers.update({
  42. "Cookie": f"w3t={entity}; w3k={cookie_w3k}",
  43. "Referer": "https://www.nsk.kp.ru",
  44. })
  45. req = requests.get('https://identity.kp.house/identity/api/2/auth/token.json?callback=data&client_name=prod&sub=1', headers=headers)
  46. signature = req.json().get('data', '')
  47. auth_id = TokenManager.extract_w3k(req.headers)
  48. return entity, signature, auth_id, cookie_w3k
  49. else:
  50. print("Failed to retrieve valid w3t or w3k tokens, retrying in 3 seconds")
  51. time.sleep(3)
  52.  
  53. class VoteBot:
  54. def __init__(self, entity, signature, auth_id, cookie_w3k):
  55. self.entity = entity
  56. self.signature = signature
  57. self.auth_id = auth_id
  58. self.cookie_w3k = cookie_w3k
  59. self.ws = None
  60.  
  61. def on_message(self, ws, message):
  62. global VOTE_COUNT
  63. message_data = json.loads(message)
  64.  
  65. if message_data[0] == 4:
  66. self.send_authentication()
  67. elif message_data[0] == 3:
  68. entity, signature, auth_id, cookie_w3k = TokenManager.get_token()
  69. self.entity = entity
  70. self.signature = signature
  71. self.auth_id = auth_id
  72. self.cookie_w3k = cookie_w3k
  73. self.send_hello()
  74. elif message_data[0] == 2:
  75. self.send_vote()
  76. elif message_data[0] == 50:
  77. VOTE_COUNT += 1
  78. print(f"Vote #{VOTE_COUNT} sent successfully")
  79. self.ws.close()
  80.  
  81. def on_error(self, ws, error):
  82. print(f"Error: {error}")
  83.  
  84. def on_close(self, ws, close_status_code, close_msg):
  85. print("Connection closed")
  86.  
  87. def on_open(self, ws):
  88. self.send_hello()
  89.  
  90. def send_hello(self):
  91. hello_message = [
  92. 1,
  93. "kpcdn",
  94. {
  95. "roles": {
  96. "caller": {"features": {"caller_identification": True, "call_canceling": True, "progressive_call_results": True}},
  97. "callee": {"features": {"caller_identification": True, "pattern_based_registration": True, "shared_registration": True, "progressive_call_results": True, "registration_revocation": True}},
  98. "publisher": {"features": {"publisher_identification": True, "subscriber_blackwhite_listing": True, "publisher_exclusion": True}},
  99. "subscriber": {"features": {"publisher_identification": True, "pattern_based_subscription": True, "subscription_revocation": True}}
  100. },
  101. "authmethods": ["ticket"],
  102. "authid": self.auth_id
  103. }
  104. ]
  105. self.ws.send(json.dumps(hello_message))
  106.  
  107. def send_authentication(self):
  108. auth_message = [
  109. 5,
  110. self.signature,
  111. {}
  112. ]
  113. self.ws.send(json.dumps(auth_message))
  114.  
  115. def send_vote(self):
  116. vote_message = [
  117. 48,
  118. 1,
  119. {"disclose_me": True},
  120. "net.kpcdn.online.send",
  121. [{
  122. "schema": "interactive",
  123. "method": "polls.raw",
  124. "target": {
  125. "spot": "interactive",
  126. "base": "polls.raw",
  127. "entity": self.entity
  128. },
  129. "@context": "message",
  130. "body": {
  131. "contest-id": "670f265afbee6d0007e94cfa",
  132. "vote-container-id": "67101efcfbee6d0007e94dd5",
  133. "competitor-id": "670febf0fbee6d0007e94d70",
  134. "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0",
  135. "referrer": "",
  136. "source": "kp.ru",
  137. "is-mobile": True
  138. }
  139. }],
  140. {}
  141. ]
  142. self.ws.send(json.dumps(vote_message))
  143.  
  144. def run(self):
  145. self.ws = websocket.WebSocketApp("wss://www.kp.kg/ws",
  146. on_open=self.on_open,
  147. on_message=self.on_message,
  148. on_error=self.on_error,
  149. on_close=self.on_close,
  150. header=["Sec-WebSocket-Protocol: wamp.2.json", "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0", "Origin: https://www.nsk.kp.ru"],
  151. cookie=f"w3k={self.cookie_w3k}; w3t={self.entity}")
  152.  
  153. self.ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
  154.  
  155. def run_bot():
  156. entity, signature, auth_id, cookie_w3k = TokenManager.get_token()
  157. bot = VoteBot(entity, signature, auth_id, cookie_w3k)
  158. bot.run()
  159.  
  160. def main(num_threads, max_concurrent_threads):
  161. semaphore = threading.Semaphore(max_concurrent_threads)
  162. threads = []
  163.  
  164. def thread_target():
  165. with semaphore:
  166. run_bot()
  167.  
  168. for _ in range(num_threads):
  169. thread = threading.Thread(target=thread_target)
  170. threads.append(thread)
  171. thread.start()
  172.  
  173. for thread in threads:
  174. thread.join()
  175.  
  176. if __name__ == "__main__":
  177. num_threads = 50000
  178. max_concurrent_threads = 50
  179. main(num_threads=num_threads, max_concurrent_threads=max_concurrent_threads)
Advertisement
Add Comment
Please, Sign In to add comment