diff --git a/your_daily_dose_malware/backends/malshare.py b/your_daily_dose_malware/backends/malshare.py index ced5388..9d5d195 100644 --- a/your_daily_dose_malware/backends/malshare.py +++ b/your_daily_dose_malware/backends/malshare.py @@ -9,30 +9,30 @@ load_dotenv() +API_KEY = os.getenv("MALSHARE_API_KEY") + def scrap_malshare(): """List hashes from the past 24 hours """ with Progress() as progress: - api_key = os.getenv("MALSHARE_API_KEY") - if api_key == "": - rich.print("[green]Skipping Malshare not api key") + if API_KEY is None or API_KEY == "": return None try: response = requests.post( "https://malshare.com/api.php", verify=True, - params={"api_key": api_key, "action": "getlist"}, + params={"api_key": API_KEY, "action": "getlist"}, ) response.raise_for_status() hashes = response.json() except requests.RequestException as err: - rich.print(f"[red] An error occurred: {err}") - + rich.print(f"[red] Malshare will be skipped. An expected error occurred: {err} ") + return None rich.print(f"[green] - Malshare: {len(hashes)} Samples") sha256_ids = [hashe["sha256"] for hashe in hashes] task = progress.add_task( - " - [green]Downloading Malware Files...", total=len(sha256_ids) + "-[green]Downloading Malware Files...", total=len(sha256_ids) ) Path("Downloaded-Malwares").mkdir(exist_ok=True) downloaded_malwares_path = Path("Downloaded-Malwares").absolute() @@ -43,7 +43,7 @@ def scrap_malshare(): try: response = requests.post( "https://malshare.com/api.php", - params={"api_key": api_key, "action": "getfile", "hash": sha256_id}, + params={"api_key": API_KEY, "action": "getfile", "hash": sha256_id}, verify=True, ) response.raise_for_status() diff --git a/your_daily_dose_malware/backends/malware_bazaar.py b/your_daily_dose_malware/backends/malware_bazaar.py index 7d55fa5..09a2bc6 100644 --- a/your_daily_dose_malware/backends/malware_bazaar.py +++ b/your_daily_dose_malware/backends/malware_bazaar.py @@ -116,7 +116,7 @@ def all_most_recent(headers_info): def scrap_malware_bazaar(hundred_recent): if os.getenv("MALWARE_BAZAAR_API_KEY") == "": - rich.print("[green] Skipping Malware Bazaar not api key") + rich.print("[red]Please set MALWARE_BAZAAR_API_KEY") return None headers = {"API-KEY": os.getenv("MALWARE_BAZAAR_API_KEY")} if hundred_recent: