#python.exe get_pravda.py import sys import subprocess import time import os import urllib.request import re warning = '''[Warning] - This file is generated for downloading pravda samples - This might fail anytime depending upon change in URI, as simple logic being used here. - created on 14-12-2025 by darshan.sutar --------------------------------------------------------------------------------\n\n''' def cleanup(uri): res = '' for line in uri: res += line.rstrip().rstrip("=") res = res.replace("?ttp", "http").replace("[dot]", ".").replace("%3D", "=").replace("3D", "=") #res = urllib.parse.unquote(res) return res def cleanup2(uri): res = '' for line in uri: res += line.rstrip() res = res.replace("?ttp", "http").replace("[dot]", ".").replace("%3D", "=") #res = urllib.parse.unquote(res) return res def download_extract(ZIP_URL): ZIP_FILE = "sample.zip" match = re.search(r"/([^/]+\.zip)\?", ZIP_URL) if match: zip_name = match.group(1) #print(zip_name) ZIP_FILE = zip_name EXTRACT_DIR = os.getcwd() ZIP_PASSWORD = "infected" print("[INFO] Downloading") try: urllib.request.urlretrieve(ZIP_URL, ZIP_FILE) print("[INFO] Download completed successfully") except urllib.error.HTTPError as e: print("[ERROR] HTTP error occurred") print("Reason:", e.reason) except urllib.error.URLError as e: print("[ERROR] URL error occurred") print("Reason:", e.reason) except Exception as e: print("[ERROR] Unexpected error during download") print("[INFO] Extracting") cmd = ["7z", "x", ZIP_FILE, f"-p{ZIP_PASSWORD}", f"-o{EXTRACT_DIR}", "-y"] #subprocess.run(cmd, check=True) try: result = subprocess.run(cmd,capture_output=True,text=True,check=True) print("[INFO] Extraction completed") except subprocess.CalledProcessError as e: print("[ERROR] Extraction failed") def process_msg(arg): with open(arg, "r", encoding="utf-8") as f: content = f.read() uri_start = "Flagged File Location:" uri_end = "Flagged File Secondary Location:" start = content.find(uri_start) end = content.find(uri_end, start) if start != -1 and end != -1: extracted = content[start + len(uri_start): end].strip() #print(type(extracted)) plain_uri = cleanup(extracted) #print(plain_uri) download_extract(plain_uri) else: print("[Error] Flagged location is not present in message.txt") print("[Error] Not a Pravda ticket or wrong message.txt") if len(sys.argv) < 2: print("[ERROR] No message.txt file or URL provided.") print("Usage: get_pravda.py ") print("Usage: get_pravda.py ") print("Usage: get_pravda.py message.txt") sys.exit(1) #arg = sys.argv[1].lstrip() mer = re.compile(r"^\d+-\d+$") for arg in sys.argv[1:]: print("[INFO]Processing:", arg) arg = arg.lstrip() if mer.match(arg): print("[INFO] Input is Merlin item") print("[INFO] Trying to find given Merlin item...") cmd = ["merlin-get.bat", "-c", "-m", arg] p1 = subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True) check = p1.stdout[-11:].rstrip().lstrip() #print(check) if check == "not found": print("[Error] Merlin item {} not found".format(arg)) else: print("[INFO] Merlin item found {}".format(arg)) hcated_path = os.path.join(os.environ["APPDATA"],"hcated",arg) #cwd = os.getcwd() #print(cwd) if os.path.exists(hcated_path): print("[INFO] message.txt downloaded to {}".format(hcated_path)) os.chdir(hcated_path) msg = hcated_path + "\\" + "message.txt" #print(msg) if os.path.isfile(msg): process_msg("message.txt") else: print("[Error] message.txt not found, might need to download JWT token") else: print("[INFO] Path does not exist") elif arg.startswith("?ttps"): print("[INFO] Input is URL") plain_url = cleanup2(arg) #print(plain_url) download_extract(plain_url) elif arg.startswith("message.txt"): print("[INFO] Input is message.txt") process_msg(arg) else: print("[WARN] Unsupported argument format.") print("Usage: get_pravda.py ") print("Usage: get_pravda.py ") print("Usage: get_pravda.py message.txt") sys.exit(1)