侧信道检测APatchRoot

admin 2026-01-22 00:34:57 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 本文提出利用侧信道时间差检测APatchRoot的方案。针对APatch在内核Hooktruncate系统调用的机制,设计程序绑定CPU核心并对比触发后门深层代码与浅层代码的执行耗时。APatch环境下时间差异显著而正常环境下差异微小,据此可有效识别设备Root状态。 综合评分: 92 文章分类: 移动安全,安全工具,逆向分析,恶意软件


cover_image

侧信道检测APatch Root

原创

ru1n ru1n

网络空间威胁观察

2026年1月20日 22:48 上海

侧信道检测APatch Root

摘要

APatch在内核中HOOK了truncate(45号)系统调用,作为应用层请求ROOT权限的接口。如下是相关代码,它的含义如下:

  • • 挑选truncate作为后门调用, 安装HOOK
  • • 取调用的key与cmd参数, 如果参数校验通过, 进入后门调用, 否则进入正常调用
  • 后门系统调用代码

由此可以得出检验方法:

  1. 1. 设置key, cmd参数, 尽可能多的触发后门调用中的代码, 计算执行时间为T1
  2. 2. 设置key, cmd参数, 尽可能少的触发后门调用中的代码, 计算执行时间为T2
  3. 3. 在正常环境中, T1与T2应该接近, 因为都会触发truncate的参数检验提前返回
  4. 4. 在APatch环境中, T1与T2应该有较大相差值

实现细节

检测代码如下, 基本逻辑如下:

  • • 要将执行线程绑定到固定CPU核心上, 避免线程切换CPU核心产生影响
  • • 设置参数1为su, 参数2在1000-1005执行若干次, 计算时间T1
  • • 设置参数1为su, 参数2在994-999执行若干次, 计算时间T2
  • • 在APatch环境中, T1与T2存在较大差异, 因为T1会执行更多后门代码, T2在后门代码开头即会退出
  • • 在正常环境中, T1与T2基本无差异, 因为会在truncate函数入口处由于su文件不存在退出
#define _GNU_SOURCE

#include&nbsp;<sched.h>
#include&nbsp;<stdio.h>
#include&nbsp;<unistd.h>

static&nbsp;inline&nbsp;uint64_t&nbsp;get_ticks()&nbsp;{
&nbsp; uint64_t&nbsp;v;
&nbsp; asm&nbsp;volatile("isb; mrs %0, cntvct_el0; isb"&nbsp;:&nbsp;"=r"(v) : :&nbsp;"memory");
&nbsp; return&nbsp;v;
}

void&nbsp;bind_to_cpu(int&nbsp;cpu_id)&nbsp;{
&nbsp; cpu_set_t&nbsp;cpuset;
&nbsp; CPU_ZERO(&cpuset);
&nbsp; CPU_SET(cpu_id, &cpuset);

&nbsp; if&nbsp;(sched_setaffinity(0,&nbsp;sizeof(cpu_set_t), &cpuset) ==&nbsp;-1) {
&nbsp; &nbsp; perror("sched_setaffinity");
&nbsp; }&nbsp;else&nbsp;{
&nbsp; &nbsp; printf("Thread successfully bound to CPU %d\n", cpu_id);
&nbsp; }
}

int&nbsp;get_current_cpu()&nbsp;{
&nbsp; int&nbsp;cpu = sched_getcpu();
&nbsp; if&nbsp;(cpu ==&nbsp;-1) {
&nbsp; &nbsp; perror("sched_getcpu");
&nbsp; &nbsp; return&nbsp;-1;
&nbsp; }
&nbsp; return&nbsp;cpu;
}

uint64_t&nbsp;runner(int&nbsp;cmd)&nbsp;{
&nbsp; char&nbsp;buffer[3] =&nbsp;"su";

&nbsp; uint64_t&nbsp;t1 = get_ticks();
&nbsp; for&nbsp;(int&nbsp;i =&nbsp;0; i <&nbsp;10000; i++) {
&nbsp; &nbsp; syscall(45, buffer, cmd);
&nbsp; }
&nbsp; uint64_t&nbsp;t2 = get_ticks();
&nbsp; return&nbsp;t2 - t1;
}

int&nbsp;main(int&nbsp;argc,&nbsp;char&nbsp;*argv[])&nbsp;{
&nbsp; // 绑定cpu核心, 避免切换cpu核心对结果的影响
&nbsp; bind_to_cpu(0);

&nbsp; uint64_t&nbsp;d1 =&nbsp;0, d2 =&nbsp;0;
&nbsp; for&nbsp;(int&nbsp;i =&nbsp;0; i <&nbsp;5; i++) {
&nbsp; &nbsp; d2 += runner(0x999&nbsp;- i);
&nbsp; }
&nbsp; for&nbsp;(int&nbsp;i =&nbsp;0; i <&nbsp;5; i++) {
&nbsp; &nbsp; d1 += runner(0x1000&nbsp;+ i);
&nbsp; }
&nbsp; printf("Duration for cmd 0x1000: %lu tk\n", d1);
&nbsp; printf("Duration for cmd 0x500 : %lu tk\n", d2);
&nbsp; uint64_t&nbsp;diff = d1 > d2 ? d1 - d2 : d2 - d1;
&nbsp; printf("Delta percentage: %.2f%%\n",
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(double)diff / ((double)(d1 + d2) /&nbsp;2) *&nbsp;100.0);
&nbsp; return&nbsp;0;
}

如下图所示, APatch环境中T1 T2差异较明显, 正常环境中T1 T2差异不明显

APatch环境

正常环境


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:网络空间威胁观察 ru1n ru1n《侧信道检测APatch Root》

暗网泄露3亿美国活跃邮箱 网络安全文章

暗网泄露3亿美国活跃邮箱

文章总结: 文档披露暗网泄露3亿美国活跃邮箱数据,含姓名、电话、性别及出生日期等敏感信息。该数据约源自2023年,下载渠道不稳定,属于重大数据泄露事件。 综合评
评论:0   参与:  0