[ARCH] Add secret scanner for audit/docs (0 hits)
This commit is contained in:
1 parent
a6953ab353
commit
b3bb51f8ae
1 file changed
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Scan audit exports and repo docs for key-like material; print paths only."""
|
||||
import argparse
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
PATTERNS = [
|
||||
re.compile(r"sk-[A-Za-z0-9]{20,}"),
|
||||
re.compile(r"ghp_[A-Za-z0-9]{20,}"),
|
||||
re.compile(r"AIza[0-9A-Za-z_-]{20,}"),
|
||||
re.compile(r"-----BEGIN (RSA|OPENSSH|PRIVATE) KEY-----"),
|
||||
re.compile(r"xox[baprs]-[A-Za-z0-9-]{10,}"),
|
||||
]
|
||||
|
||||
|
||||
def scan(path: Path):
|
||||
try:
|
||||
text = path.read_text(errors="ignore")
|
||||
except OSError:
|
||||
return False
|
||||
return any(p.search(text) for p in PATTERNS)
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("paths", nargs="*", default=["ops/audit", "docs"])
|
||||
args = ap.parse_args()
|
||||
root = Path("/root/buryan-infra")
|
||||
hits = []
|
||||
for raw in args.paths:
|
||||
base = root / raw
|
||||
if base.is_file():
|
||||
files = [base]
|
||||
else:
|
||||
files = [p for p in base.rglob("*") if p.is_file() and p.suffix.lower() in (".md", ".txt", ".json", ".yaml", ".yml", ".sh", ".py")]
|
||||
for p in files:
|
||||
if scan(p):
|
||||
hits.append(str(p.relative_to(root)))
|
||||
for h in hits:
|
||||
print(h)
|
||||
print("hits=%d" % len(hits))
|
||||
raise SystemExit(1 if hits else 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user