我禁用了 ASLR。好吧,我想获取环境变量“SHELL”的地址,所以我使用了 C 函数 getenv()。
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char* ptr = getenv("SHELL");
printf("%p\n", ptr);
}
通过getenv()获取的地址
$ ./getenv
0xbffff752
用gdb得到的地址:
gdb> x/4000s $esp
...
(gdb) x/s 0xbffff710
0xbffff710: "SHELL=/bin/bash"
(gdb) x/s 0xbffff716
0xbffff716: "/bin/bash"
为什么地址不同?如前所述,我必须说出使用 GDB 获得的正确地址。
最佳答案
Why the addresses are different?
因为一个在 gdb
下运行而另一个不是。在不同的环境下运行会导致不同的环境。字面意思。
在 gdb
下运行时,printf()
语句的输出是什么?
As note, I must say the correct address in the obtained with gdb.
该声明基于什么信息?
关于c - 获取环境变量地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31772163/