首页
社区
课程
招聘
[原创]task_for_pid使用权限的问题
发表于: 2013-12-29 14:45 12609

[原创]task_for_pid使用权限的问题

2013-12-29 14:45
12609
写了个修改进程内存数据的程序,需要用到task_for_pid函数。之前对一个进程内存搜索修改都没有问题,换了个进程就报错kern_failure
JerrysPhone:/home/jerry root# ./mscan 810
attach to process pid[810]
kr: 5
The_task: 0×0
这说明mscan程序不具备访问别的进程的权限
<key>task_for_pid-allow</key>
并且,这个被扫描报错的进程也没有主动开放被别的进程访问的能力
<key>get-task-allow</key>
作为调试工具,需要在签名是带上下面的entitlement,以便内核开放出功能
http://iphonedevwiki.net/index.php/Debugserver#Patching_for_process_attaching
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>com.apple.springboard.debugapplications</key>
<true/>
<key>get-task-allow</key>
<true/>
<key>task_for_pid-allow</key>
<true/>
<key>run-unsigned-code</key>
<true/>
</dict>
</plist>
如果去看gdb和memscan,都是具备这样的权限:
ldid -e /usr/bin/gdb
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>com.apple.springboard.debugapplications</key>
<true/>
<key>get-task-allow</key>
<true/>
<key>task_for_pid-allow</key>
<true/>
</dict>
</plist>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>com.apple.springboard.debugapplications</key>
<true/>
<key>get-task-allow</key>
<true/>
<key>task_for_pid-allow</key>
<true/>
</dict>
</plist>
root# ldid -e /usr/bin/memscan
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>com.apple.springboard.debugapplications</key>
<true/>
<key>get-task-allow</key>
<true/>
<key>task_for_pid-allow</key>
<true/>
<key>run-unsigned-code</key>
<true/>
</dict>
但我遇到的问题是说ldid -Sentitlement.xml app之后,运行就报Killed: 9,固件版本为6.1(10B142)
root# ./mscan 810
Killed: 9
这说明签名后的程序无法通过内核的校验。
OSX自带签名工具codesign的使用小结:
1. 使用codesign,首先需要产生自签名证书。
参考:《解决iOS上Killed 9 错误》
http://danqingdani.blog.163.com/blog/static/186094195201332210447261/
他创建了一个名为tanjiti的自签名证书
2. 签名一个程序的命令格式为:
codesign -fs <自签名证书> mach-o_file
例如:codesign -fs tanjiti sqlite3
3. 签名一个程序,并添加资格(Entitlements)文件:
codesign -fs <自签名证书> --entitlements <资格文件> mach-o_file
4. 查看签名程序的资格(Entitlements),可以用下面的命令,注意有一个“-”
codesign -d --entitlements - /Applications/Whatever.app/
5. 另外我看到一种代--resource-rules的使用方式
codesign --force --sign <自签名证书> --resource-rules=ResourceRules.plist --entitlements ent.xml mach-o_file
显然
--force等价于-f
--sign等价于-s
--force --sign等价于-fs
我用上面第3种方式来签名同样遇到Killed: 9的问题。用第2种方式回到kern_failure的问题。这样看和ldid的效果一致。
因为开始说到“之前对一个进程内存搜索修改都没有问题”,于是聚焦到这个进程,把entitlements拿出来一看,发现有:
<key>get-task-allow</key><true/>
所以找到出现kern_failure问题的mach-o文件,entitlements内容如下:
<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>keychain-access-groups</key>
<array>
<string>LHH6UF568H.com.wanmei.mtheroes</string>
</array>
<key>application-identifier</key>
<string>LHH6UF568H.com.wanmei.mtheroes</string>
<key>aps-environment</key>
<string>production</string>
</dict>
</plist>
做如下修改:
-                <string>production</string>
-
+                <string>development</string>
+                <key>get-task-allow</key>
+                <true/>
保存成资格文件ent.xml,然后签名:
codesign -fs <自签名证书> --entitlements ent.xml mach-o_file
这样kern_failure的问题针对这个mach-o_file解决了。

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (3)
雪    币: 1098
活跃值: (193)
能力值: (RANK:210 )
在线值:
发帖
回帖
粉丝
2
我记得kern_failure跟越狱工具也有关系的。
有的越狱工具对内核签名验证的地方进行了patch,不签名直接运行gcc编译生成的可执行文件也是没有问题的。
而没对内核签名验证的地方进行patch的越狱工具,不签名是不能直接运行的。
2013-12-29 16:02
0
雪    币: 174
活跃值: (205)
能力值: ( LV6,RANK:80 )
在线值:
发帖
回帖
粉丝
3
以前也写过类似的内存工具,主要是完成fuzzy搜索,过程中也碰到了楼主的Killed: 9问题,回头试试看能不能解决。谢谢楼主分享!
2013-12-29 19:48
0
雪    币: 218
活跃值: (459)
能力值: ( LV12,RANK:290 )
在线值:
发帖
回帖
粉丝
4
fixed by add:
<key>proc_info-allow</key>
参考:
http://www.newosxbook.com/src.jl?tree=listings&file=12-1-vmmap.c
2014-5-12 17:26
0
游客
登录 | 注册 方可回帖
返回
//