-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-malware-csv.py
More file actions
41 lines (33 loc) · 1.2 KB
/
Copy pathget-malware-csv.py
File metadata and controls
41 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
import requests
import zipfile
import os
# URL of the ZIP file
url = "https://bazaar.abuse.ch/export/csv/full/"
# Filenames
zip_filename = "malwarebazaar.zip"
csv_output_filename = "malwarebazaar.csv"
def download_and_extract_csv():
try:
print("Downloading ZIP file...")
response = requests.get(url, stream=True)
response.raise_for_status()
# Save the ZIP file locally
with open(zip_filename, "wb") as f:
f.write(response.content)
print("Extracting ZIP file...")
with zipfile.ZipFile(zip_filename, 'r') as zip_ref:
for file in zip_ref.namelist():
if file.endswith(".csv"):
# Extract and save the CSV file
with zip_ref.open(file) as csv_file:
with open(csv_output_filename, "wb") as out_csv:
out_csv.write(csv_file.read())
print(f"{csv_output_filename} has been saved.")
# Delete the ZIP file after extraction
os.remove(zip_filename)
print("ZIP file has been deleted.")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
download_and_extract_csv()