Skip to content

Commit

Permalink
fix: avoid malshare client error occure when malware is triggered
Browse files Browse the repository at this point in the history
  • Loading branch information
poneoneo committed Sep 17, 2024
1 parent eb2e118 commit 89ab683
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions your_daily_dose_malware/backends/malshare.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,24 @@

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("[red]Please set MALSHARE_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]
Expand All @@ -43,7 +42,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()
Expand Down

0 comments on commit 89ab683

Please sign in to comment.