1

是否可以在 OS X 上获得正在运行的进程的 ASLR 幻灯片?

我不想以某种方式禁用 ASLR(例如 like gdb),而是获得偏移量。

例子:

$ cat > test.c
#include <stdio.h>

int test(void) {
    return 42;
}

int main(void) {
    getchar();
    printf("%p: %d\n", test, test());
    return 0;
}
$ gcc test.c -o test

多次运行 test 将确认test()每次运行确​​实有不同的地址:

$ ./test
^D
0x104493e50: 42
$ ./test
^D
0x106fe8e80: 42

注意:查找幻灯片的方法不应该搜索进程的内存或以其他方式检查它,因为我需要一个适用于所有可执行文件的便携式解决方案。

4

2 回答 2

1

使用MachOView的源代码中的函数find_main_binaryget_image_sizefrom ,如果您有进程的 pid 并且您具有 root 权限,则可以获取进程的 ASLR 幻灯片,如下所示:Attach.mm

pid_t pid = ...;

mach_vm_address_t main_address;
if(find_main_binary(pid, &main_address) != KERN_SUCCESS) {
    printf("Failed to find address of header!\n");
    return 1;
}

uint64_t aslr_slide;
if(get_image_size(main_address, pid, &aslr_slide) == -1) {
    printf("Failed to find ASLR slide!\n");
    return 1;
}

printf("ASLR slide: 0x%llx\n", aslr_slide);

我把它做成了一个叫做get_aslr的小工具。

于 2013-09-19T18:51:21.740 回答
-2

不,那会破坏 ASLR 的目的。

于 2013-08-02T02:18:10.260 回答