r/jailbreak • • Apr 12 '14
My own iOS 5 Jailbreak
I've been doing some research about iOS 5 and how it was exploited, based on my research I tried to do a custom jailbreak, I wanted some help with the userland part, you can help on github here is the link: https://github.com/spawncpy/spawn5 if I did anything wrong in the code, please correct it, thx
75
Upvotes
11
u/winocm_the_programme Developer Apr 13 '14 edited Apr 13 '14
First of all, why are you writing to 'libSystem.B.dylib'? Also, the getrlimit/setrlimit thing is an example bug that is introduced by patching the kernel (as mentioned in the iOS Hacker's Handbook).
The default evasi0n amfi.dylib also does not work on iOS 5.
Look at
/dev/bpf.Additionally, iOS 5 and previous OSes are much easier to exploit (thanks to something called the shared PMAP structure). iOS 6 introduces a feature called 'userland protection' which unmaps the user TTB and sets the kernel ASID to 0 (kernel_pmap's ASID). This feature effectively separates the userland and kernel. The only time they're reset back to the proper context is in copyin/copyout and also the first level exception handlers. (The current TTBs are stored in each process's
thread_tstruct.. which is stored in TPIDPRRW(sp?) (c13, c0, 4)).No one uses kernel TTE remapping though, that makes exploiting iOS way more trivial (only a 36-byte arbitrary write is needed, that's all.). Kernel TTE remapping is an architectural flaw, which is also.. kinda unpatchable because of the design architecture. Kernel is always loaded at the beginning of the physical RAM base and always creates N TTE entries for the virtual base that point to the physical base. Since the physical base always will remain static (as it is integrated into hardware), you just need to write TTE entries that correspond to that PA. This also bypasses user protect, as the TTE entries kernel pmap's TTE store are globally mapped (loaded in TTBR0) versus user entries (which are again umapped, stored in TTBR1, granularity is controlled by TTBCR to create an address space separation.). Oh by the way, did you know that the kernel pmap's TTE store never changes? The system TTE base is always 16kB (4 * 2 * PAGE_SIZE) after the top of kernel data (which is 1MB aligned iirc?). The address is found in boot_args, which has a struct definition of:
Though, there is the issue of writeback cache. No idea why evasi0n/co decide to use flush_dcache/invalidate_icache when the DCCIMVAC operation (c7, c14, 1) works equally as well and in less space (addresses must be aligned to cache line boundary, which is usually (address & ~(1 << 6)) or (address & ~(1 << 5))).
Additionally, always /always/ disable both fast interrupts and interrupts during kernel patching, as your thread may be preempted by another. Restore the CPSR after you're done patching and after cache invalidation (thanks Cortex-A8 errata!).
Whatever. No one really pays attention to technical things that effectively make life easier.
On a side note: The WataMote OP is very nice.
6
u/BlekShader iPhone 5S, iOS 10.2 Apr 13 '14
Just one word: amazing. Seriously, keep working on this, it's always nice to welcome new hackers :D
I've read on GitHub that you need r/w access. If you're planning to do the jailbreak just userland, you could just use evasi0n's shebang trick to remount the fs, as it should work on iOS 5. What do you think? :)
30
u/mrolive1 iPod touch 5th gen Apr 12 '14
The IOS jailbreaking scene could always use a new figure :)
48
u/Bashar-Assad iPhone 1st gen, iOS 10 Beta Apr 12 '14
I just want to say it's awesome what you're doing.
14
u/X-weApon-X iPhone 8 Plus, 16.3.1| Apr 13 '14
I wish I could help you but you are now one of the "Grate Gods" :) Well, maybe a Baby Grate God.
But I can and will encourage you to keep working on it, and I stumbled upon THIS about 3 days ago, it shows step by step how to get into iOS and exploit it- Doesn't apply to iOS 7.x, but it is very intresting:
http://media.blackhat.com/bh-us-11/Esser/BH_US_11_Esser_Exploiting_The_iOS_Kernel_Slides.pdf
1
u/We1etu1n Developer Apr 21 '14
call it #UnthreadedJB
1
u/totes_meta_bot Apr 21 '14
This thread has been linked to from elsewhere on reddit.
I am a bot. Comments? Complaints? Message me ^here. I don't read ^PMs!
-30
u/MRRutherford Apr 12 '14
...why iOS5 and not 7?....
-1
u/[deleted] Apr 13 '14
Okay I added the amfi.dylib I made filemover to move files And I added plist files for both jb and filemover binaries