中止陷阱而不是缓冲区溢出
我一直在读乔恩·埃里克森(Jon Erickson)写的一本很棒的书《黑客》(Hacking)。我想编译一个缓冲区溢出示例并对其进行调试,但应用程序不是在分配的空间之外写入,而是仅响应“中止陷阱”。这是 Xcode 或 Mac OS 引入的一些安全预防措施吗?作者使用的是原始 gcc 和 Debian。
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int value = 5;
char buffer_one[8], buffer_two[8];
strcpy(buffer_one, "one"); /* put "one" into buffer_one */
strcpy(buffer_two, "two"); /* put "two" into buffer_two */
printf("[BEFORE] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[BEFORE] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[BEFORE] value is at %p and is %d (0x%08x)\n", &value, value, value);
printf("\n[STRCPY] copying %d bytes into buffer_two\n\n", strlen(argv[1]));
strcpy(buffer_two, argv[1]); /* copy first argument into buffer_two */
printf("[AFTER] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[AFTER] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[AFTER] value is at %p and is %d (0x%08x)\n", &value, value, value);
}
I've been reading an excellent book Hacking by Jon Erickson. I wanted to compile an buffer overflow example and debug it, but instead of writing outside allocated space, the application just responds with 'Abort trap'. Is this some security precaution introduced by Xcode or Mac OS? The author is using raw gcc and Debian.
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
int value = 5;
char buffer_one[8], buffer_two[8];
strcpy(buffer_one, "one"); /* put "one" into buffer_one */
strcpy(buffer_two, "two"); /* put "two" into buffer_two */
printf("[BEFORE] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[BEFORE] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[BEFORE] value is at %p and is %d (0x%08x)\n", &value, value, value);
printf("\n[STRCPY] copying %d bytes into buffer_two\n\n", strlen(argv[1]));
strcpy(buffer_two, argv[1]); /* copy first argument into buffer_two */
printf("[AFTER] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
printf("[AFTER] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
printf("[AFTER] value is at %p and is %d (0x%08x)\n", &value, value, value);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是溢出保护的开始 - 尽管我不确定 XCode / OSX,但使用 gcc,您可以传递 -fno-stack-protector 并且必须关闭 ASLR
本文有助于2011 年粉碎堆栈
您应该能够了解如何禁用保护来使用此代码。
顺便说一句,我正在读同一本书 - 我不得不调整/谷歌搜索以使一些内容与 2011 年相关。
This is overflow protection kicking in - although I'm not sure about XCode / OSX, with gcc you can pass -fno-stack-protector and have to turn off the ASLR
This article helps Smashing the Stack in 2011
You should be able to find out how to disable the protections to play with this code.
I'm reading the same book btw - I've had to adjust / google around to make some things relevant for 2011.