feat(activation): Add session protocol, record builder, and deletescript

Three post-exploit modules: drmHandshake session activation protocol
wrapping libimobiledevice, activation record plist builder with device
info fields, and iOS-version-specific deletescript for Setup.app
removal and activation record cleanup via AFC.

Files created:
- include/activation/session.h, src/activation/session.c
- include/activation/record.h, src/activation/record.c
- include/bypass/deletescript.h, src/bypass/deletescript.c

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
tr4m0ryp 2026-04-05 02:17:33 +02:00
parent 17fca828a5
commit f0eeac6fde
6 changed files with 856 additions and 0 deletions

View file

@ -0,0 +1,45 @@
/*
* record.h -- Activation record plist builder.
*
* Constructs activation record plists from device information. These
* records contain AccountToken, DeviceCertificate, FairPlayKeyData,
* UniqueDeviceCertificate, and related fields needed by the activation
* protocol.
*/
#ifndef RECORD_H
#define RECORD_H
#include <stdint.h>
#include <plist/plist.h>
#include "device/device.h"
/*
* record_build -- Build a complete activation record from device info.
* Returns a new plist dict containing all required activation fields.
* Caller must free with record_free() or plist_free().
* Returns NULL on error.
*/
plist_t record_build(const device_info_t *dev);
/*
* record_build_a12 -- Build an A12+ specific activation record.
* Uses the FActivation/drmHandshake variant with additional fields
* required for A12 and newer chipsets (SEP-aware activation).
* Returns a new plist dict, or NULL on error. Caller must free.
*/
plist_t record_build_a12(const device_info_t *dev);
/*
* record_to_xml -- Serialize an activation record to XML string.
* On success, *len is set to the byte length (excluding NUL).
* Returns a malloc'd string the caller must free, or NULL on error.
*/
char *record_to_xml(plist_t record, uint32_t *len);
/*
* record_free -- Free an activation record plist.
*/
void record_free(plist_t record);
#endif /* RECORD_H */

View file

@ -0,0 +1,61 @@
/*
* session.h -- drmHandshake session activation protocol.
*
* Wraps libimobiledevice's session-mode mobileactivation API for the
* drmHandshake protocol required since iOS 10.2+.
*
* Flow:
* 1. session_get_info() -> device session blob
* 2. session_drm_handshake() -> local handshake response
* 3. session_create_activation_info() -> activation info with session
* 4. session_activate() -> finalize activation
*/
#ifndef SESSION_H
#define SESSION_H
#include <plist/plist.h>
#include "device/device.h"
/*
* session_get_info -- Retrieve session info blob from device.
* Sends CreateTunnel1SessionInfoRequest via mobileactivation service.
* On success, *session_info is set to a new plist that the caller must
* free with plist_free().
* Returns 0 on success, -1 on error.
*/
int session_get_info(device_info_t *dev, plist_t *session_info);
/*
* session_drm_handshake -- Perform local drmHandshake using session info.
* In offline mode, constructs the handshake response locally from the
* session blob (CollectionBlob, HandshakeRequestMessage, UniqueDeviceID).
* On success, *handshake_response is set to a new plist dict containing
* FDRBlob, SUInfo, HandshakeResponseMessage, and serverKP.
* Caller must free with plist_free().
* Returns 0 on success, -1 on error.
*/
int session_drm_handshake(device_info_t *dev, plist_t session_info,
plist_t *handshake_response);
/*
* session_create_activation_info -- Create activation info with session.
* Sends CreateTunnel1ActivationInfoRequest using the handshake response
* to produce the activation info blob.
* On success, *activation_info is set to a new plist. Caller frees.
* Returns 0 on success, -1 on error.
*/
int session_create_activation_info(device_info_t *dev,
plist_t handshake_response,
plist_t *activation_info);
/*
* session_activate -- Finalize session-mode activation.
* Sends HandleActivationInfoWithSessionRequest with the activation record
* and handshake response. This completes the drmHandshake protocol.
* Returns 0 on success, -1 on error.
*/
int session_activate(device_info_t *dev, plist_t activation_record,
plist_t handshake_response);
#endif /* SESSION_H */

View file

@ -0,0 +1,65 @@
/*
* deletescript.h -- Post-bypass iOS cleanup operations.
*
* Performs iOS-version-specific cleanup after activation bypass:
* remove Setup.app, set PurpleBuddy done, purge activation records,
* and clear system caches. Uses AFC for all file operations.
*/
#ifndef DELETESCRIPT_H
#define DELETESCRIPT_H
#include "device/device.h"
typedef struct {
int ios_major;
int ios_minor;
int ios_patch;
} ios_version_t;
/*
* deletescript_parse_version -- Parse iOS version string into components.
* Accepts formats: "16.3.1", "17.0", "26.1". Missing components are 0.
* Returns 0 on success, -1 on error.
*/
int deletescript_parse_version(const char *version_str, ios_version_t *ver);
/*
* deletescript_run -- Run the full deletescript for the device.
* Auto-detects iOS version and runs all appropriate cleanup steps.
* Requires an active lockdown connection on the device.
* Returns 0 on success, -1 on error.
*/
int deletescript_run(device_info_t *dev);
/*
* deletescript_remove_setup_app -- Rename Setup.app to Setup.app.bak.
* Disables the activation lock setup screen on next boot.
* Returns 0 on success, -1 on error.
*/
int deletescript_remove_setup_app(device_info_t *dev);
/*
* deletescript_set_purplebuddy_done -- Set SetupDone=true in purplebuddy plist.
* Writes to /private/var/mobile/Library/Preferences/com.apple.purplebuddy.plist.
* Returns 0 on success, -1 on error.
*/
int deletescript_set_purplebuddy_done(device_info_t *dev);
/*
* deletescript_purge_activation_records -- Remove all activation records.
* Purges both /var/root/Library/Lockdown/activation_records/ and
* /var/mobile/Library/mad/activation_records/ directories.
* Returns 0 on success, -1 on error.
*/
int deletescript_purge_activation_records(device_info_t *dev);
/*
* deletescript_clear_caches -- Clear system caches.
* Removes cached activation and setup state that could interfere
* with the bypass persisting across reboots.
* Returns 0 on success, -1 on error.
*/
int deletescript_clear_caches(device_info_t *dev);
#endif /* DELETESCRIPT_H */