2025腾讯游戏安全竞赛Andorid决赛

准备工作

需求

image-20260406142720538

image-20260406142744624

image-20260406142757749

image-20260406142849360

效果

image-20260406142605218

寻找Gname

image-20260406143254382

0xADF07C0

寻找Gworld

通过Seamless定位

image-20260406143450754

0xAFAC398

寻找GObject

image-20260406143558237

0xAE34A98

SDKdump

1
2
3
4
./ue4dumper64 --strings --newue+ --gname 0xADF07C0 --package com.ACE2025.Game --output /data/local/tmp
./ue4dumper64 --objs --newue+ --gname 0xADF07C0 --guobj 0xAE34A98 --package com.ACE2025.Game --output /data/local/tmp
./ue4dumper64 --sdku --newue+ --gname 0xADF07C0 --guobj 0xAE34A98 --package com.ACE2025.Game --output /data/local/tmp --verbose
./ue4dumper64 --sdkw --newue+ --gname 0xADF07C0 --gworld 0xAFAC398 --package com.ACE2025.Game --output /data/local/tmp

ACEInject分析

主逻辑

sub_10BC/10DC/10F0/110C :初始化/注册函数,cxa_atexit 等基础设施

sub_1254来启动sub_111C线程

sub_111C:主hook线程:找libUE4.so基址 → mprotect → 写4字节补丁

image-20260406153100262

0x6711AC4在ue4的sub_6711A54里

image-20260406153916474

原始: 0x52A81408 → MOVZ W8, #0x40A0, LSL #16 → W8 = 0x40A00000

补丁: 0x52A85908 → MOVZ W8, #0x42C8, LSL #16 → W8 = 0x42C80000

两个值都是 MOVZ 指令,只是 imm16 不同。将结果解释为 IEEE 754 浮点数:

  • 0x40A00000 = 5.0f
  • 0x42C80000 = 100.0f

image-20260406154355054

1
2
3
4
BL  sub_6BBEC0C        ; 创建 SphereComponent
MOV W8, #0x40A00000 ; ← 被篡改!radius = 5.0
STR X0, [X19, #0x220] ; 存到 this->CollisionComp (SDK确认偏移)
STR W8, [X0, #0x460] ; 设置碰撞球半径
1
2
Class: MyProjectProjectile.Actor.Object
SphereComponent* CollisionComp; // [Offset: 0x220]

偏移0x220是 CollisionComp,SphereComponent + 0x460 是球体半径。函数功能确认为 MyProjectProjectile 构造函数,补丁将子弹碰撞球半径从5.0改为100.0。

最后读取 Zygisk 模块的安装脚本 customize.sh,确认

  • libGame.so 释放路径: /data/data/com.ACE2025.Game/
  • Zygisk模块 arm64-v8a.so 负责将 libGame.so 注入游戏进程

工具函数

sub_12D8:解析 /proc/self/maps 获取指定库的基址

image-20260406151800559

sub_1618:mprotect 封装,将目标内存改为RWX (权限=7)

image-20260406151852956

反调试

读 /proc/self/status 检查 TracerPid

image-20260406151936155

读 /proc/self/stat 检查PPID

image-20260406151959523

Frida检测

扫描 /proc/net/tcp 匹配Frida端口

image-20260406152103070

描 /proc/self/maps 找frida相关映射

image-20260406152121238

遍历 /proc/self/task/*/comm 找frida线程名

image-20260406152143557

Hook检测

用 dladdr 检查 fopen/dlsym/dlopen 是否被hook

image-20260406152934448

ACEInject 检测

因为测试时候Zygisk已开启,但是辅助似乎失败了模块已安装,但 libGame.so 没有被释放到游戏目录

只能手动释放,因此方案四其实对我这里是失效的,如果是正常的话应该是可以检测的

1
2
3
4
5
6
7
/data/adb/modules/TEST3/libGame.so存在   /data/data/com.ACE2025.Game/libGame.so  不存在
customize.sh 安装时应该把它 unzip 到游戏目录,但失败了。手动复制:
cp /data/adb/modules/TEST3/libGame.so /data/data/com.ACE2025.Game/libGame.so
chmod 644 /data/data/com.ACE2025.Game/libGame.so
chown $(stat -c %u:%g /data/data/com.ACE2025.Game/) /data/data/com.ACE2025.Game/libGame.so
然后强制关闭游戏再重新启动,再检查是否注入成功:
cat /proc/$(pidof com.ACE2025.Game)/maps | grep libGame

image-20260406164227643

方案一: 内存权限异常检测

任何通过 mprotect 修改代码段的外挂,都必须将 .text 段从 r-xp 改为 rwxp。正常应用的代码段永远不会同时具有写+执行权限。

读取 /proc/self/maps,对所有已加载的 .so 映射段 若权限为 rwxp(同时可写+可执行),则异常

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* ================================================================
* 检测1: 内存权限异常检测
*
* 原理: 正常 .so 代码段权限为 r-xp, 外挂通过 mprotect 改为 rwxp.
* 只检查非系统库, 排除 libc/linker 等正常 rwxp.
* ================================================================ */
static void detect_memory_permissions(void)
{
FILE *f = fopen("/proc/self/maps", "r");
if (!f) return;

char line[1024];
int detected = 0;

while (fgets(line, sizeof(line), f)) {
MapEntry e;
if (parse_maps_line(line, &e) < 0) continue;
if (e.path[0] == '\0' || !strstr(e.path, ".so")) continue;
if (is_system_lib(e.path)) continue;

if (strchr(e.perms, 'w') && strchr(e.perms, 'x')) {
log_write("MemPerm",
"DETECTED -- %s 地址 0x%lx-0x%lx 权限=%s",
e.path, e.start, e.end, e.perms);
detected = 1;
}
}
fclose(f);

if (!detected)
log_write("MemPerm", "PASS");
}

方案二:代码段完整性校验

检测过程:

  1. 从 /proc/self/maps 找到 libUE4.so 在内存中的地址和对应的磁盘文件路径
  2. 对代码段(.text,带 x 执行权限的段)按 4KB 页逐页比对
  3. 先算每页的 CRC32,快速判断是否一致
    4. CRC 不一致的页,再逐字节定位具体哪些字节被改了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ================================================================
* 检测2: 代码段完整性校验 (内存 vs 磁盘, CRC + 逐字节比对)
*
* 原理: 外挂修改内存中的代码段, 磁盘原文件未变.
* 按页 CRC32 快速定位, 不一致时逐字节报告差异.
* ================================================================ */

static void detect_code_integrity(const char *libname)
{
uintptr_t base;
char disk_path[512];

if (find_module_info(libname, &base, disk_path, sizeof(disk_path)) < 0) {
log_write("CodeInteg", "SKIP -- %s 未加载", libname);
return;
}

FILE *disk_fp = fopen(disk_path, "rb");
if (!disk_fp) {
log_write("CodeInteg", "WARN -- 无法打开磁盘文件: %s", disk_path);
return;
}

FILE *maps = fopen("/proc/self/maps", "r");
if (!maps) { fclose(disk_fp); return; }

char line[1024];
int tampered_pages = 0;
int tampered_bytes = 0;
int total_pages = 0;

uint8_t *disk_buf = (uint8_t *)malloc(PAGE_SIZE);
if (!disk_buf) { fclose(maps); fclose(disk_fp); return; }

while (fgets(line, sizeof(line), maps)) {
MapEntry e;
if (parse_maps_line(line, &e) < 0) continue;
if (!strstr(e.path, libname)) continue;
if (!strchr(e.perms, 'x')) continue;

size_t seg_size = e.end - e.start;

for (size_t off = 0; off < seg_size; off += PAGE_SIZE) {
size_t chunk = PAGE_SIZE;
if (off + chunk > seg_size) chunk = seg_size - off;

if (fseek(disk_fp, e.offset + off, SEEK_SET) != 0) break;
size_t nread = fread(disk_buf, 1, chunk, disk_fp);
if (nread != chunk) break;

const uint8_t *mem_ptr = (const uint8_t *)(e.start + off);

uint32_t disk_crc = crc32_calc(disk_buf, chunk);
uint32_t mem_crc = crc32_calc(mem_ptr, chunk);
total_pages++;

if (disk_crc != mem_crc) {
tampered_pages++;
for (size_t i = 0; i < chunk; i++) {
if (disk_buf[i] != mem_ptr[i]) {
uintptr_t vaddr = (e.start + off + i) - base;
log_write("CodeInteg",
"DETECTED -- %s+0x%lx "
"磁盘=0x%02x 内存=0x%02x "
"(页CRC: 磁盘=0x%08x 内存=0x%08x)",
libname, vaddr,
disk_buf[i], mem_ptr[i],
disk_crc, mem_crc);
tampered_bytes++;
}
}
}
}
}

free(disk_buf);
fclose(maps);
fclose(disk_fp);

if (tampered_pages == 0) {
log_write("CodeInteg",
"PASS -- %s 共 %d 页全部通过 CRC 校验",
libname, total_pages);
} else {
log_write("CodeInteg",
"SUMMARY -- %s %d/%d 页异常, %d 字节被修改",
libname, tampered_pages, total_pages, tampered_bytes);
}
}

方案三:异常模块加载检测

Zygisk 注入会将 libGame.so 等外挂模块映射进游戏进程。正常游戏进程不应该包含不在 APK 中的 .so 模块。

方法:
1. 读取 /proc/self/maps,提取所有已加载的 .so 路径
2. 建立白名单:APK 自带的 .so + 系统库(/system/lib64/, /vendor/lib64/ 等)
3. 不在白名单内的 .so → 可疑模块注入
4. 特别关注来自 /data/data/、/data/local/tmp/ 等路径的 .so

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* ================================================================
* 检测3: 异常模块加载检测
*
* 原理: 扫描 /proc/self/maps, 找出不在白名单内的 .so.
* ================================================================ */

static int is_whitelisted_path(const char *path)
{
if (path[0] == '\0' || path[0] == '[') return 1;

/* 系统路径 */
if (is_system_lib(path)) return 1;
if (strncmp(path, "/dev/", 5) == 0) return 1;
if (strncmp(path, "/proc/", 6) == 0) return 1;

/* 应用自身安装路径 */
if (strstr(path, "/data/app/") && strstr(path, "com.ACE2025.Game")) return 1;

/* Android 运行时 */
if (strstr(path, "dalvik")) return 1;
if (strstr(path, "boot")) return 1;
if (strstr(path, "framework")) return 1;

/* OAT/ART/VDEX/APK */
if (strstr(path, ".oat")) return 1;
if (strstr(path, ".art")) return 1;
if (strstr(path, ".vdex")) return 1;
if (strstr(path, ".apk")) return 1;

/* 检测库自身 */
if (strstr(path, "libAnswer.so")) return 1;

return 0;
}

static void detect_abnormal_modules(void)
{
FILE *f = fopen("/proc/self/maps", "r");
if (!f) return;

char line[1024];
int detected = 0;

char reported[32][512];
int reported_count = 0;

while (fgets(line, sizeof(line), f)) {
MapEntry e;
if (parse_maps_line(line, &e) < 0) continue;
if (e.path[0] == '\0') continue;
if (!strstr(e.path, ".so")) continue;

int dup = 0;
for (int i = 0; i < reported_count; i++) {
if (strcmp(reported[i], e.path) == 0) { dup = 1; break; }
}
if (dup) continue;

if (!is_whitelisted_path(e.path)) {
log_write("ModuleLoad",
"DETECTED -- 可疑模块: %s (0x%lx-0x%lx %s)",
e.path, e.start, e.end, e.perms);
detected = 1;
if (reported_count < 32) {
strncpy(reported[reported_count], e.path, 511);
reported[reported_count][511] = '\0';
reported_count++;
}
}
}
fclose(f);

if (!detected)
log_write("ModuleLoad", "PASS");
}

方案四:inotify 文件系统监控

使用 inotify 实时监控游戏数据目录, 当外挂向目录内创建/写入/移入 .so 文件时立即触发告警.ACEInject 的 customize.sh 会将 libGame.so 释放到/data/data/com.ACE2025.Game/ 目录下.

但是这里我们是手动释放的所以没效果 其实正常情况应该是生效的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
* ================================================================
* 检测4: inotify 文件系统监控
*
* 原理: 使用 inotify 实时监控游戏数据目录, 当外挂向目录内
* 创建/写入/移入 .so 文件时立即触发告警.
* ACEInject 的 customize.sh 会将 libGame.so 释放到
* /data/data/com.ACE2025.Game/ 目录下.
*
* 优势: 事件驱动, 不需要轮询, 比 maps 扫描更早发现文件投放.
* 应用对自己的 /data/data/ 目录有完整 inotify 权限.
* ================================================================ */

static void *inotify_thread(void *arg)
{
(void)arg;

int ifd = inotify_init();
if (ifd < 0) {
log_write("Inotify", "WARN -- inotify_init 失败: %s", strerror(errno));
return NULL;
}

/* 监控游戏数据目录 */
const char *watch_dirs[] = {
"/data/data/com.ACE2025.Game",
"/data/data/com.ACE2025.Game/files",
"/data/data/com.ACE2025.Game/cache",
"/data/local/tmp",
NULL
};

int wd_count = 0;
for (int i = 0; watch_dirs[i] != NULL; i++) {
int wd = inotify_add_watch(ifd, watch_dirs[i],
IN_CREATE | IN_MODIFY | IN_MOVED_TO | IN_CLOSE_WRITE);
if (wd >= 0) {
log_write("Inotify", "监控目录: %s (wd=%d)", watch_dirs[i], wd);
wd_count++;
}
}

if (wd_count == 0) {
log_write("Inotify", "WARN -- 没有可监控的目录");
close(ifd);
return NULL;
}

log_write("Inotify", "文件监控线程已启动, 监控 %d 个目录", wd_count);

char buf[INOTIFY_BUF_SIZE];

while (1) {
ssize_t len = read(ifd, buf, sizeof(buf));
if (len <= 0) break;

char *ptr = buf;
while (ptr < buf + len) {
struct inotify_event *event = (struct inotify_event *)ptr;

if (event->len > 0 && event->name[0] != '\0') {
/* 只关注 .so 文件 */
if (!strstr(event->name, ".so"))
goto next_event;

/* APK 内合法的 .so 白名单 */
static const char *legit_libs[] = {
"libAnswer.so",
"libUE4.so",
"libc++_shared.so",
"libOVRPlugin.so",
"libplaycore.so",
"libtry-alloc-lib.so",
"libvrapi.so",
NULL
};

int legitimate = 0;
for (int k = 0; legit_libs[k] != NULL; k++) {
if (strcmp(event->name, legit_libs[k]) == 0) {
legitimate = 1;
break;
}
}

if (!legitimate) {
const char *event_type = "未知";
if (event->mask & IN_CREATE) event_type = "创建";
if (event->mask & IN_MODIFY) event_type = "修改";
if (event->mask & IN_MOVED_TO) event_type = "移入";
if (event->mask & IN_CLOSE_WRITE) event_type = "写入完成";

log_write("Inotify",
"DETECTED -- 非法 .so 文件: %s [%s]",
event->name, event_type);
}
}

next_event:
ptr += sizeof(struct inotify_event) + event->len;
}
}

close(ifd);
log_write("Inotify", "文件监控线程退出");
return NULL;
}

效果

完整代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <stdint.h>
#include <stdarg.h>
#include <time.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/inotify.h>
#include <elf.h>
#include <dlfcn.h>
#include <errno.h>

/* ================================================================
* libAnswer.so -- 外挂检测库 (ACEInject + cheat)
*
* 检测方案:
* 1. 内存权限异常检测 -- .so 代码段出现 rwx 权限
* 2. 代码段完整性校验 -- 内存 vs 磁盘逐页 CRC + 逐字节比对
* 3. 异常模块加载检测 -- 非白名单 .so 被加载到进程
* 4. inotify 文件监控 -- 实时监控游戏目录的可疑文件写入
*
* 全部基于 /proc/self 和应用自身目录, 无需 root 权限
* 检测到外挂只记录日志, 不 kill 游戏进程
* ================================================================ */

#define LOG_DIR "/data/data/com.ACE2025.Game"
#define LOG_FILE LOG_DIR "/cheat_detection.log"
#define PAGE_SIZE 4096

/* inotify 事件缓冲区 */
#define INOTIFY_BUF_SIZE (1024 * (sizeof(struct inotify_event) + 256))

/* ======================== CRC32 ======================== */

static uint32_t g_crc32_tab[256];

static void crc32_init(void)
{
for (uint32_t i = 0; i < 256; i++) {
uint32_t c = i;
for (int j = 0; j < 8; j++)
c = (c >> 1) ^ (0xEDB88320u & (-(c & 1)));
g_crc32_tab[i] = c;
}
}

static uint32_t crc32_calc(const void *data, size_t len)
{
const uint8_t *p = (const uint8_t *)data;
uint32_t crc = 0xFFFFFFFF;
for (size_t i = 0; i < len; i++)
crc = (crc >> 8) ^ g_crc32_tab[(crc ^ p[i]) & 0xFF];
return crc ^ 0xFFFFFFFF;
}

/* ======================== Logging ======================== */

static pthread_mutex_t g_log_mutex = PTHREAD_MUTEX_INITIALIZER;

static void log_write(const char *detector, const char *fmt, ...)
{
pthread_mutex_lock(&g_log_mutex);
FILE *f = fopen(LOG_FILE, "a");
if (f) {
time_t now = time(NULL);
struct tm *tm_info = localtime(&now);
char timebuf[64];
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tm_info);

fprintf(f, "[%s][%s] ", timebuf, detector);
va_list ap;
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
fprintf(f, "\n");
fflush(f);
fclose(f);
}
pthread_mutex_unlock(&g_log_mutex);
}

/* ======================== Maps 解析工具 ======================== */

typedef struct {
uintptr_t start;
uintptr_t end;
char perms[8];
uintptr_t offset;
char path[512];
} MapEntry;

static int parse_maps_line(const char *line, MapEntry *e)
{
memset(e, 0, sizeof(*e));
char path_buf[512] = {0};
int n = sscanf(line, "%lx-%lx %7s %lx %*s %*d %511[^\n]",
&e->start, &e->end, e->perms, &e->offset, path_buf);
if (n < 4) return -1;

char *p = path_buf;
while (*p == ' ' || *p == '\t') p++;
strncpy(e->path, p, sizeof(e->path) - 1);
return 0;
}

static int find_module_info(const char *libname,
uintptr_t *out_base,
char *out_path, size_t path_size)
{
FILE *f = fopen("/proc/self/maps", "r");
if (!f) return -1;

char line[1024];
int found = 0;
*out_base = 0;
out_path[0] = '\0';

while (fgets(line, sizeof(line), f)) {
MapEntry e;
if (parse_maps_line(line, &e) < 0) continue;
if (!strstr(e.path, libname)) continue;
if (!found || e.start < *out_base) {
*out_base = e.start;
strncpy(out_path, e.path, path_size - 1);
out_path[path_size - 1] = '\0';
}
found = 1;
}
fclose(f);
return found ? 0 : -1;
}

/* ======================== 系统库判断 ======================== */

static int is_system_lib(const char *path)
{
if (strncmp(path, "/system/", 8) == 0) return 1;
if (strncmp(path, "/system_ext/", 12) == 0) return 1;
if (strncmp(path, "/vendor/", 8) == 0) return 1;
if (strncmp(path, "/apex/", 6) == 0) return 1;
if (strncmp(path, "/product/", 9) == 0) return 1;
if (strncmp(path, "/odm/", 5) == 0) return 1;
if (strstr(path, "linker")) return 1;
return 0;
}

/* ================================================================
* 检测1: 内存权限异常检测
*
* 原理: 正常 .so 代码段权限为 r-xp, 外挂通过 mprotect 改为 rwxp.
* 只检查非系统库, 排除 libc/linker 等正常 rwxp.
* ================================================================ */

static void detect_memory_permissions(void)
{
FILE *f = fopen("/proc/self/maps", "r");
if (!f) return;

char line[1024];
int detected = 0;

while (fgets(line, sizeof(line), f)) {
MapEntry e;
if (parse_maps_line(line, &e) < 0) continue;
if (e.path[0] == '\0' || !strstr(e.path, ".so")) continue;
if (is_system_lib(e.path)) continue;

if (strchr(e.perms, 'w') && strchr(e.perms, 'x')) {
log_write("MemPerm",
"DETECTED -- %s 地址 0x%lx-0x%lx 权限=%s",
e.path, e.start, e.end, e.perms);
detected = 1;
}
}
fclose(f);

if (!detected)
log_write("MemPerm", "PASS");
}

/* ================================================================
* 检测2: 代码段完整性校验 (内存 vs 磁盘, CRC + 逐字节比对)
*
* 原理: 外挂修改内存中的代码段, 磁盘原文件未变.
* 按页 CRC32 快速定位, 不一致时逐字节报告差异.
* ================================================================ */

static void detect_code_integrity(const char *libname)
{
uintptr_t base;
char disk_path[512];

if (find_module_info(libname, &base, disk_path, sizeof(disk_path)) < 0) {
log_write("CodeInteg", "SKIP -- %s 未加载", libname);
return;
}

FILE *disk_fp = fopen(disk_path, "rb");
if (!disk_fp) {
log_write("CodeInteg", "WARN -- 无法打开磁盘文件: %s", disk_path);
return;
}

FILE *maps = fopen("/proc/self/maps", "r");
if (!maps) { fclose(disk_fp); return; }

char line[1024];
int tampered_pages = 0;
int tampered_bytes = 0;
int total_pages = 0;

uint8_t *disk_buf = (uint8_t *)malloc(PAGE_SIZE);
if (!disk_buf) { fclose(maps); fclose(disk_fp); return; }

while (fgets(line, sizeof(line), maps)) {
MapEntry e;
if (parse_maps_line(line, &e) < 0) continue;
if (!strstr(e.path, libname)) continue;
if (!strchr(e.perms, 'x')) continue;

size_t seg_size = e.end - e.start;

for (size_t off = 0; off < seg_size; off += PAGE_SIZE) {
size_t chunk = PAGE_SIZE;
if (off + chunk > seg_size) chunk = seg_size - off;

if (fseek(disk_fp, e.offset + off, SEEK_SET) != 0) break;
size_t nread = fread(disk_buf, 1, chunk, disk_fp);
if (nread != chunk) break;

const uint8_t *mem_ptr = (const uint8_t *)(e.start + off);

uint32_t disk_crc = crc32_calc(disk_buf, chunk);
uint32_t mem_crc = crc32_calc(mem_ptr, chunk);
total_pages++;

if (disk_crc != mem_crc) {
tampered_pages++;
for (size_t i = 0; i < chunk; i++) {
if (disk_buf[i] != mem_ptr[i]) {
uintptr_t vaddr = (e.start + off + i) - base;
log_write("CodeInteg",
"DETECTED -- %s+0x%lx "
"磁盘=0x%02x 内存=0x%02x "
"(页CRC: 磁盘=0x%08x 内存=0x%08x)",
libname, vaddr,
disk_buf[i], mem_ptr[i],
disk_crc, mem_crc);
tampered_bytes++;
}
}
}
}
}

free(disk_buf);
fclose(maps);
fclose(disk_fp);

if (tampered_pages == 0) {
log_write("CodeInteg",
"PASS -- %s 共 %d 页全部通过 CRC 校验",
libname, total_pages);
} else {
log_write("CodeInteg",
"SUMMARY -- %s %d/%d 页异常, %d 字节被修改",
libname, tampered_pages, total_pages, tampered_bytes);
}
}

/* ================================================================
* 检测3: 异常模块加载检测
*
* 原理: 扫描 /proc/self/maps, 找出不在白名单内的 .so.
* ================================================================ */

static int is_whitelisted_path(const char *path)
{
if (path[0] == '\0' || path[0] == '[') return 1;

/* 系统路径 */
if (is_system_lib(path)) return 1;
if (strncmp(path, "/dev/", 5) == 0) return 1;
if (strncmp(path, "/proc/", 6) == 0) return 1;

/* 应用自身安装路径 */
if (strstr(path, "/data/app/") && strstr(path, "com.ACE2025.Game")) return 1;

/* Android 运行时 */
if (strstr(path, "dalvik")) return 1;
if (strstr(path, "boot")) return 1;
if (strstr(path, "framework")) return 1;

/* OAT/ART/VDEX/APK */
if (strstr(path, ".oat")) return 1;
if (strstr(path, ".art")) return 1;
if (strstr(path, ".vdex")) return 1;
if (strstr(path, ".apk")) return 1;

/* 检测库自身 */
if (strstr(path, "libAnswer.so")) return 1;

return 0;
}

static void detect_abnormal_modules(void)
{
FILE *f = fopen("/proc/self/maps", "r");
if (!f) return;

char line[1024];
int detected = 0;

char reported[32][512];
int reported_count = 0;

while (fgets(line, sizeof(line), f)) {
MapEntry e;
if (parse_maps_line(line, &e) < 0) continue;
if (e.path[0] == '\0') continue;
if (!strstr(e.path, ".so")) continue;

int dup = 0;
for (int i = 0; i < reported_count; i++) {
if (strcmp(reported[i], e.path) == 0) { dup = 1; break; }
}
if (dup) continue;

if (!is_whitelisted_path(e.path)) {
log_write("ModuleLoad",
"DETECTED -- 可疑模块: %s (0x%lx-0x%lx %s)",
e.path, e.start, e.end, e.perms);
detected = 1;
if (reported_count < 32) {
strncpy(reported[reported_count], e.path, 511);
reported[reported_count][511] = '\0';
reported_count++;
}
}
}
fclose(f);

if (!detected)
log_write("ModuleLoad", "PASS");
}

/* ================================================================
* 检测4: inotify 文件系统监控
*
* 原理: 使用 inotify 实时监控游戏数据目录, 当外挂向目录内
* 创建/写入/移入 .so 文件时立即触发告警.
* ACEInject 的 customize.sh 会将 libGame.so 释放到
* /data/data/com.ACE2025.Game/ 目录下.
*
* 优势: 事件驱动, 不需要轮询, 比 maps 扫描更早发现文件投放.
* 应用对自己的 /data/data/ 目录有完整 inotify 权限.
* ================================================================ */

static void *inotify_thread(void *arg)
{
(void)arg;

int ifd = inotify_init();
if (ifd < 0) {
log_write("Inotify", "WARN -- inotify_init 失败: %s", strerror(errno));
return NULL;
}

/* 监控游戏数据目录 */
const char *watch_dirs[] = {
"/data/data/com.ACE2025.Game",
"/data/data/com.ACE2025.Game/files",
"/data/data/com.ACE2025.Game/cache",
"/data/local/tmp",
NULL
};

int wd_count = 0;
for (int i = 0; watch_dirs[i] != NULL; i++) {
int wd = inotify_add_watch(ifd, watch_dirs[i],
IN_CREATE | IN_MODIFY | IN_MOVED_TO | IN_CLOSE_WRITE);
if (wd >= 0) {
log_write("Inotify", "监控目录: %s (wd=%d)", watch_dirs[i], wd);
wd_count++;
}
}

if (wd_count == 0) {
log_write("Inotify", "WARN -- 没有可监控的目录");
close(ifd);
return NULL;
}

log_write("Inotify", "文件监控线程已启动, 监控 %d 个目录", wd_count);

char buf[INOTIFY_BUF_SIZE];

while (1) {
ssize_t len = read(ifd, buf, sizeof(buf));
if (len <= 0) break;

char *ptr = buf;
while (ptr < buf + len) {
struct inotify_event *event = (struct inotify_event *)ptr;

if (event->len > 0 && event->name[0] != '\0') {
/* 只关注 .so 文件 */
if (!strstr(event->name, ".so"))
goto next_event;

/* APK 内合法的 .so 白名单 */
static const char *legit_libs[] = {
"libAnswer.so",
"libUE4.so",
"libc++_shared.so",
"libOVRPlugin.so",
"libplaycore.so",
"libtry-alloc-lib.so",
"libvrapi.so",
NULL
};

int legitimate = 0;
for (int k = 0; legit_libs[k] != NULL; k++) {
if (strcmp(event->name, legit_libs[k]) == 0) {
legitimate = 1;
break;
}
}

if (!legitimate) {
const char *event_type = "未知";
if (event->mask & IN_CREATE) event_type = "创建";
if (event->mask & IN_MODIFY) event_type = "修改";
if (event->mask & IN_MOVED_TO) event_type = "移入";
if (event->mask & IN_CLOSE_WRITE) event_type = "写入完成";

log_write("Inotify",
"DETECTED -- 非法 .so 文件: %s [%s]",
event->name, event_type);
}
}

next_event:
ptr += sizeof(struct inotify_event) + event->len;
}
}

close(ifd);
log_write("Inotify", "文件监控线程退出");
return NULL;
}

/* ================================================================
* 检测主线程 (检测1-3 轮询)
* ================================================================ */

static void run_all_detections(int round)
{
log_write("Main", "========== 第 %d 轮检测 ==========", round);

detect_memory_permissions();
detect_code_integrity("libUE4.so");
detect_abnormal_modules();

log_write("Main", "========== 第 %d 轮结束 ==========", round);
}

static void *detection_thread(void *arg)
{
(void)arg;
log_write("Main", "检测线程已启动, 等待 libUE4.so 加载...");

uintptr_t ue4_base = 0;
char ue4_path[512] = {0};
for (int i = 0; i < 120; i++) {
if (find_module_info("libUE4.so", &ue4_base, ue4_path, sizeof(ue4_path)) == 0) {
log_write("Main", "libUE4.so 已加载: base=0x%lx path=%s",
ue4_base, ue4_path);
break;
}
usleep(500000);
}

if (ue4_base == 0) {
log_write("Main", "WARN -- 等待超时, libUE4.so 未加载");
return NULL;
}

sleep(5);

/* 执行5轮检测 */
run_all_detections(1);
for (int round = 2; round <= 5; round++) {
sleep(10);
run_all_detections(round);
}

log_write("Main", "检测线程退出");
return NULL;
}

/* ================================================================
* 入口: .so 加载时自动执行
* ================================================================ */

__attribute__((constructor))
static void libAnswer_init(void)
{
crc32_init();
log_write("Main", "libAnswer.so 已加载, PID=%d", getpid());

/* 启动检测线程 (检测1-3: 轮询) */
pthread_t tid1;
if (pthread_create(&tid1, NULL, detection_thread, NULL) == 0)
pthread_detach(tid1);

/* 启动 inotify 线程 (检测4: 事件驱动) */
pthread_t tid2;
if (pthread_create(&tid2, NULL, inotify_thread, NULL) == 0)
pthread_detach(tid2);
}

其他文件:

Application.mk

1
2
APP_ABI      := arm64-v8a
APP_PLATFORM := android-24

Android.mk

1
2
3
4
5
6
7
8
9
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := Answer
LOCAL_SRC_FILES := libAnswer.c
LOCAL_LDLIBS := -llog -ldl
LOCAL_CFLAGS := -Wall -Wextra -O2
include $(BUILD_SHARED_LIBRARY)

编译命令

1
2
3
/mnt/d/AndroidNdk/android-ndk-r27d/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android30-clang \
-shared -fPIC -O2 -Wall \
-o libAnswer.so jni/libAnswer.c -ldl -llog

image-20260406170832031

Cheat分析

cheat 是一个独立的 ARM64 可执行文件,运行在游戏进程外部,通过以下方式实现外挂功能

sub_242078(进程发现)

  • 遍历 /proc/ 目录
  • 读取每个进程的 /proc/<pid>/cmdline
  • 匹配 “com.ACE2025.Game” 获取游戏 PID

image-20260406171502904

sub_243414远程内存读取

  • 解析 /proc/<pid>/maps 获取 libUE4.so 基址
  • 使用 process_vm_readv 系统调用直接读取游戏进程内存(不需要 ptrace)
  • 读取 UE4 引擎关键结构
  • 遍历对象数组搜索 “MyProjectCharacter”
  • 实现透视,通过 SurfaceComposerClient::createSurface 创建叠加窗口

sub_24CCBC:自瞄

  • 打开 /dev/uinput 创建虚拟触控设备
  • 注册 EV_SYN、EV_KEY、EV_ABS 等事件类型
  • 计算目标角度后通过虚拟设备注入触摸事件,实现自动瞄准

sub_24C958:触摸输入读取

  • 遍历 /dev/input/ 设备
  • 读取真实触屏事件,检测玩家开火动作

Cheat检测

懒得整了 重打包太麻烦了

2025 腾讯游戏安全大赛 mobile 决赛 wp - TLSN - 博客园

[原创] 2025騰訊遊戲安全大賽(安卓決賽)-Android安全-看雪安全社区|专业技术交流与安全研究论坛

看这款两篇博客即可

大致思路有

mincore检测

image-20260406180203559

两个关键系统调用:

madvise(addr, size, MADV_DONTNEED)

告诉内核:这块内存我暂时不用了,可以回收物理页。

  • 虚拟地址仍然有效
  • 物理 RAM 被释放
  • 下次访问时内核会从磁盘文件重新加载(对于 libUE4.so 这种文件映射)

mincore(addr, size, &vec)

查询:这块虚拟内存现在有没有物理页?”

  • vec & 1 == 1 → 在物理内存中(驻留)
  • vec & 1 == 0 → 不在物理内存中

T0: madvise(MADV_DONTNEED) → 释放物理页

此时 mincore 返回 0 (不驻留)

T1: 等待 500ms…

T2: mincore 检查

  • 返回 0 → 没人访问过 → PASS (无外挂)
  • 返回 1 → 有人访问了 → DETECTED

为什么能检测 process_vm_readv?

每个进程只能访问自己的内存,A 进程看不到 B 进程的数据,process_vm_readv 做了什么

1
2
3
4
5
6
7
8
9
// cheat 进程中的调用:
process_vm_readv(
game_pid, // 目标: 游戏进程的 PID
&local_buf, // 读到哪: cheat 自己的缓冲区
1,
&remote_addr, // 读什么: 游戏进程中的地址 (如 libUE4 + 0xAF64308)
1,
0
);

跨进程读内存的系统调用

cheat 在外部进程中循环调用

process_vm_readv(game_pid, …, libUE4_base + 0xAF64308, …)

这个系统调用在内核层面访问游戏进程的页表,读取目标地址的数据。如果该页不在物理内存,内核必须先从磁盘加载到 RAM,然后才能读取并返回给 cheat。

所以我们: madvise → 释放页面 → 物理 RAM 空了

cheat: process_vm_readv → 内核发现页不在 RAM → 从磁盘重新加载 → 页回到 RAM

我们mincore → 发现页又在 RAM 了 → 但我们没访问过它 → 有人在外部读!

需要去掉 UWorld UE4 引擎每帧都访问 UWorld(游戏世界的根对象),即使没有外挂

检测虚拟设备的名称与数目

在.so文件刚被加载的时候获取虚拟设备的数目与名称,之后每隔一段时间,检测虚拟驱动设备的数目与名称,当虚拟设备的数目增加且名称为 8 字节长度的时候,判定为外挂程序。

需要root权限

检测虚拟设备抓取

利用的是这个原理,cheat在启动过程中对某一虚拟设备进行了设备抓取。(dev/input)

inotify监控

inotify监控 /dev/input

事实上,通过监控 /dev/uinput 也能达到同样效果

需要在 Permissive 模式下才能执行,即需要提前开启setenforce 0

测到外挂后,向/data/ldata/com.ACE2025.Game/log.txt文件中写入 [inotify input check], find cheat xxx!

inotify 监控 /proc/self/maps

ACEInject检测中的 inotify监控方法