堆或 BSS 的内容
示例:覆盖文件指针
/* The following variables are stored in the BSS region */
static char buf[BUFSIZE], *tmpfile;
tmpfile = "/tmp/vulprog.tmp";
gets(buf); /* buffer overflow can happen here */
... Open tmpfile, and write to it .../tmp/vulprog.tmp。/etc/shadow,我们就可以使程序写入它。tmpfile的内存。通常,它指向了/tmp/vluprog.tmp字符串。使用缓冲区溢出漏洞,我们就可以将tmpfile的内容修改为0x903040,它就是字符串/etc/shadow的地址。之后,当程序使用tmpfile变量打开文件来写入时,它实际上打开了shadow文件。/etc/shadow?
/etc/shadow就储存在内存中。我们现在需要猜测它在哪里。示例:覆盖函数指针:
int main(int argc, char **argv) {
static char buf[16]; /* in BSS */
static int (*funcptr)(const char *str); /* in BSS */
funcptr = (int (*)(const char *str))goodfunc;
/* We can cause buffer overflow here */
strncpy(buf, argv[1], strlen(argv[1]));
(void)(*funcptr)(argv[2]);
return 0;
}
/* This is what funcptr would point to if we didn’t overflow it */
int goodfunc(const char *str) {
... ...
}int (*funcptr)(char *str))允许程序员动态修改被调用的函数。我们可以通过覆盖它的地址来覆盖函数指针,使之在执行时,它调用我们指向的函数。argv[]方式:将 Shellcode 储存在程序的参数中。这会使 Shellcode 储存在栈上。之后我们需要猜测它的地址(就像我们在栈溢出中那样)。这个方式需要可执行的栈。函数指针
atexit,函数指针就会由atexit储存在堆上,并且会在程序终止前调用。svc/rpc注册函数(librpc, libnsl以及其他)将回调函数储存在堆上。其它示例
crontab基于堆的溢出:长文件名的传递会溢出静态缓冲区。在内存中的缓冲区上面,我们拥有pwd结构,它储存用户名、密码、UID、GID,以及其他。通过覆盖pwd的 UID/GID 字段,我们可以修改权限,使crond使用它执行我们的crontab(只要他尝试执行我们的crontab)。这个脚本之后可以产生 Suid Root Shell,因为我们的脚本会使用 UID/GID 0 来执行。