From 16ddd3fe7f9276a466b725aa9b2e9b97c8cc1cd5 Mon Sep 17 00:00:00 2001 From: Dominik Fuhrmann <dominik.fuhrmann1@gmail.com> Date: Wed, 18 Dec 2024 18:32:40 +0100 Subject: [PATCH] reworked structure --- .../client.c | 0 .../client.py | 0 .../server.c | 0 .../server.py | 0 decryption/camellia.py | 33 ------------------ decryption/rc4.py | 33 ------------------ decryptionScripts/aes-128bit.py | 34 +++++++++++++++++++ decryptionScripts/aes-256bit.py | 34 +++++++++++++++++++ .../blowfish-128bit.py | 16 +++++---- decryptionScripts/blowfish-64bit.py | 34 +++++++++++++++++++ .../3des.py => decryptionScripts/rc4-64bit.py | 22 ++++++------ decryptionScripts/rc4-8bit.py | 34 +++++++++++++++++++ decryptionScripts/twofish-128bit.py | 34 +++++++++++++++++++ decryptionScripts/twofish-256bit.py | 34 +++++++++++++++++++ readme.md | 19 +++++++++++ ...ate-creation.sh => certificateCreation.sh} | 0 setup/compilation_client.sh | 5 --- setup/compilation_server.sh | 5 --- setup/decryption.sh | 3 ++ ...nstallaltion.sh => wolfssInstallaltion.sh} | 0 20 files changed, 247 insertions(+), 93 deletions(-) rename {communication => communicationScripts}/client.c (100%) rename {communication => communicationScripts}/client.py (100%) rename {communication => communicationScripts}/server.c (100%) rename {communication => communicationScripts}/server.py (100%) delete mode 100644 decryption/camellia.py delete mode 100644 decryption/rc4.py create mode 100644 decryptionScripts/aes-128bit.py create mode 100644 decryptionScripts/aes-256bit.py rename decryption/blowfish.py => decryptionScripts/blowfish-128bit.py (67%) create mode 100644 decryptionScripts/blowfish-64bit.py rename decryption/3des.py => decryptionScripts/rc4-64bit.py (58%) create mode 100644 decryptionScripts/rc4-8bit.py create mode 100644 decryptionScripts/twofish-128bit.py create mode 100644 decryptionScripts/twofish-256bit.py create mode 100644 readme.md rename setup/{certificate-creation.sh => certificateCreation.sh} (100%) delete mode 100644 setup/compilation_client.sh delete mode 100644 setup/compilation_server.sh create mode 100644 setup/decryption.sh rename setup/{wolfssl-installaltion.sh => wolfssInstallaltion.sh} (100%) diff --git a/communication/client.c b/communicationScripts/client.c similarity index 100% rename from communication/client.c rename to communicationScripts/client.c diff --git a/communication/client.py b/communicationScripts/client.py similarity index 100% rename from communication/client.py rename to communicationScripts/client.py diff --git a/communication/server.c b/communicationScripts/server.c similarity index 100% rename from communication/server.c rename to communicationScripts/server.c diff --git a/communication/server.py b/communicationScripts/server.py similarity index 100% rename from communication/server.py rename to communicationScripts/server.py diff --git a/decryption/camellia.py b/decryption/camellia.py deleted file mode 100644 index ae8ae0e..0000000 --- a/decryption/camellia.py +++ /dev/null @@ -1,33 +0,0 @@ -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes -import itertools - -# Verschlüsselten Datenstrom laden -with open('encrypted_file_camellia.bin', 'rb') as f: - ciphertext = f.read() - -start_time = time.time() # Startzeit -# Brute-Force-Funktion für Camellia -def brute_force_camellia(ciphertext): - key_space = (bytes([k]) for k in range(2**8)) # 8-Bit Schlüsselraum zur Demo - target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt - for key in key_space: - try: - cipher = Cipher(algorithms.Camellia(key.ljust(16, b'\0')), modes.ECB()) - decryptor = cipher.decryptor() - plaintext = decryptor.update(ciphertext) - if target_pattern in plaintext: # Überprüfung des entschlüsselten Inhalts - print(f"Schlüssel gefunden: {key}") - print(f"Entschlüsselter Inhalt: {plaintext}") - return plaintext - except Exception as e: - continue - -end_time = time.time() -plaintext = brute_force_camellia(ciphertext) -if plaintext: - print("Datei erfolgreich entschlüsselt!") -else: - print("Kein gültiger Schlüssel gefunden.") - -duration = end_time - start_time -print(f"Dauer des Angriffs: {duration:.2f} Sekunden") \ No newline at end of file diff --git a/decryption/rc4.py b/decryption/rc4.py deleted file mode 100644 index efb6e80..0000000 --- a/decryption/rc4.py +++ /dev/null @@ -1,33 +0,0 @@ -from cryptography.hazmat.primitives.ciphers import Cipher, algorithms -import itertools - -# Verschlüsselten Datenstrom laden -with open('encrypted_file_rc4.bin', 'rb') as f: - ciphertext = f.read() - -start_time = time.time() # Startzeit -# Brute-Force-Funktion für RC4 -def brute_force_rc4(ciphertext): - key_space = (bytes([k]) for k in range(2**8)) # 8-Bit Schlüsselraum zur Demo - target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt - for key in key_space: - try: - cipher = Cipher(algorithms.ARC4(key), mode=None) - decryptor = cipher.decryptor() - plaintext = decryptor.update(ciphertext) - if target_pattern in plaintext: # Überprüfung des entschlüsselten Inhalts - print(f"Schlüssel gefunden: {key}") - print(f"Entschlüsselter Inhalt: {plaintext}") - return plaintext - except Exception as e: - continue - -end_time = time.time() -plaintext = brute_force_rc4(ciphertext) -if plaintext: - print("Datei erfolgreich entschlüsselt!") -else: - print("Kein gültiger Schlüssel gefunden.") - -duration = end_time - start_time -print(f"Dauer des Angriffs: {duration:.2f} Sekunden") \ No newline at end of file diff --git a/decryptionScripts/aes-128bit.py b/decryptionScripts/aes-128bit.py new file mode 100644 index 0000000..5b07618 --- /dev/null +++ b/decryptionScripts/aes-128bit.py @@ -0,0 +1,34 @@ +from Crypto.Cipher import AES +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_aes.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für AES mit 128-Bit Schlüssel +def brute_force_aes_128bit(ciphertext): + key_space = (bytes([k]) for k in range(256)) # Beispiel für 128-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = AES.new(key, AES.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_aes_128bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/aes-256bit.py b/decryptionScripts/aes-256bit.py new file mode 100644 index 0000000..ee4ba08 --- /dev/null +++ b/decryptionScripts/aes-256bit.py @@ -0,0 +1,34 @@ +from Crypto.Cipher import AES +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_aes.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für AES mit 256-Bit Schlüssel +def brute_force_aes_256bit(ciphertext): + key_space = (b''.join(k) for k in product(b'abc123', repeat=32)) # Beispiel für 256-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = AES.new(key, AES.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_aes_256bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryption/blowfish.py b/decryptionScripts/blowfish-128bit.py similarity index 67% rename from decryption/blowfish.py rename to decryptionScripts/blowfish-128bit.py index 0600f9f..7a8af87 100644 --- a/decryption/blowfish.py +++ b/decryptionScripts/blowfish-128bit.py @@ -1,32 +1,34 @@ from Crypto.Cipher import Blowfish from itertools import product +import time # Verschlüsselten Datenstrom laden with open('encrypted_file_blowfish.bin', 'rb') as f: ciphertext = f.read() start_time = time.time() # Startzeit -# Brute-Force-Funktion für Blowfish -def brute_force_blowfish(ciphertext): - key_space = (b''.join(k) for k in product(b'abc123', repeat=4)) # Demo: Schlüsselraum für 32-Bit + +# Brute-Force-Funktion für Blowfish mit 128-Bit Schlüssel +def brute_force_blowfish_128bit(ciphertext): + key_space = (b''.join(k) for k in product(b'abc123', repeat=16)) # Beispiel für 128-Bit Schlüsselraum target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt for key in key_space: try: cipher = Blowfish.new(key, Blowfish.MODE_ECB) plaintext = cipher.decrypt(ciphertext) - if target_pattern in plaintext: # Überprüfung des entschlüsselten Inhalts + if target_pattern in plaintext: print(f"Schlüssel gefunden: {key}") - print(f"Entschlüsselter Inhalt: {plaintext}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") return plaintext except Exception as e: continue end_time = time.time() -plaintext = brute_force_blowfish(ciphertext) +plaintext = brute_force_blowfish_128bit(ciphertext) if plaintext: print("Datei erfolgreich entschlüsselt!") else: print("Kein gültiger Schlüssel gefunden.") duration = end_time - start_time -print(f"Dauer des Angriffs: {duration:.2f} Sekunden") \ No newline at end of file +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/blowfish-64bit.py b/decryptionScripts/blowfish-64bit.py new file mode 100644 index 0000000..4f0531c --- /dev/null +++ b/decryptionScripts/blowfish-64bit.py @@ -0,0 +1,34 @@ +from Crypto.Cipher import Blowfish +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_blowfish.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für Blowfish mit 64-Bit Schlüssel +def brute_force_blowfish_64bit(ciphertext): + key_space = (bytes([k]) for k in range(256)) # Beispiel für 64-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = Blowfish.new(key, Blowfish.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_blowfish_64bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryption/3des.py b/decryptionScripts/rc4-64bit.py similarity index 58% rename from decryption/3des.py rename to decryptionScripts/rc4-64bit.py index 443b73d..b974976 100644 --- a/decryption/3des.py +++ b/decryptionScripts/rc4-64bit.py @@ -1,32 +1,34 @@ -from Crypto.Cipher import DES3 +from Crypto.Cipher import ARC4 from itertools import product +import time # Verschlüsselten Datenstrom laden -with open('encrypted_file_3des.bin', 'rb') as f: +with open('encrypted_file_rc4.bin', 'rb') as f: ciphertext = f.read() start_time = time.time() # Startzeit -# Brute-Force-Funktion für 3DES -def brute_force_3des(ciphertext): - key_space = (b''.join(k) for k in product(b'abc123', repeat=8)) # Demo: Schlüsselraum für 3DES + +# Brute-Force-Funktion für RC4 mit 64-Bit Schlüssel +def brute_force_rc4_64bit(ciphertext): + key_space = (b''.join(k) for k in product(b'abc123', repeat=8)) # Beispiel für 64-Bit Schlüsselraum target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt for key in key_space: try: - cipher = DES3.new(key, DES3.MODE_ECB) + cipher = ARC4.new(key) plaintext = cipher.decrypt(ciphertext) - if target_pattern in plaintext: # Überprüfung des entschlüsselten Inhalts + if target_pattern in plaintext: print(f"Schlüssel gefunden: {key}") - print(f"Entschlüsselter Inhalt: {plaintext}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") return plaintext except Exception as e: continue end_time = time.time() -plaintext = brute_force_3des(ciphertext) +plaintext = brute_force_rc4_64bit(ciphertext) if plaintext: print("Datei erfolgreich entschlüsselt!") else: print("Kein gültiger Schlüssel gefunden.") duration = end_time - start_time -print(f"Dauer des Angriffs: {duration:.2f} Sekunden") \ No newline at end of file +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/rc4-8bit.py b/decryptionScripts/rc4-8bit.py new file mode 100644 index 0000000..cb2fc4c --- /dev/null +++ b/decryptionScripts/rc4-8bit.py @@ -0,0 +1,34 @@ +from Crypto.Cipher import ARC4 +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_rc4.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für RC4 mit 8-Bit Schlüssel +def brute_force_rc4_8bit(ciphertext): + key_space = (bytes([k]) for k in range(256)) # 8-Bit Schlüsselraum (alle möglichen 1-Byte-Schlüssel) + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = ARC4.new(key) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_rc4_8bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/twofish-128bit.py b/decryptionScripts/twofish-128bit.py new file mode 100644 index 0000000..f03c70c --- /dev/null +++ b/decryptionScripts/twofish-128bit.py @@ -0,0 +1,34 @@ +from twofish import Twofish +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_twofish.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für Twofish mit 128-Bit Schlüssel +def brute_force_twofish_128bit(ciphertext): + key_space = (bytes([k]) for k in range(256)) # Beispiel für 128-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = Twofish.new(key, Twofish.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_twofish_128bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/decryptionScripts/twofish-256bit.py b/decryptionScripts/twofish-256bit.py new file mode 100644 index 0000000..3ecfd30 --- /dev/null +++ b/decryptionScripts/twofish-256bit.py @@ -0,0 +1,34 @@ +from twofish import Twofish +from itertools import product +import time + +# Verschlüsselten Datenstrom laden +with open('encrypted_file_twofish.bin', 'rb') as f: + ciphertext = f.read() + +start_time = time.time() # Startzeit + +# Brute-Force-Funktion für Twofish mit 256-Bit Schlüssel +def brute_force_twofish_256bit(ciphertext): + key_space = (b''.join(k) for k in product(b'abc123', repeat=32)) # Beispiel für 256-Bit Schlüsselraum + target_pattern = b"Das ist eine Text-Datei!" # Gesuchter Inhalt + for key in key_space: + try: + cipher = Twofish.new(key, Twofish.MODE_ECB) + plaintext = cipher.decrypt(ciphertext) + if target_pattern in plaintext: + print(f"Schlüssel gefunden: {key}") + print(f"Entschlüsselter Inhalt: {plaintext.decode()}") + return plaintext + except Exception as e: + continue + +end_time = time.time() +plaintext = brute_force_twofish_256bit(ciphertext) +if plaintext: + print("Datei erfolgreich entschlüsselt!") +else: + print("Kein gültiger Schlüssel gefunden.") + +duration = end_time - start_time +print(f"Dauer des Angriffs: {duration:.2f} Sekunden") diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..6271c02 --- /dev/null +++ b/readme.md @@ -0,0 +1,19 @@ +### Folder Structure + +- **Certificates** + - This folder contains the communication certificates that have been created. These certificates are generated by the `certificateCreation.sh` script located in the **Setup** folder + +- **CommunicationScripts** + - This folder includes the server and client scripts that build the end-to-end communication between the two Raspberry Pis + +- **EncryptedData** + - This folder stores the encrypted data collected during the communication between the two devices + +- **DecryptionScripts** + - This folder contains scripts designed to decrypt the collected binary data. These scripts process the encrypted data and inform if the enrcyption was successful or not + +- **Setup** + - This folder includes essential setup scripts and configuration files to prepare the environment: + - `certificateCreation.sh`: A script that generates all necessary certificates for secure communication + - `decryption.sh`: A script that installs the required libraries and dependencies needed to execute the decryption scripts + - `wolfsslInstallation`: A script to install and configure the `wolfSSL` library, which is used for secure communication between the devices diff --git a/setup/certificate-creation.sh b/setup/certificateCreation.sh similarity index 100% rename from setup/certificate-creation.sh rename to setup/certificateCreation.sh diff --git a/setup/compilation_client.sh b/setup/compilation_client.sh deleted file mode 100644 index 26d9c1c..0000000 --- a/setup/compilation_client.sh +++ /dev/null @@ -1,5 +0,0 @@ -# Compile client script -gcc -o client_program ../scripts/client.c -lwolfssl - -# start client -./client_program \ No newline at end of file diff --git a/setup/compilation_server.sh b/setup/compilation_server.sh deleted file mode 100644 index c96d210..0000000 --- a/setup/compilation_server.sh +++ /dev/null @@ -1,5 +0,0 @@ -# Compile server script -gcc -o server_program ../scripts/server.c -lwolfssl - -# start server -./server_program \ No newline at end of file diff --git a/setup/decryption.sh b/setup/decryption.sh new file mode 100644 index 0000000..5834a9a --- /dev/null +++ b/setup/decryption.sh @@ -0,0 +1,3 @@ +# Install dependencies for decryption scripts +pip install pycryptodome +pip install twofish \ No newline at end of file diff --git a/setup/wolfssl-installaltion.sh b/setup/wolfssInstallaltion.sh similarity index 100% rename from setup/wolfssl-installaltion.sh rename to setup/wolfssInstallaltion.sh -- GitLab