简体   繁体   English

为程序调试缓冲区溢出设置系统

[英]setting up system for program debugging buffer overflow

I remember reading a long time ago that if I want to test for buffer overflows on my linux box that I need to set something in the system to allow it to happen. 我记得很久以前读过一篇文章,如果我想测试Linux机器上的缓冲区溢出,则需要在系统中进行一些设置以使其发生。 I can't remember exactly what it was for, but I was hoping some one knew what I was talking about. 我不记得确切的用途了,但是我希望有人能知道我在说什么。

I want to be able to test my programs for vulnerabilities, and see if the registers are overwritten. 我希望能够测试程序中的漏洞,并查看寄存器是否被覆盖。

EDIT: I am running ubuntu 10.04 编辑:我正在运行ubuntu 10.04

One option is to use a memory debugger such as Valgrind . 一种选择是使用内存调试器,例如Valgrind Note, however, that Valgrind only tracks for buffer overflows on dynamically-allocated memory. 但是请注意,Valgrind仅在动态分配的内存上跟踪缓冲区溢出。

If you have the option to use C++ instead of C, then you can switch to using containers rather than raw arrays, and harness GCC's "checked container" mode (see GCC STL bound checking ). 如果可以选择使用C ++而不是C,则可以切换到使用容器而不是原始数组,并利用GCC的“已检查容器”模式(请参阅GCC STL绑定检查 )。 I'm sure other compilers offer similar tools. 我确定其他编译器也会提供类似的工具。

Another hint (in addition of Oli's answer ), when chasing memory bugs with the gdb debugger, is to disable address space layout randomization , with eg 当使用gdb调试器追踪内存错误时,另一个提示(除了Oli的回答 )是使用例如禁用地址空间布局随机化

 echo 0 > /proc/sys/kernel/randomize_va_space

After doing that, two consecutive runs of the same deterministic program will usually mmap regions at the same addresses (from one run to another), and this helps a lot debugging with gdb (because then malloc usually gives the same result from one run to another, at the same given location in the run). 执行完此操作后,同一确定性程序的两次连续运行通常会将mmap区域mmap到同一地址(从一个运行到另一个),这对gdb调试gdb (因为malloc通常会从一次运行到另一个提供相同的结果) ,在运行中的相同给定位置)。

You can also use the watch command of gdb . 您还可以使用gdbwatch命令。 In particular, if in a first run (with ASLR disabled) you figure that the location 0x123456 is changing unexepectedly, you could give gdb the following command in its second run: 特别是,如果在第一次运行(禁用ASLR)中发现位置0x123456意外更改,则可以在第二次运行中为gdb以下命令:

 watch * (void**) 0x123456

Then gdb will break when this location changes (sadly, it has to be mmap -ed already). 然后,当此位置更改时, gdb将中断(遗憾的是,它必须已经被mmap -ed了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM