import ssl import socket weak_protocols = { "SSLv3": ssl.PROTOCOL_TLS_CLIENT, "TLSv1.0": ssl.PROTOCOL_TLSv1, "TLSv1.1": ssl.PROTOCOL_TLSv1_1, } weak_ciphers = ['RC4', 'DES', '3DES', 'EXPORT', 'NULL', 'MD5'] def test_protocols(hostname, port=443): print(f"Testowanie protokolow na {hostname}:{port}") for name, proto in weak_protocols.items(): try: context = ssl.SSLContext(proto) context.check_hostname = False context.verify_mode = ssl.CERT_NONE with socket.create_connection((hostname, port), timeout=5) as sock: with context.wrap_socket(sock, server_hostname=hostname) as ssock: used_version = ssock.version() used_cipher = ssock.cipher() print(f"Obsluguje {name}: uzyto {used_version}, szyfr: {used_cipher[0]}") except ssl.SSLError as e: print(f"{name} odrzucony: {e}") except Exception as e: print(f"Blad podczas testowania {name}: {e}") print() def test_ciphers(hostname, port=443): print(f"Testowanie slabych szyfrow na {hostname}:{port}") context = ssl.create_default_context() context.set_ciphers('ALL') context.check_hostname = False context.verify_mode = ssl.CERT_NONE try: with socket.create_connection((hostname, port), timeout=5) as sock: with context.wrap_socket(sock, server_hostname=hostname) as ssock: cipher = ssock.cipher()[0] if any(weak in cipher.upper() for weak in weak_ciphers): print(f"Wykryto slaby szyfr: {cipher}") else: print(f"Uzyty szyfr nie jest na liscie slabych: {cipher}") except Exception as e: print(f"Blad: nie udalo sie nawiazac polaczenia: {e}") print() def main(): host = input("Podaj nazwe hosta: ").strip() test_protocols(host) test_ciphers(host) if __name__ == "__main__": main()