【发布时间】:2022-02-08 04:32:26
【问题描述】:
我想知道在 bash 脚本中对 open(2) 进行了哪些调用。
我编写了以下拦截系统调用的程序:
#include <fcntl.h>
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#define DYLD_INTERPOSE(_replacment,_replacee) \
__attribute__((used)) static struct{ const void* replacment; const void* replacee; } _interpose_##_replacee \
__attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacment, (const void*)(unsigned long)&_replacee };
static
int
my_open(const char *filename, int oflag, mode_t mode)
{
printf("$jason$ open: %s\n", filename);
return open(filename, oflag, mode);
}
DYLD_INTERPOSE(my_open, open)
然后我使用:
clang -dynamiclib libfile.c -o libfile.dylib
export DYLD_INSERT_LIBRARIES=libfile.dylib
touch /tmp/testingtesting
它不起作用。
我用我编译的程序试了一下,效果很好。我用 brew 编译的程序试了一下,效果很好。我阅读了touch.c 的源代码。它调用open(2)。
然后我禁用了 SIP,它运行良好。因此,我得出结论认为是 SIP 导致了问题。不过我不想禁用 SIP。
我该怎么办?我正在考虑只允许 dtrace:csrutil enable --without dtrace。因为我认为 dtrace 可以跟踪系统调用,但我不确定这是否是一个安全的选择。
【问题讨论】:
标签: c bash macos system-calls dtrace