Analyze SSL/TLS configuration and certificates.
| 11 | |
| 12 | class SSLAnalyzer(WebScannerModule): |
| 13 | """Analyze SSL/TLS configuration and certificates.""" |
| 14 | |
| 15 | name = "ssl" |
| 16 | description = "Analyze SSL/TLS certificates and configuration" |
| 17 | |
| 18 | WEAK_CIPHERS = [ |
| 19 | "RC4", "DES", "3DES", "MD5", "NULL", "EXPORT", "anon" |
| 20 | ] |
| 21 | |
| 22 | def __init__(self): |
| 23 | super().__init__() |
| 24 | |
| 25 | async def run(self, target: Target) -> ScanResult: |
| 26 | """Analyze SSL/TLS configuration.""" |
| 27 | result = self.create_result(target) |
| 28 | |
| 29 | host = self._extract_host(target.value) |
| 30 | port = 443 |
| 31 | self.logger.info(f"Analyzing SSL/TLS for {host}:{port}") |
| 32 | |
| 33 | try: |
| 34 | # Get certificate info |
| 35 | cert_info = await self._get_certificate(host, port) |
| 36 | if cert_info: |
| 37 | result.raw_data["certificate"] = cert_info |
| 38 | |
| 39 | result.add_finding( |
| 40 | title="Certificate Information", |
| 41 | description=f"Certificate issued to {cert_info.get('subject', 'Unknown')}", |
| 42 | severity=Severity.INFO, |
| 43 | data=cert_info, |
| 44 | ) |
| 45 | |
| 46 | # Check expiration |
| 47 | if cert_info.get("not_after"): |
| 48 | expiry = datetime.fromisoformat(cert_info["not_after"]) |
| 49 | days_until_expiry = (expiry - datetime.now()).days |
| 50 | |
| 51 | if days_until_expiry < 0: |
| 52 | result.add_finding( |
| 53 | title="Certificate Expired", |
| 54 | description=f"Certificate expired {abs(days_until_expiry)} days ago", |
| 55 | severity=Severity.CRITICAL, |
| 56 | ) |
| 57 | elif days_until_expiry < 30: |
| 58 | result.add_finding( |
| 59 | title="Certificate Expiring Soon", |
| 60 | description=f"Certificate expires in {days_until_expiry} days", |
| 61 | severity=Severity.MEDIUM, |
| 62 | ) |
| 63 | |
| 64 | # Check for self-signed |
| 65 | if cert_info.get("issuer") == cert_info.get("subject"): |
| 66 | result.add_finding( |
| 67 | title="Self-Signed Certificate", |
| 68 | description="Certificate appears to be self-signed", |
| 69 | severity=Severity.MEDIUM, |
| 70 | ) |
no outgoing calls
no test coverage detected