Build a Python CVE Watcher That Alerts You When Your Software Has a New Vulnerability
Critical flaws like the GPUStack 9.8 bypass get added to CISA’s exploited list within days of disclosure. If you run that software, you have hours — not weeks — to patch. But nobody sends you a personal alert. Today we will build a Python CVE watcher: a script that checks the public NVD (National Vulnerability Database) API for the software you use and alerts you when a new vulnerability appears.
The Code
import json
import os
import time
import urllib.request
import urllib.parse
STATE_FILE = "cve_seen.json"
WATCHLIST = [
("gpustack", "gpustack"),
("openssl", "openssl"),
("wordpress", "wordpress"),
("apache", "http_server"),
]
def load_seen():
if os.path.exists(STATE_FILE):
with open(STATE_FILE) as f:
return set(json.load(f))
return set()
def save_seen(seen):
with open(STATE_FILE, "w") as f:
json.dump(sorted(seen), f)
def fetch_recent_cves(vendor, product, days=2):
query = urllib.parse.urlencode({
"keywordSearch": f"{vendor} {product}",
"resultsPerPage": 20,
})
url = f"https://services.nvd.nist.gov/rest/json/cves/2.0?{query}"
req = urllib.request.Request(url, headers={"User-Agent": "cve-watcher/1.0"})
with urllib.request.urlopen(req, timeout=30) as resp:
data = json.load(resp)
out = []
for item in data.get("vulnerabilities", []):
cve = item["cve"]
published = cve.get("published", "")[:10]
desc = cve["descriptions"][0]["value"]
score = None
for m in cve.get("metrics", {}).get("cvssMetricV31", []):
score = m["cvssData"]["baseScore"]
out.append((cve["id"], published, score, desc))
return out
def main():
seen = load_seen()
new_findings = []
for vendor, product in WATCHLIST:
try:
for cve_id, published, score, desc in fetch_recent_cves(vendor, product):
if cve_id not in seen:
seen.add(cve_id)
new_findings.append((cve_id, published, score, desc))
except Exception as e:
print(f"[!] {vendor}/{product}: check failed ({e})")
time.sleep(6)
save_seen(seen)
if new_findings:
print(f"\n*** {len(new_findings)} NEW CVE(s) ***")
for cve_id, published, score, desc in new_findings:
print(f"\n{cve_id} | {published} | CVSS {score}")
print(f" {desc[:200]}...")
else:
print("No new CVEs for your watchlist. All clear.")
if __name__ == "__main__":
main()
How It Works
- Watchlist — you list the software you actually run, as vendor/product pairs. Start with the 5–10 things that matter most: your web server, your CMS, your VPN, your AI tools.
- NVD API — the script queries the free public NVD API (no key needed for light use) for recent CVEs mentioning each product.
- State file — cve_seen.json remembers which CVEs you have already been told about, so you only get alerted once per flaw.
- Rate limit respect — NVD asks unauthenticated users to wait 6 seconds between requests; the script does exactly that. (Get a free NVD API key if you want faster checks.)
Try It
Save as cve_watcher.py, edit the WATCHLIST to your own software, and run it:
python3 cve_watcher.py
Run it daily with cron and you have a personal early-warning system:
0 8 * * * cd /home/anony/scripts && python3 cve_watcher.py >> cve_log.txt 2>&1
Level Up
- Send real alerts — pipe new findings into an email, a Telegram bot message, or a webhook instead of just printing them.
- Filter by severity — only alert on CVSS 7.0 and above so low-severity noise does not bury the critical ones.
- Check CISA KEV too — the KEV catalog lists flaws confirmed exploited in the wild; a CVE appearing there means patch today. The KEV JSON feed is free at cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json.
- Add your versions — match CVEs against the exact versions you run, so you only get alerted about flaws that actually affect you.
You just built the same kind of monitoring that security teams pay for — from a public API and 60 lines of Python. Run it on your own systems, keep your watchlist current, and you will never again learn about a critical flaw from a breach notification.



Comments
Post a Comment