如何关闭 Glibc 运行时保护?

发布于 2024-11-24 22:52:59 字数 460 浏览 0 评论 0原文

我正在尝试了解代码漏洞,并正在测试我编写的一些简单程序。然而,Glibc 在运行时捕获的许多问题(例如 Stack-Smashing、Double Free 等)。因此我希望能够在没有 Glibc 运行时检测错误的情况下运行我的程序。有没有办法关闭Glibc的检测? (比如编译器标志等)。

我在之前的链接中看到它描述了如何关闭 ASLR 和 Canary,但这不是我想要做的,因为它仍然会阻止像 Double Free 这样的错误和我想尝试的其他一些堆错误(http ://stackoverflow.com/questions/2340259/how-to-turn-off-gcc-compiler-optimization-to-enable-buffer-overflow)。

我还知道您可以使用 -w 标志关闭编译时警告,但这似乎也不是我想要的。我尝试过阅读 GCC 标志并查找有关 Glibc 的信息,但我还没有取得任何进展。因此,我将非常感谢任何帮助。谢谢。

I am trying to learn about code vulnerabilities, and am testing some simple programs I wrote. However, many of the issues Glibc catches during runtime (e.g. Stack-Smashing, Double Free, etc.). Thus I would like to be able to run my programs without Glibc's runtime detection errors. Is there a way to turn off Glibc's detection? (like with a compiler flag, etc).

I saw in a previous link it is described how to turn off ASLR and Canaries, but this is not what I'd like to do, since it still stops errors like a Double Free and some other heap errors I want to try out (http://stackoverflow.com/questions/2340259/how-to-turn-off-gcc-compiler-optimization-to-enable-buffer-overflow).

I also know you can turn off compile-time warnings with the -w flags but that doesn't seem to be what I want either. I've tried reading over the GCC flags and looking up information about Glibc, but I haven't gotten anywhere yet. Thus I would greatly appreciate any help. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不知在何时 2024-12-01 22:52:59

检查 malloc(3) 的手册页以了解 MALLOC_CHECK_ 环境变量的用法。使用这个,您可以关闭那些双重免费错误和诸如此类的东西的“中止”。

man malloc

因此,如果您的程序被称为“badfree”,您可以使用导出命令设置 MALLOC_CHECK_(注意尾随下划线),或者只是在每次执行 badfree 时设置它。

export MALLOC_CHECK_=0
./badfree

--或者-

MALLOC_CHECK_=0 ./badfree

请记住,如果您使用第一种方法,它是为您在该 shell 中运行的任何程序设置的。

malloc(3) 手册页中的 MALLOC_CHECK_ 设置为:

MALLOC_CHECK_ =
 0  Silently ignore any issues
 1  Send error message to stderr
 2  abort() is called immediately, killing your program.
 3  Do both '1' and '2' (MALLOC_CHECK_ is a bitfield)

Check the man page for malloc(3) for usage of the MALLOC_CHECK_ environment variable. Using this, you can turn off 'aborts' for those double free errors and whatnot to play with things.

man malloc

So if your program was called 'badfree', you can either set MALLOC_CHECK_ (note trailing underscore) with an export command, or just set it every execution of badfree.

export MALLOC_CHECK_=0
./badfree

--or--

MALLOC_CHECK_=0 ./badfree

Just remember if you use the first method, it's set for ANY program you run in that shell.

Settings for MALLOC_CHECK_ from the malloc(3) man page are:

MALLOC_CHECK_ =
 0  Silently ignore any issues
 1  Send error message to stderr
 2  abort() is called immediately, killing your program.
 3  Do both '1' and '2' (MALLOC_CHECK_ is a bitfield)
独闯女儿国 2024-12-01 22:52:59

您可以重载operator newoperator delete,但这对于使用mallocfree<的程序没有帮助。 /代码>。当然,您也可以编写自己的实现,但在某些操作系统上重载 C 库函数可能有点困难。

从概念上讲,双重释放和释放(未分配的指针)之间有什么区别?

You can overload operator new and operator delete, but that isn't going to help with a program that uses malloc and free. You can of course write your own implementations of those, also, but overloading C-library functions can be a bit challenging on some OSs.

What, conceptually, is the difference between a double free and free (unallocated_pointer) ?

素罗衫 2024-12-01 22:52:59

您至少应该能够

-fno-stack-protector

在编译时

关闭堆栈保护编辑:抱歉,刚刚发现这对您来说还不够

似乎并不容易,因为 glibc 对于所有程序来说都是全局的,所以这会很糟糕如果你能关闭保护的话。
我的建议是安装一个没有堆保护的旧 Linux 发行版(2003 年中期或更早的版本应该可以)。

You should at least be able to turn off stack protection with

-fno-stack-protector

at compiletime

Edit: sorry, have just seen that this isn't enough for you

Doesn't seem to be easy because glibc is global for all programs, so it would be pretty bad if you could turn the protection off.
My proposal would be to install an old linux distribution that has no heap protection (mid 2003 or earlier should work).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文