Git Product home page Git Product logo

jelbreklib's Introduction

jelbrekLib

Give me tfp0, I give you jelbrek

Library with commonly used patches in open-source jailbreaks. Call this a (light?) QiLin open-source alternative.

Compiling:

./make.sh

Setup

  • Compile OR head over to https://github.com/jakeajames/jelbrekLib/tree/master/downloads and get everything there.
  • Link with jelbrekLib.dylib and include jelbrekLib.h
  • Call init_with_kbase() with tfp0, the kernel base and (optionally, leave NULL otherwise) a custom kernel execution function, as your first thing and term_jelbrek(), as your last

Issues

  • AMFID patch won't resist after app enters background. Fix would be using a daemon (like amfidebilitate) or injecting a dylib (iOS 11)

iOS 12 status

  • rootFS remount is broken. There is hardening on snapshot_rename() which can and has been (privately) bypassed, but it for sure isn't as bad as last year with iOS 11.3.1, where they made major changes. The only thing we need is figuring out how they check if the snapshot is the rootfs and not something in /var for example where snapshot_rename works fine. Use unc0ver's code if you need the remount, I will probably add it along some bigger update

Credits

  • xerub for the original patchfinding code
  • theninjaprawn for some patchfinders
  • xerub for the original trustcache injection technique
  • stek29 for nvramunlock & lock and hsp4 patch
  • theninjaprawn & Ian Beer for dylib injection
  • Luca Todesco for the original remount patch technique
  • Umang Raghuvanshi for the rename-APFS-snapshot remount idea
  • pwn20wnd for the oiriginal implementation of the rename-APFS-snapshot technique
  • AMFID dylib-less patch technique by Ian Beer reworked with the patch code from Electra's amfid_payload (stek29 & coolstar)
  • rootless-hsp4 idea by Ian Beer. Implemented on his updated async_wake exploit
  • Sandbox exceptions by stek29 (https://stek29.rocks/2018/01/26/sandbox.html) (& a few fixes by me for iOS 12+)
  • CSBlob patching with stuff from Jonathan Levin and xerub
  • Symbol finding (https://github.com/jakeajames/kernelSymbolFinder) & the CoreTrust bypass technique by me ;)
  • The rest of patches are fairly simple and shouldn't be considered property of anyone in my opinion. Everyone who has enough knowledge can write them fairly easily
  • sbingner for kerneldec

And, don't forget to tell me if I forgot to credit anyone!

jelbreklib's People

Contributors

geosn0w avatar jakeajames avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jelbreklib's Issues

Some question about bypassCodeSign()

Hi,Jake James
I copy one dylib to my app bundle, it signed by ldid2.
Then i use bypassCodeSign() to bypass all codesign checks for it.
Like this:
bypassCodeSign(path_of_dylib_at_bundle);
It just crash and no return.
I try sign the dylib with a legit cert, but It still crash.

OSVersion: iOS12.1

Code Typo?

Hi:
In jelbrek.m there is the following code snippet:

  if (rv || !S_ISREG(st.st_mode) || st.st_size < 0x4000) {
            printf("[-] Binary too big\n");
            return 3;
        }

Which I believe should be st.st_size > 0x4000

Stuck

Stuck at

[i] offsets selected for iOS 13.0 or above
[*] copying to /var/mobile/Containers/Data/Application/017BDE09-9DE3-4F75-A027-7A1F85A05AE1/Documents/22.03.20:18.30.25_kernelcache

used
init_with_kbase(tfp0, kbase, NULL);
uint64_t trustcache = Find_trustcache();

Failed to initialize patchfinder

Device: iPhone 7+, iOS 13.1.2
Jailbreak: Latest checkra1n

I built a small tool to learn more about kernel internals and wanted to use jelbrekLib to accomplish some tasks.
I am unable to initialize jelbrekLib though because of failing to initialize patchfinder. Is this an issue stemming from checkra1n or this library?

Here is the log of the tool when starting:

tfp0: 0x2507
Kernel slide: 0x1f104000
[*] Initializing jelbrekLib
[i] offsets selected for iOS 13.0 or above
[*] copying to /var/root/Documents/02.04.20:17.20.38_kernelcache
[+] Initialized KernelSymbolFinder
[-] Failed to initialize patchfinder
Initialization failed! ret: 3

Here is the main function of my tool (very simple code):

int main(int argc, char **argv) {
    printf("Start\n");
    
    get_tfp0();
    get_kaslr_slide();

    int ret = init_with_kbase(tfp0, 0xfffffff007004000 + kaslr_slide, NULL);

    if (ret != 0) {
        printf("Initialization failed! ret: %d\n", ret);
        return ret;
    }

    term_jelbrek();
    printf("Dealloc'd jelbrekLib\n");
    return 0;
}

KP in FindKernelBase()

Use the one in voucher_swap instead. It works fine.

I'm trying adapting voucher_swap to rootlessJB, Stucked in AMFI stage.

The trustbin method KP(of course), patchAMFI cannot set exception port
Logs:

[D] platform: iPhone8,1 16C101
[+] created 1024 pipes
[+] created 8000 ports
[+] sprayed 16777216 bytes to 1024 pipes in kalloc.16384
[+] created 3564 vouchers
[+] sprayed 315752448 bytes to 8 ports in kalloc.1024
[+] stashed voucher pointer in thread
...........................................................................................................................................................................
[+] sprayed 357924864 bytes of OOL ports to 4 ports in kalloc.32768
[+] recovered voucher port 0xf07 for freed voucher
[+] adding references to the freed voucher to change the OOL port pointer
[+] receiving the OOL ports will leak port 0x1ebf03
[+] received voucher port 0xf07 in OOL ports
[+] voucher overlapped at offset 0x5ae0
[+] received fake port 0xd07
[+] port is at pipe index 256
[+] got ip_requests at 0xffffffe01c4c9300
[+] fake port is at offset 5712
[+] base port is at 0xffffffe005d15650
[+] kernel_task is at 0xffffffe00026e1c0
[+] done! port 0xd07 is tfp0
[D] found kernel slide 0x0000000004e00000
	[*] Starting fun
[*] Initializing jelbrekLib
[i] offsets selected for iOS 12.0 or above
[+] Initialized patchfinder
[*] Unsandboxing pid 220
[*] copying to /var/mobile/Containers/Data/Application/A6F314E3-3541-4FB1-B46D-13601E5A67DB/Documents/31.01.19:13.16.21_kernelcache
[*] Sandboxing pid 220 with slot at 0xffffffe0058f3aa0
[i] Mach-o header at 0x1C0
[lzss] Opening /var/mobile/Containers/Data/Application/A6F314E3-3541-4FB1-B46D-13601E5A67DB/Documents/31.01.19:13.16.21_kernelcache for reading
[lzss] Opening /var/mobile/Containers/Data/Application/A6F314E3-3541-4FB1-B46D-13601E5A67DB/Documents/31.01.19:13.16.21_kernelcache.dec for writing
[+] Decompressed kernelcache!
[+] Initialized KernelSymbolFinder
[+] kexecute: got user client: 0x1ebf07
	[i] Kernel base: 0xfffffff00be04000
	[i] uid: 0

[*] Unsandboxing pid 220
	[+] Escaped sandbox!
	Wrote file 0x121e9eaf8
[-] Old host type: 0x80000000
[-] New host type: 0x80000004
[remap_kernel_task] kernel task at 0xffffffe00026e1c0
[*] vm_kernel_page_size: 4000
[+] allocated address: ffffffe000014000
[*] address to wire: ffffffe000014000
[*] vm_kernel_page_size: 4000
[+] allocated address: ffffffe00001c000
[*] address to wire: ffffffe00001c000
[remap_kernel_task] remapped successfully to 0xffffffe005a4e1c0
[remap_kernel_task] port kaddr: 0xffffffe005d158f0
[*] vm_kernel_page_size: 4000
[+] allocated address: ffffffe000024000
[*] address to wire: ffffffe000024000
	[*] Installing bootstrap...
......................................................
	[+] Installed bootstrap!
[*] amfid, it's your turn
[i] amfid's PID: 221
[*] Setting Entitlements...
[i] before: get-task-allow is 0x0
[i] after: get-task-allow is 0xffffffe00020e140
[*] Getting task port
[*] Got amfid's task port? :) 0x1e7907
[+] amfid_task_port = 0x1e7907
[+] AMFID_ExceptionPort = 0x1ec207
[-] Error setting amfid exception port: (os/kern) invalid argument
[*] About to search for the binary load address
[+] About to call mach_vm_region
[-] Failed to get the region: (os/kern) invalid argument
[i] Amfid load address: 0xffffffffffffffff
[amfid][-] Error reading MISVSACI: (os/kern) invalid argument
[*] Will trust /var/containers/Bundle/tweaksupport/usr/bin/inject_dylib
[*] trust_chain at 0xfffffff00aa78000

"init_with_kbase" will always fail due to missing sandbox escape.

In previous commits the order of the init_with_kbase function was changed.

Now the function will always fail, as the following code is called before a sandbox escape and root privilege escalation is executed and /System/Library/Caches/com.apple.kernelcaches/kernelcache is not readable inside the sandbox.

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    
    // random enough
    // let's say this is ran from an unsandboxed process
    // home dir is /var/mobile/Documents
    // there's a chance a file named kernelcache is there
    // who knows what people do XD, at least I have done it
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"dd.MM.YY:HH.mm.ss"];
    
    NSString *docs = [[[fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] path];
    mkdir((char *)[docs UTF8String], 0777);
    newPath = [docs stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_kernelcache", [formatter stringFromDate:[NSDate date]]]];
    
    printf("[*] copying to %s\n", [newPath UTF8String]);
    
    // create a copy to be safe
    [fileManager copyItemAtPath:@"/System/Library/Caches/com.apple.kernelcaches/kernelcache" toPath:newPath error:&error];
    if (error) {
        printf("[-] Failed to copy kernelcache with error: %s\n", [[error localizedDescription] UTF8String]);
        return 4;
    }

Some question about hidePath

I've read the source code and found the hidePath is setting VISSHADOW, which will affect vfs_lookup's behaviour.
But I'm wondering:

  1. Does it work with SYS_stat-based detection?
  2. Does it work with SYS_symlink-based detection?
  3. Does it work with opendir & readdir based detection?

Kernel Symbol finder

[] Initializing the jelbrekLib
[i] offsets selected for iOS 13.0 or above
[
] copying to /var/root/Documents/29.04.20:22.46.05_kernelcache
[+] Initialized KernelSymbolFinder
[+] Initialized patchfinder
[+] kexecute: got user client: 0x240b
[+] tfp0 = 0x9987
[+] kbase = 0xfffffff02104c000
[+] kslide = 0x000000001a048000
[+] trying to find _serial_putc
[i] MAGIC = 0xbebafeca
[!] Unrecognized file
[+] _serial_putc = 0xffffffffffffffff

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.