声明
本文字数:500
阅读时长:1分钟
附件/链接:点击查看原文下载
本文属于【狼组安全社区】原创奖励计划,未经许可禁止转载
由于传播、利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,狼组安全团队以及文章作者不为此承担任何责任。
狼组安全团队有对此文章的修改和解释权。如欲转载或传播此文章,必须保证此文章的完整性,包括版权声明等全部内容。未经狼组安全团队允许,不得任意修改或者增减此文章内容,不得以任何方式将其用于商业目的。
前言
开启全局的webview调试可以干很多事情,比如说可以调试微信小程序,可以调试APP中嵌入的webview。
IOS App 是否支持 WebInspector 是通过 entitlement 控制的。已知将 com.apple.security.get-task-allow
设置为 true
之后会允许调试 WebView。Xcode 编译出来的调试版本 App 都会带上这个 entitlement,这也是 lldb 真机调试必须的配置。
当在 iOS 设备与Mac进行连接且启用了 WebInspector 之后 ,在IOS上会出现一个 webinspectord
的服务进程。使用frida hook这个进程即可实现全局调试:
frida -U webinspectord -l webview.js
webview.js 代码如下:
const
SecTaskCopyValueForEntitlement = Module.findExportByName(
null
,
'SecTaskCopyValueForEntitlement'
);
const
CFRelease =
new
NativeFunction(Module.findExportByName(
null
,
'CFRelease'
),
'void'
, [
'pointer'
]);
const
CFStringGetCStringPtr =
new
NativeFunction(Module.findExportByName(
null
,
'CFStringGetCStringPtr'
),
'pointer'
, [
'pointer'
,
'uint32'
]);
const
kCFStringEncodingUTF8 =
0x08000100
;
const
expected = [
'com.apple.security.get-task-allow'
,
'com.apple.private.webinspector.allow-remote-inspection'
,
'com.apple.private.webinspector.allow-carrier-remote-inspection'
,
'com.apple.webinspector.allow'
];
Interceptor.attach(SecTaskCopyValueForEntitlement, {
onEnter
:
function
(
args
)
{
const
p = CFStringGetCStringPtr(args[
1
], kCFStringEncodingUTF8);
const
ent = Memory.readUtf8String(p);
if
(expected.indexOf(ent) >
-1
)
this
.shouldOverride =
true
},
onLeave
:
function
(
retVal
)
{
if
(!
this
.shouldOverride)
return
if
(!retVal.isNull())
CFRelease(retVal);
retVal.replace(ObjC.classes.NSNumber.numberWithBool_(
1
));
}
})
参考资料
ChiChou/GlobalWebInspect: Enable WebView remote inspector for every app (https://github.com/ChiChou/GlobalWebInspect)
越狱 iOS 全局开启 WebView 远程调试 (https://paper.seebug.org/555/)
原文始发于微信公众号(WgpSec狼组安全团队):IOS安全 webview hook 全局调试
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论