CreditTone / hooker

🔥🔥hooker是一个基于frida实现的逆向工具包。为逆向开发人员提供统一化的脚本包管理方式、通杀脚本、自动化生成hook脚本、内存漫游探测activity和service、firda版JustTrustMe、disable ssl pinning
Apache License 2.0
3.7k stars 934 forks source link

双进程反调试案例 #44

Open CreditTone opened 3 years ago

CreditTone commented 3 years ago

遇到一个app孵化了一个子进程,然后子进程又对父进程进行了trace。导致frida无法附加上去。

第一步:直接输入进程名发现,有两个相同的进程。(失败) Enter the need to attach package. : com.gome.eshopnew It's com.gome.eshopnew that you have attached app. Traceback (most recent call last): File "hooker.py", line 93, in attach online_session = rdev.attach(target) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 26, in wrapper return f(*args, *kwargs) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 156, in attach return Session(self._impl.attach(self._pid_of(target))) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 180, in _pid_of return self.get_process(target).pid File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 26, in wrapper return f(args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 110, in get_process raise _frida.ProcessNotFoundError("ambiguous name; it matches: %s" % ", ".join(["%s (pid: %d)" % (process.name, process.pid) for process in matching])) frida.ProcessNotFoundError: ambiguous name; it matches: com.gome.eshopnew (pid: 7661), com.gome.eshopnew (pid: 7743)

第二步:尝试通过进程号attach(失败) Enter the need to attach package. : 7661 It's 7661 that you have attached app. Traceback (most recent call last): File "hooker.py", line 91, in attach online_session = frida.core.Session(rdev._impl.attach(pid)) frida.PermissionDeniedError: unable to access process with pid 7661 due to system restrictions; try sudo sysctl kernel.yama.ptrace_scope=0, or run Frida as root

思考:仔细一想可能主进程已经被traceing了........

第三步:验证猜想 ~/hooker/com.gome.eshopnew$ adb shell 1|oxygen: su 1|oxygen: cat /proc/7661/status Name: m.gome.eshopnew State: S (sleeping) Tgid: 7661 Pid: 7661 PPid: 744 TracerPid: 7743 Uid: 10122 10122 10122 10122 Gid: 10122 10122 10122 10122 Ngid: 0 FDSize: 256 Groups: 3001 3002 3003 9997 50122 VmPeak: 2304804 kB VmSize: 2253688 kB

TracerPid果然是非0。这种情况需要想办法把孵化的那个子进程干掉,或者找到做ptrace的那个so硬改nop重打包安装。其他暂时没想到

crylg commented 3 years ago

mark. 持续关注 试了下直接杀子进程,主进程也被干掉了.

crylg commented 3 years ago

很奇怪,我的表现情况不一样 2746 真快乐 com.gome.eshopnew

1|root@x86:/ # cat /proc/2746/status
Name: e.eshopnew:gome TracerPid: 0 State: S (sleeping) Tgid: 2746 Ngid: 0 Pid: 2746 PPid: 1696 Uid: 10045 10045 10045 10045 Gid: 10045 10045 10045 10045 FDSize: 256 Groups: 3001 3002 3003 9997 50045 VmPeak: 1956020 kB VmSize: 1956020 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 216612 kB VmRSS: 148120 kB VmData: 449696 kB VmStk: 8196 kB VmExe: 16 kB VmLib: 108096 kB VmPTE: 484 kB VmPMD: 0 kB VmSwap: 0 kB Threads: 25 SigQ: 0/16136 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000001204 SigIgn: 0000000000000004 SigCgt: 40000002000096f8 CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000000000000000 Cpus_allowed: 3 Cpus_allowed_list: 0-1 voluntary_ctxt_switches: 421 nonvoluntary_ctxt_switches: 915

crylg commented 3 years ago

我这边TracerPid:0

crylg commented 3 years ago

抱歉,草率了,原来我的APP卡在了第一个界面. 没有执行后面的程序 我杀一次子进程,重启了模拟器,尽然 都 没办法 再正常打开这个app了

unemployed-denizen commented 3 years ago

好像有人之前写过解决方法,看这个: http://91fans.com.cn/post/antifridaoper/

oooodogecoin commented 3 years ago

好像有人之前写过解决方法,看这个:

http://91fans.com.cn/post/antifridaoper/

感谢。不过,我认为最终极的解决方案是hook安卓framewokr层把他孵化的子进程拦截掉。使得永远也ptrace不了自己,这样frida原操作就可以继续进行。安卓孵化子进程的套路比较固定,比较好弄。

junknet commented 3 years ago

通杀方案: 编译内核,关掉内核写入保护,内存管理单元下子系统下直接映射成物理地址(主要为了修改sys_call_table所在页表写入权限) 写个内核模块劫持sys_call_table 里面的hook ptrace中断调用 (参考rootkit技术)

shuai19980 commented 2 years ago

遇到一个应用程序启动了一个子进程,然后子进程又对父进程进行了。导致frida无法附加后续。

首次直接输入进程名发现,有两个相同的进程。(失败) 输入需要附加包。 : com.gome.eshopnew 您附加的应用程序是 com.gome.eshopnew。 回溯(最近一次调用): 文件“hooker.py”,第 93 行,在附加 online_session = rdev.attach(target) 文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site -packages/frida/core.py", line 26, in wrapper return f(*args, *kwargs) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/ frida/core.py”,第 156 行,在附加 返回 Session(self._impl.attach(self._pid_of(target))) 文件“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/站点包/frida/core.py”,第 180 行, return self.get_process(target).pid File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 26, in wrapper return f( args, **kwargs) 文件 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/frida/core.py", line 110, in get_process raise _frida.ProcessNotFoundError("ambiguous name; 它匹配: %s" % ", ".join(["%s (pid: %d)" % (process.name, process.pid) for process in matching])) frida.ProcessNotFoundError: ambiguous name; 它匹配:com.gome.eshopnew (pid: 7661), com.gome.eshopnew (pid: 7743)

第二步:尝试通过程序号attach(失败) 输入需要附加的包。 : 7661 您附加的应用程序是 7661。 回溯(最近一次通话): 文件“hooker.py”,第 91 行,在附加 online_session = frida.core.Session(rdev._impl.attach(pid)) frida.PermissionDeniedError:由于 pid 7661 无法访问进程系统限制;尝试sudo sysctl kernel.yama.ptrace_scope=0,或以 root 身份运行 Frida

思考:仔细一想可能主进程已经被追踪了......

第三步:猜验证想 ~/hooker/com.gome.eshopnew$ adb shell 1|oxygen: su 1|oxygen: cat /proc/7661/status Name: m.gome.eshopnew State: S (sleeping) Tgid: 7661 PID:7661 PPID:744 TracerPid:7743 发表于:10122 10122 10122 10122 GID:10122 10122 10122 10122 Ngid:0 FDSize:256个 群组:3001 3002 3003 9997 50122 VmPeak:2304804 KB VmSize:2253688 KB

TracerPid 果然是非0。这种情况需要想办法把创业的那个人子进程弄掉,或者找到做那个人的那个改版的那个所以硬p 重打包安装。

你怎么解决的这个问题啊

oooodogecoin commented 2 years ago

多进程防护 更为简单粗暴的方法:1. 首先通过ps找出孙子进程的pid,记为pid3;2. 查看/proc//task找出孙子进程所有的thread,通常是3个,并记录下他们的tid;3. 使用kill -19 将这些孙子线程挂起;4. gdb 主进程,顺利gcore 。

pangff commented 2 months ago

抱歉,草率了,原来我的APP卡在了第一个界面. 没有执行后面的程序 我杀一次子进程,重启了模拟器,尽然 都 没办法 再正常打开这个app了

问题解决了吗