lab7: безопасность, mTLS, OpenBao и PKI lifecycle
This commit is contained in:
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Scan committed evidence for credentials, signed URLs and raw identifiers."""
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
PATTERNS = {
|
||||
'aws signature': re.compile(r'X-Amz-(?:Signature|Credential|Security-Token)='),
|
||||
'inline password': re.compile(r'(?i)(password|passwd|secret|token)\s*[=:]\s*["\']?[^\s"\']{6,}'),
|
||||
'url credentials': re.compile(r'://[^/\s:@]+:[^@\s]+@'),
|
||||
'private key': re.compile(r'BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY'),
|
||||
'bearer token': re.compile(r'Bearer\s+[A-Za-z0-9._-]{20,}'),
|
||||
}
|
||||
|
||||
def main():
|
||||
failures = []
|
||||
for path in (ROOT / 'evidence').rglob('*'):
|
||||
if not path.is_file() or path.suffix in {'.png', '.jpg', '.jpeg', '.webp'}:
|
||||
continue
|
||||
try:
|
||||
text = path.read_text(errors='replace')
|
||||
except OSError:
|
||||
continue
|
||||
for name, pattern in PATTERNS.items():
|
||||
for match in pattern.finditer(text):
|
||||
line = text[text.rfind('\n', 0, match.start()) + 1:text.find('\n', match.end())].strip()
|
||||
failures.append(f'{path.relative_to(ROOT)}: {name}: {line[:160]}')
|
||||
if failures:
|
||||
print('FAIL: evidence scanner found possible secrets/signatures')
|
||||
for item in failures:
|
||||
print(' ', item)
|
||||
return 1
|
||||
print('PASS: evidence has no obvious secrets, signed URLs or bearer tokens')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user