如何关闭 gcc 编译器优化以启用缓冲区溢出 [英] How to turn off gcc compiler optimization to enable buffer overflow

查看:55
本文介绍了如何关闭 gcc 编译器优化以启用缓冲区溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做作业问题 需要禁用编译器优化保护才能工作.我在 ubuntu linux 上使用 gcc 4.4.1,但无法确定哪些标志是正确的.我意识到它依赖于架构 - 我的机器使用 32 位英特尔处理器运行.

I'm working on a homework problem that requires disabling compiler optimization protection for it to work. I'm using gcc 4.4.1 on ubuntu linux, but can't figure out which flags are are the right ones. I realize it's architecture dependant - my machine runs w/ 32-bit Intel processor.

谢谢.

推荐答案

这是个好问题.为了解决该问题,您还必须禁用 ASLR,否则 g() 的地址将不可预测.

That's a good problem. In order to solve that problem you will also have to disable ASLR otherwise the address of g() will be unpredictable.

禁用 ASLR:

sudo bash -c 'echo 0 > /proc/sys/kernel/randomize_va_space'

禁用金丝雀:

gcc overflow.c -o overflow -fno-stack-protector

在 Canary 和 ASLR 被禁用后,它应该是一个直接的攻击,就像 Smashing the Stack for乐趣和利润

After canaries and ASLR are disabled it should be a straight forward attack like the ones described in Smashing the Stack for Fun and Profit

以下是 ubuntu 中使用的安全功能列表:https://wiki.ubuntu.com/Security/Features 您不必担心 NX 位,g() 的地址将始终位于内存的可执行区域中,因为它位于 TEXT 内存段内.NX 位仅在您尝试在堆栈或堆上执行 shellcode 时起作用,这对于此分配不是必需的.

Here is a list of security features used in ubuntu: https://wiki.ubuntu.com/Security/Features You don't have to worry about NX bits, the address of g() will always be in a executable region of memory because it is within the TEXT memory segment. NX bits only come into play if you are trying to execute shellcode on the stack or heap, which is not required for this assignment.

现在去破坏EIP

这篇关于如何关闭 gcc 编译器优化以启用缓冲区溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆