Advertisement
Sweetening

hackforums cli test

Jun 5th, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.00 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import undetected_chromedriver as uc
  4. from selenium.webdriver.chrome.options import Options
  5. from colorama import Fore, Style, init as colorama_init
  6. import websocket
  7. import ssl
  8. import threading
  9. import time
  10. import json
  11. import os
  12. import argparse
  13. import sys
  14. import signal
  15.  
  16. colorama_init(autoreset=True)
  17. signal.signal(signal.SIGINT, lambda sig, frame: sys.exit(0))
  18.  
  19. # --------------------
  20. # CONFIGURATION
  21. # --------------------
  22. TARGET_URL = "https://hackforums.net/convo.php"
  23. WS_BASE_URL = "wss://hackforums.net:2096/socket.io/?EIO=3&transport=websocket"
  24. DUMP_PATH = os.path.expanduser("~/.hf_socket_dump.jsonl")
  25.  
  26. # --------------------
  27. # CLI Argument Parsing
  28. # --------------------
  29. parser = argparse.ArgumentParser(description="HackForums dvz mybb shoutbox CLI Chat")
  30. parser.add_argument("-m", "--message", help="Send a message to a conversation")
  31. parser.add_argument("-c", "--convo", help="Target conversation ID to send/read from")
  32. parser.add_argument("-k", "--key", help="Public key for encryption (if applicable)")
  33. parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose socket logs")
  34. parser.add_argument("--dump", help="Specify custom dump path", default=DUMP_PATH)
  35. parser.add_argument("--read", action="store_true", help="Read messages from a conversation")
  36. args = parser.parse_args()
  37.  
  38. if args.message and not args.convo:
  39. print(f"{Fore.RED}[!] Conversation ID (-c) required when sending a message (-m).{Style.RESET_ALL}")
  40. sys.exit(1)
  41.  
  42. # --------------------
  43. # Step 1: Launch stealth browser and fetch cookies
  44. # --------------------
  45. def get_cookies():
  46. print(f"{Fore.YELLOW}[*] Launching stealth browser...{Style.RESET_ALL}")
  47. chrome_options = Options()
  48. chrome_options.add_argument("--headless=new")
  49. chrome_options.add_argument("--disable-blink-features=AutomationControlled")
  50. chrome_options.add_argument("--no-sandbox")
  51. chrome_options.add_argument("--disable-dev-shm-usage")
  52. # Add user-agent string to mimic normal browser
  53. chrome_options.add_argument(
  54. "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
  55. "(KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
  56. )
  57.  
  58. try:
  59. driver = uc.Chrome(options=chrome_options)
  60. driver.get(TARGET_URL)
  61. print(f"{Fore.YELLOW}[*] Waiting out JS/Captcha firewall (15s)...{Style.RESET_ALL}")
  62. time.sleep(15) # Allow enough time to pass CF JS challenge & login cookies to settle
  63. cookies = driver.get_cookies()
  64. driver.quit()
  65. print(f"{Fore.GREEN}[+] Browser cookies captured.{Style.RESET_ALL}")
  66. return "; ".join([f"{c['name']}={c['value']}" for c in cookies])
  67. except Exception as e:
  68. print(f"{Fore.RED}[!] Error fetching cookies: {e}{Style.RESET_ALL}")
  69. sys.exit(1)
  70.  
  71. cookie_header = get_cookies()
  72.  
  73. # --------------------
  74. # Step 2: WebSocket URL with timestamp to avoid caching
  75. # --------------------
  76. ts = int(time.time() * 1000)
  77. ws_url = f"{WS_BASE_URL}&t={ts}"
  78.  
  79. # Remove old dump file if exists
  80. if os.path.exists(args.dump):
  81. os.remove(args.dump)
  82.  
  83. # --------------------
  84. # Utility: Extract session token from cookies
  85. # --------------------
  86. def get_session_token():
  87. for part in cookie_header.split("; "):
  88. if part.startswith("session="):
  89. return part.split("=", 1)[1]
  90. return None
  91.  
  92. # --------------------
  93. # Logging & Dumping
  94. # --------------------
  95. def log_event(event_type, data):
  96. if not data:
  97. return
  98. color_map = {
  99. "debug": Fore.BLUE,
  100. "convo_message": Fore.CYAN,
  101. "typing": Fore.MAGENTA,
  102. "notice": Fore.YELLOW
  103. }
  104. color = color_map.get(event_type, Fore.WHITE)
  105. print(f"{color}[⚡ EVENT] {event_type.upper()}{Style.RESET_ALL}")
  106. print(json.dumps(data, indent=2))
  107. with open(args.dump, "a") as f:
  108. f.write(json.dumps({"event": event_type, "data": data, "ts": int(time.time())}) + "\n")
  109.  
  110. def parse_socketio_payload(message):
  111. if not message.startswith("42"):
  112. return None
  113. try:
  114. payload = json.loads(message[2:])
  115. return payload[0], payload[1]
  116. except Exception as e:
  117. print(f"{Fore.RED}[!] Payload parse error: {e}{Style.RESET_ALL}")
  118. return None
  119.  
  120. # --------------------
  121. # Socket.IO message wrappers
  122. # --------------------
  123. def send_packet(ws, event_name, data):
  124. payload = [event_name, data]
  125. packet = "42" + json.dumps(payload)
  126. ws.send(packet)
  127. if args.verbose:
  128. print(f"{Fore.YELLOW}[>] Sent event '{event_name}' with data: {data}{Style.RESET_ALL}")
  129.  
  130. def send_message(ws, convo_id, message, pubkey=None):
  131. # dvz mybb shoutbox send_message payload:
  132. data = {
  133. "convo_id": convo_id,
  134. "message": message,
  135. "key": pubkey or ""
  136. }
  137. send_packet(ws, "send_message", data)
  138.  
  139. def request_convo(ws, convo_id):
  140. send_packet(ws, "fetch_messages", {"convo_id": convo_id})
  141.  
  142. def join_convo(ws, convo_id):
  143. send_packet(ws, "join_conversation", {"convo_id": convo_id})
  144.  
  145. def auth_user(ws):
  146. token = get_session_token()
  147. data = {"session": token} if token else {}
  148. send_packet(ws, "auth_user", data)
  149. print(f"{Fore.GREEN}[+] Sent 'auth_user' with session token.{Style.RESET_ALL}")
  150.  
  151. # --------------------
  152. # WebSocket event handlers
  153. # --------------------
  154. def on_message(ws, message):
  155. if args.verbose:
  156. print(f"{Fore.LIGHTBLACK_EX}[<] {message}{Style.RESET_ALL}")
  157. result = parse_socketio_payload(message)
  158. if result:
  159. event_type, data = result
  160. log_event(event_type, data)
  161. # You can add auto-reply or other logic here
  162.  
  163. def on_error(ws, error):
  164. if error:
  165. print(f"{Fore.RED}[!] WebSocket error: {error}{Style.RESET_ALL}")
  166. else:
  167. print(f"{Fore.RED}[!] WebSocket error occurred with no message.{Style.RESET_ALL}")
  168.  
  169. def on_close(ws, code, msg):
  170. print(f"{Fore.RED}[-] WebSocket closed: Code={code} Message={msg}{Style.RESET_ALL}")
  171.  
  172. def on_open(ws):
  173. print(f"{Fore.GREEN}[+] WebSocket handshake initiated{Style.RESET_ALL}")
  174.  
  175. def socketio_handshake():
  176. try:
  177. # Standard Socket.IO probe & upgrade handshake
  178. ws.send("2probe")
  179. time.sleep(1)
  180. ws.send("5")
  181. time.sleep(1)
  182. ws.send("3")
  183. time.sleep(1)
  184.  
  185. # Authenticate user with session token
  186. auth_user(ws)
  187.  
  188. # Join convo and optionally send/read messages
  189. if args.convo:
  190. join_convo(ws, args.convo)
  191. if args.read:
  192. request_convo(ws, args.convo)
  193. if args.message:
  194. send_message(ws, args.convo, args.message, args.key)
  195.  
  196. # Heartbeat loop
  197. while True:
  198. time.sleep(15)
  199. ws.send("2")
  200. if args.verbose:
  201. print(f"{Fore.YELLOW}[>] Heartbeat ping sent{Style.RESET_ALL}")
  202.  
  203. except Exception as e:
  204. print(f"{Fore.RED}[X] Handshake thread error: {e}{Style.RESET_ALL}")
  205.  
  206. threading.Thread(target=socketio_handshake, daemon=True).start()
  207.  
  208. # --------------------
  209. # Run WebSocket client
  210. # --------------------
  211. def start_ws():
  212. ws = websocket.WebSocketApp(
  213. ws_url,
  214. on_open=on_open,
  215. on_message=on_message,
  216. on_error=on_error,
  217. on_close=on_close,
  218. header=[
  219. "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
  220. "Origin: https://hackforums.net",
  221. f"Referer: {TARGET_URL}",
  222. f"Cookie: {cookie_header}"
  223. ]
  224. )
  225. print(f"{Fore.YELLOW}[*] Connecting to {ws_url}{Style.RESET_ALL}")
  226. try:
  227. ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
  228. except KeyboardInterrupt:
  229. print(f"{Fore.RED}\n[!] Interrupted by user. Closing WebSocket...{Style.RESET_ALL}")
  230. ws.close()
  231. sys.exit(0)
  232.  
  233. # --------------------
  234. # Entrypoint
  235. # --------------------
  236. if __name__ == "__main__":
  237. start_ws()
  238.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement