Skip to content

Instantly share code, notes, and snippets.

@black-dragon74
Created March 21, 2025 10:52
Show Gist options
  • Save black-dragon74/afe742cb1e030ffb62c764a5021ab042 to your computer and use it in GitHub Desktop.
Save black-dragon74/afe742cb1e030ffb62c764a5021ab042 to your computer and use it in GitHub Desktop.
A script to guess encryption key for JioFiber routers
#!/usr/bin/env python3
"""
Code is poetry; script by black-dragon74
Use this script to guess the encryption key for your JioFiber router.
You need to generate a backup and provide it as an input to this script.
The script will provide you the encryption key if it is successful, use ONLY that key
to re-encrypt the backup else JioFiber will fail to restore it.
All the required info like SSID and SERIAL are present on the back sticker of your router.
WARNING: Use this at your own risk!
"""
from itertools import permutations
import subprocess
import argparse
IN_FILE = ""
OUT_FILE = ""
SERIAL = ""
SSID = ""
ARGS: argparse.Namespace = argparse.Namespace()
def tryToEncrypt(hexKey):
p = subprocess.Popen(
[
"openssl",
"aes-128-cbc",
"-pass",
"pass:{}".format(hexKey),
"-in",
IN_FILE,
"-out",
OUT_FILE,
],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
output, _ = p.communicate()
output = output.decode()
returnCode = p.returncode
if returnCode == 0:
print("Successfully encrypted the file using key: {}".format(hexKey))
exit()
else:
print("Failed!")
print()
def tryToDecrypt(hexKey):
p = subprocess.Popen(
[
"openssl",
"aes-128-cbc",
"-d",
"-pass",
"pass:{}".format(hexKey),
"-in",
IN_FILE,
"-out",
OUT_FILE,
],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
output, _ = p.communicate()
output = output.decode()
returnCode = p.returncode
if returnCode == 0:
print("Success. Your password is: {}".format(hexKey))
print("You should keep it in a safe place.")
exit()
else:
print("Failed!")
print()
def tryKey(key):
p = subprocess.Popen(
["openssl", "enc", "-aes-128-cbc", "-k", key, "-P", "-nosalt"],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
output, _ = p.communicate()
output = output.decode()
startIndex = output.find("key=") + len("key=")
endIndex = output.find("\n", startIndex)
hexKey = output[startIndex:endIndex]
print("Trying to decrypt with key: {}".format(key))
tryToDecrypt(hexKey)
keyStrings = [
"1n0NaZQnC9oxcfwf",
"us4AQiJAgbj0Fmxq",
"NTqK8Ps5iFke8zrp",
"bfqerloC15y79WQZ",
"9gNzEbuDjtyT9Pyc",
"uuphsZuO92AZW5GJ",
"qdySWmmvYKdBcO53",
"Q7ODauKsxUAUtbR7",
"Kohgiem4joochei3",
"6f1D27JyLm70GUUu",
"zuFbKywMhJjVEhk3",
"6uMrt5ricsD1ABDh",
"iPjZ8bYm6s3uGYVf",
"QGwaPHx2K1rNDTmL",
"fJ7OeRF2TvqKdR30",
]
def useCombination(keyIndex):
x = [SERIAL, keyStrings[keyIndex], SSID]
perms = []
for i in range(1, len(x) + 1):
for c in permutations(x, i):
perms.append("".join(c))
for i in range(0, len(perms)):
raw = perms[i]
tryKey(raw)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="A script to guess encryption key and to use it for encrpyting and decrypting JioFiber backups",
epilog="Note: Use this at your own risk, the author is not responsible for any damage to your router.",
)
pg = parser.add_mutually_exclusive_group()
pg.add_argument(
"-e",
"--encrypt",
action="store_true",
help="Apply encryption on the input and save to output",
)
pg.add_argument(
"-d",
"--decrypt",
action="store_true",
default=True,
help="Apply decryption on the input and save to output",
)
parser.add_argument(
"-i",
"--input",
help="Input file name",
type=str,
required=True,
)
parser.add_argument(
"-o",
"--output",
help="Output file name",
type=str,
required=True,
)
parser.add_argument(
"-s",
"--serial",
help="The serial number of your JioFiber router (found on the back sticker)",
type=str,
required=True,
)
parser.add_argument(
"-w",
"--ssid",
help="The factory default Wi-Fi SSID of your router (without JioFiber- prefix)",
type=str,
required=True,
)
parser.add_argument(
"-k",
"--key",
help="The (optional) password to use for crypto operations, no guessing is done if this is present",
type=str,
)
ARGS = parser.parse_args()
IN_FILE = ARGS.input
OUT_FILE = ARGS.output
SERIAL = ARGS.serial
SSID = ARGS.ssid
# If encryption is requested, a password must be provided
# We cannot guess as we can encrypt using any password but JioFiber
# will be unable to decrypt it, unless we specify the correct password
if ARGS.encrypt:
if ARGS.key is None:
raise Exception("Please specify password using -k <password>")
tryToEncrypt(ARGS.key)
if ARGS.key:
tryKey(ARGS.key)
else:
for i in range(0, len(keyStrings)):
useCombination(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment