首页
社区
课程
招聘
[原创]内核开发系列5 - 通过QEMU或Corellium内核开发,并了解checkra1n的pongoOS
2021-12-18 12:19 21783

[原创]内核开发系列5 - 通过QEMU或Corellium内核开发,并了解checkra1n的pongoOS

2021-12-18 12:19
21783

checkra1n因为使用的是不可修复的BootROM漏洞checkm8,从长远考虑,使用checkm8进行自定义越狱开发.
checkra1n使用的pongoOS已经开源,所以只要修改pongoOS就可以自定义越狱:pongoOS

 

但在使用pongoOS之前,需要了解一些基础知识,不然无法读懂代码并修改.


基础知识之iPhone启动过程:

iPhone启动过程

 

更多checkra1n分析可以参考checkm基因组_checkm8漏洞利用的技术分析


基础知识之ARM64执行环境:

ARM64执行环境
更多ARM64执行环境分析可以参考《TrustZone for Armv8-A》阅读笔记


EL0 用户App运行所在的层,内存地址小于0x8000000000000000,通过SVC(supervisor call) 调用 EL1
-
EL1 内核主要运行所在的层,内存地址大于0x8000000000000000(int64有符号即为负数),一般0xFFFFFFFFXXXXXXXX,通过HVC(hypervisor call) 调用 EL12
-
EL2 通过SMC(Secure monitor Call)调用EL3(iPhone没有到有EL2分层,也就是没看到有EL1主动调用EL2,EL3)
-
EL3 运行内核监控Kernel Patch Protection(KPP)
-
通过真机是难以进行内核开发调试的,不断重启手机也会损伤手机,也耗费更多的时间.所要有PC上可以调试的环境.一般可以通QEMU或Corellium(收费)进行调试.

内核开发系列3-基于QEMU和iBoot泄露源码内核开发调试

暂无时间写.请自行查资料

内核开发系列4-基于Corellium内核开发调试

暂无时间写.请自行查资料

了解checkra1n的pongoOS

BootROM在DFU时才会被调用.一般启动是直接走iBoot. iBoot最开始的才会进行分层,所以只有在EL3启动前,对内核EL1修改时,KPP才不会导致设备重启.所以checkra1n的pongoOS是在iBoot启动前.

 

使用checkm8获得权限并上传pongoOS后,pongoOS入口点src/boot/entry.S

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
.globl start
.align 4
start:
// branch from x27 will end up here
    mov x9, x8
// branch from x29 here
    adr x4, start
    mov x5, #0x800000000
    movk x5, #0x1800, lsl#16
    and x30, x30, 0x4
    orr x30, x30, x5
    cmp x4, x5
    b.eq start$l0
    add x6, x4, #0x200000
 
...
 
start$l0:
    mov x1, x0
    mov x0, x9
    mov x29, xzr
    bl _set_exception_stack_core0
    bl _set_execution_stack_core0
    bl _trampoline_entry ***调用/src/boot/stage3.c的trampoline_entry*
    b .

/src/boot/stage3.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
void trampoline_entry(void* boot_image, void* boot_args)
{
    extern uint64_t __bss_start[] __asm__("section$start$__DATA$__common"),
                    __bss_end[] __asm__("segment$end$__DATA");
    if (__bss_start[0] == 0x746F6F626F747561) {
        uint32_t autoboot_sz = (uint32_t)(__bss_start[1]);
        extern volatile void smemcpy128(void*,void*,uint32_t);
        smemcpy128 ((void*)0x818e00000, __bss_start, (autoboot_sz + 64)/16);
        __bss_start[0] = 0;
    }
 
    if (!boot_args) {
        // bootloader
        strcpy(boot_image + 0x200, "Stage2 KJC Loader");
        patch_bootloader(boot_image);
    } else {
 
        gboot_args = boot_args;
        gboot_entry_point = boot_image;
        extern volatile void setup_el1(void * entryp,uint64_t,uint64_t);
 
 
        extern volatile void smemset(void*, uint8_t, uint64_t);
        smemset(&__bss_start, 0, ((uint64_t)__bss_end) - ((uint64_t)__bss_start));
        extern void main (void);
        setup_el1(main, (uint64_t)boot_image, (uint64_t)boot_args); //进入/src/boot/main.c
    }
    jump_to_image((uint64_t)boot_image, (uint64_t)boot_args);
}

更多待更新...


 

内核开发系列
内核开发系列1 - 从越狱隐藏到自定义越狱
内核开发系列2-硬件及内核基础知识
内核开发系列3-基于QEMU和iBoot泄露源码内核开发调试
内核开发系列4-基于Corellium内核开发调试
内核开发系列5 - 从checkra1n了解Kernel Patch

 

更多待更新...


 

原创内容,转载或内核开发交流可Q: 3#1#0#4#1#9#0#6#2 (倒序)



[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

最后于 2022-2-7 19:15 被alice编辑 ,原因:
收藏
点赞1
打赏
分享
最新回复 (1)
雪    币: 5485
活跃值: (3247)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
尐进 2022-1-29 16:55
2
0
mark 期望能看到更多的内核开发教程
游客
登录 | 注册 方可回帖
返回