Restore multi-year trending PoCs with 4-day filter

This commit is contained in:
0xMarcio
2025-12-17 21:14:24 +01:00
parent 722d7261ba
commit 0afef5597e
4 changed files with 54 additions and 27 deletions

View File

@@ -1,9 +1,11 @@
#!/usr/bin/env python3
"""Regenerate the Trending PoCs table in README.md.
"""Regenerate the Trending PoCs tables in README.md.
- Only consider repositories whose names contain the current year's CVE pattern (e.g., CVE-2025-1234).
- Consider the latest 4 years (current year and previous 3).
- Require repository name to contain a CVE for that year (e.g., CVE-2025-1234).
- Require a non-empty description (we only want actual PoCs, not empty shells).
- Restrict to repositories updated in the last 4 days.
- Sort by most recently updated, then stars, and emit up to 20 rows.
- Sort by most recently updated, then stars, and emit up to 20 rows per year.
"""
from __future__ import annotations
@@ -18,6 +20,7 @@ import requests
WINDOW_DAYS = 4
MAX_ROWS = 20
YEARS_BACK = 4
class Repo(TypedDict):
@@ -50,8 +53,8 @@ def time_ago(updated_at: str, now: datetime) -> str:
return "just now"
def fetch_trending(current_year: int, cutoff: datetime) -> List[Repo]:
query = f"CVE-{current_year} in:name stars:>2 pushed:>={cutoff.date().isoformat()} archived:false"
def fetch_trending(year: int, cutoff: datetime) -> List[Repo]:
query = f"CVE-{year} in:name stars:>2 pushed:>={cutoff.date().isoformat()} archived:false"
url = "https://api.github.com/search/repositories"
params = {
"q": query,
@@ -63,12 +66,13 @@ def fetch_trending(current_year: int, cutoff: datetime) -> List[Repo]:
resp = requests.get(url, params=params, headers=github_headers(), timeout=30)
resp.raise_for_status()
items: Iterable[Repo] = resp.json().get("items", [])
pattern = re.compile(rf"cve-{current_year}-\d+", re.IGNORECASE)
pattern = re.compile(rf"cve-{year}-\d+", re.IGNORECASE)
filtered: List[Repo] = []
for item in items:
name = item.get("name", "")
updated_at = item.get("updated_at")
if not updated_at or not pattern.search(name or ""):
description = (item.get("description") or "").strip()
if not updated_at or not pattern.search(name or "") or not description:
continue
updated_dt = datetime.strptime(updated_at, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc)
if updated_dt < cutoff:
@@ -94,20 +98,21 @@ def main() -> None:
cutoff = datetime.now(timezone.utc) - timedelta(days=WINDOW_DAYS)
now = datetime.now(timezone.utc)
repos = fetch_trending(current_year, cutoff)
output: List[str] = ['<h1 align="center">Recently updated Proof-of-Concepts</h1>']
output.append(f"\n\n## {current_year}\n")
output.append(f"### Updated in the last {WINDOW_DAYS} days (up to {MAX_ROWS} repos)\n")
output.append("| Stars | Updated | Name | Description |")
output.append("| --- | --- | --- | --- |")
if repos:
output.extend(build_rows(repos, now))
else:
output.append("| 0⭐ | — | No recent CVE PoCs | No repositories matched the filters. |")
for year in range(current_year, current_year - YEARS_BACK, -1):
repos = fetch_trending(year, cutoff)
output.append(f"\n\n## {year}\n")
output.append(f"### Updated in the last {WINDOW_DAYS} days (up to {MAX_ROWS} repos)\n")
output.append("| Stars | Updated | Name | Description |")
output.append("| --- | --- | --- | --- |")
if repos:
output.extend(build_rows(repos, now))
else:
output.append("| 0⭐ | — | No recent CVE PoCs | No repositories matched the filters. |")
Path("README.md").write_text("\n".join(output), encoding="utf-8")
print(f"Wrote {len(repos)} rows for {current_year}")
print(f"Wrote tables for {YEARS_BACK} years ending {current_year}")
if __name__ == "__main__":