IOT Connect
Hello everyone , In this blog post , I will try to explain my solution steps for IOT Connect challenge from Mobile Hacking Lab Platform . i hope it will be useful for you

image.png 



from Crypto.Cipher import AES import base64 encrypted_text = 'OSnaALIWUkpOziVAMycaZQ==' # The base64 encoded string from the Java code def create_key_from_number(num): """ Create a 16-byte key from a number by converting it to a byte array and padding with zeros to ensure the key length is 16 bytes. """ key = str(num).encode('utf-8') # Convert number to bytes key = key.ljust(16, b'\0') # Pad the key to 16 bytes if it's shorter return key def attempt_decrypt(encrypted_text, key): """ Attempt to decrypt the encrypted text using the provided key. Returns the decrypted text if successful, or None if decryption fails. """ cipher = AES.new(key, AES.MODE_ECB) try: decrypted_bytes = cipher.decrypt(base64.b64decode(encrypted_text)) decrypted_text = decrypted_bytes.decode('utf-8').strip() return decrypted_text except (ValueError, UnicodeDecodeError): return None def brute_force_decrypt(encrypted_text): """ Brute-force attempt to find the correct key for AES decryption. Searches for a key that produces meaningful output, like "master_on". """ for num in range(1000): key = create_key_from_number(num) decrypted_text = attempt_decrypt(encrypted_text, key) if decrypted_text and "master_on" in decrypted_text: print(f"Decrypt success and the key is {num}") print(f"Decrypted text: {decrypted_text}") return print("No valid key found") # Start the brute-force decryption attempt brute_force_decrypt(encrypted_text)

Last updated