def main(): """Main function.""" build = None ios_version = None parser = parse_arguments() ivkey = parser.ivkey logging.info('Launching %s', sys.argv) json_data = ipsw_utils.get_json_data(parser.device) ios_version = parser.ios_version build = parser.build_id if build is None: # I assume you have at least specified # iOS version (eg : 10.2.1) build = ipsw_utils.get_build_id(json_data, ios_version) if parser.local is not True: logging.info("grabbing OTA file URL for %s/%s", parser.device, ios_version) fw_url = ipsw_utils.get_firmware_url(json_data, build) if fw_url is None: print("[w] could not get OTA url, trying with IPSW url") json_data = ipsw_utils.get_json_data(parser.device, "ipsw") build = ipsw_utils.get_build_id(json_data, ios_version, "ipsw") fw_url = ipsw_utils.get_firmware_url(json_data, build) if fw_url is None: print("[e] could not get IPSW url, exiting...") sys.exit(1) parser.img_file = ipsw_utils.grab_file(fw_url, parser.img_file) if parser.download is True: # Just download image file # won't decrypt return 0 magic, image_type = decrypt_img.get_image_type(parser.img_file) if parser.ip_addr is not None: print("[i] grabbing keys from gidaes server on %s:12345" % parser.ip_addr) kbag = decrypt_img.get_kbag(parser.img_file) print("[i] kbag : {}".format(kbag)) ivkey = decrypt_img.get_gidaes_keys(parser.ip_addr, kbag) magic = "img4" if ivkey is None and parser.ip_addr is None: ivkey = get_firmware_keys(parser.device, build, parser.img_file, image_type) init_vector = ivkey[:32] key = ivkey[-64:] print("[x] iv : %s" % init_vector) print("[x] key : %s" % key) decrypt_img.decrypt_img(parser.img_file, parser.img_file + ".dec", magic, key, init_vector) print("[x] done") return 0
def grab_key_from_pongo(img_file: str): """Send command and grab PongoOS output.""" print("[i] grabbing keys from PongoOS device") kbag = decrypt_img.get_kbag(img_file) print("[i] kbag : {}".format(kbag)) pongo.pongo_send_command(f"aes cbc dec 256 gid0 {kbag}") ivkey = pongo.pongo_get_key() return ivkey