◆ 通过覆盖.dtors进行缓冲区溢出攻击
作者:Juan M. Bello Rivas
整理:warning3
主页:
日期:2000-12-14
介绍:
-----
本文简要介绍了一种获取C程序(此程序应当是用gcc编译的)执行流程控制
的技术。本文假设读者熟悉普通的缓冲区溢出技术以及ELF文件格式。缓冲区溢出攻击
鸣谢:
------
感谢ga和dvorak的有趣讨论。
综述:
--------
gcc为函数提供了几种类型的属性,其中两个是我们特别感兴趣的:构造
函数(constructors)和析构函数(destructors)。程序员应当使用类似下面的方
式来指定这些属性:
static void start(void) __attribute__ ((constructor));
static void stop(void) __attribute__ ((destructor));
带有"构造函数"属性的函数将在main()函数之前被执行,而声明为"析构函数"属
性的函数则将在_after_ main()退出时执行。
在生成的ELF可执行印像将会包含两个不同的节:.ctors和.dtors。它们都
有类似下面的布局:
0xffffffff ... 0x00000000
注意:如果你真得想要了解有关这部分的所有知识,我建议你去看
gcc-2.95.2/gcc/collect2.c
我们应当知道的几件事情包括:
* .ctors和.dtors将会被映射到进程地址空间中,缺省是可写的。
* 在对二进制文件正常的strip(1)命令后,这些节不会被去掉。
* 我们并不关心是否程序员已经设置了任何的构造函数和析构函数,因为这
两节总会出现而且会被映射到内存空间中。
技术细节:
----------
现在是演示一下我们先前所说的时候了:
[warning3@redhat-6 dtor]$ cat > yopta.c
#include
static void start(void) __attribute__ ((constructor));
static void stop(void) __attribute__ ((destructor));
int
main(int argc, char *argv[])
{
printf("start == %p\n", start);
printf("stop == %p\n", stop);
exit(EXIT_SUCCESS);
}
void
start(void)
{
printf("hello world!\n");
}
void
stop(void)
{
printf("goodbye world!\n");
}
EOF
[warning3@redhat-6 dtor]$ gcc -o yopta yopta.c
[warning3@redhat-6 dtor]$ ./yopta
hello world!
start == 0x8048434
stop == 0x8048448
goodbye world!
[warning3@redhat-6 dtor]$ objdump -h yopta
yopta: file format elf32-i386
Sections:
Idx Name Size VMA LMA File offAlgn
16 .ctors 0000000c080494f8080494f8000004f82**2
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-27331-1.html
真是两难