commit 0b629c0a13d97e0560d6e2d9fab8d3f9e1aa5961 Author: Jakub Date: Fri Jul 4 08:02:19 2025 +0000 first commit diff --git a/ssl_test_final.py b/ssl_test_final.py new file mode 100644 index 0000000..16cf659 --- /dev/null +++ b/ssl_test_final.py @@ -0,0 +1,57 @@ +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() +