Archived
Python script that scans an array of selected plugins against the names found in our CVE.
97 lines
3.0 KiB
Python
97 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
import csv
|
|
import os
|
|
from urllib.parse import urlparse
|
|
|
|
REL_PATH = "../"
|
|
LOCAL_PATH = REL_PATH + "wordfence_vulnerabilities.json"
|
|
RAW_URL = ""
|
|
bad_plugins = []
|
|
OUT_CSV = "matches.csv"
|
|
OUT_JSON = "matches.json"
|
|
|
|
def load_json_local(path):
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
def load_json_from_url(url):
|
|
import requests
|
|
r = requests.get(url, timeout=30)
|
|
r.raise_for_status()
|
|
return r.json()
|
|
|
|
def main():
|
|
data = None
|
|
if os.path.exists(LOCAL_PATH):
|
|
print(f"Loading local file: {LOCAL_PATH}")
|
|
data = load_json_local(LOCAL_PATH)
|
|
elif RAW_URL:
|
|
print(f"Local file not found, downloading from: {RAW_URL}")
|
|
data = load_json_from_url(RAW_URL)
|
|
else:
|
|
raise SystemExit("Error: no local file and RAW_URL is empty.")
|
|
|
|
if isinstance(data, dict) and "vulnerabilities" in data:
|
|
entries = data["vulnerabilities"]
|
|
elif isinstance(data, list):
|
|
entries = data
|
|
else:
|
|
entries = []
|
|
if isinstance(data, dict):
|
|
for v in data.values():
|
|
if isinstance(v, list):
|
|
entries = v
|
|
break
|
|
|
|
bad_set = set(bad_plugins)
|
|
matches = []
|
|
for entry in entries:
|
|
try:
|
|
if entry.get("type") != "plugin":
|
|
continue
|
|
slug = entry.get("slug", "").strip()
|
|
if not slug:
|
|
continue
|
|
if slug in bad_set:
|
|
matches.append({
|
|
"slug": slug,
|
|
"title": entry.get("title"),
|
|
"cve": entry.get("cve"),
|
|
"severity": entry.get("severity"),
|
|
"cvss_score": entry.get("cvss_score"),
|
|
"cve_link": entry.get("cve_link"),
|
|
"raw": entry
|
|
})
|
|
except Exception:
|
|
continue
|
|
|
|
if not matches:
|
|
print("No matches found for the bad_plugins list.")
|
|
else:
|
|
print(f"Found {len(matches)} matches:")
|
|
for m in matches:
|
|
print(f"- {m['slug']} | CVE: {m.get('cve')} | sev: {m.get('severity')} | CVSS: {m.get('cvss_score')}")
|
|
print(f" link: {m.get('cve_link')}")
|
|
|
|
with open(OUT_CSV, "w", newline='', encoding="utf-8") as csvf:
|
|
writer = csv.DictWriter(csvf, fieldnames=["slug", "title", "cve", "severity", "cvss_score", "cve_link"])
|
|
writer.writeheader()
|
|
for m in matches:
|
|
writer.writerow({
|
|
"slug": m["slug"],
|
|
"title": m.get("title"),
|
|
"cve": m.get("cve"),
|
|
"severity": m.get("severity"),
|
|
"cvss_score": m.get("cvss_score"),
|
|
"cve_link": m.get("cve_link")
|
|
})
|
|
print(f"Saved CSV results to {OUT_CSV}")
|
|
|
|
with open(OUT_JSON, "w", encoding="utf-8") as jf:
|
|
json.dump(matches, jf, ensure_ascii=False, indent=2)
|
|
print(f"Saved JSON results to {OUT_JSON}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|