c - 测试缓冲区溢出

标签 c security buffer-overflow

我得到了一个 C 代码文件,其中给定正确的输入会发生缓冲区溢出,然后授予 root 访问权限。这是一个使用 ZShell 的 Fedora 错误。为了测试这个(安全主题),我们禁用了 Linux 内核中启用的随机内存地址分配。

我被要求测试不同的输入,直到发生段错误,其中输入是缓冲区大小。我不明白的是,我为什么要用不同的值进行测试?我不确定代码是否有帮助,但我只是不明白改变输入的意义。

/* vulnerable.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned char buf[] =
"\x31\xc0" /* xorl %eax,%eax */
"\x50" /* pushl %eax */
"\x68""//sh" /* pushl $0x68732f2f */
"\x68""/bin" /* pushl $0x6e69622f */
"\x89\xe3" /* movl %esp,%ebx */
"\x50" /* pushl %eax */
"\x53" /* pushl %ebx */
"\x89\xe1" /* movl %esp,%ecx */
"\x99" /* cdql */
"\xb0\x0b" /* movb $0x0b,%al */
"\xcd\x80" /* int $0x80 */
;
/* -------------------------------------------------- */
void vuln(char * buf)
{
    char a[16] = { 0 };
    strcpy(a, buf);
}
int main(int argc, char * argv[])
{
    int *ret;
    if (argc != 2)
    {
        printf("Usage: %s <input>\n", argv[0]);
        exit(1);
    }
    vuln(argv[1]);
    printf("%p\n", buf);
    return 0;
}

最佳答案

What I don't get is, why should I test with different values? I'm not sure the code will help but I just dont get the point of varying the input.

缓冲区溢出只会在给定特定输入时发生,因此您应该尝试不同的输入以查看导致问题发生的原因。

提示:当用户输入比程序预期的长时会发生缓冲区溢出,因此您应该尝试使用不同的输入长度,直到程序开始崩溃或出现意外情况。

关于c - 测试缓冲区溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10540094/

相关文章:

javascript - 如何保护/隐藏 Javascript 方法或 JS 文件不让用户查看

c# - FormsAuthentication.FormsCookiePath

c - 保护程序免受缓冲区溢出的影响?

c - 在C中读取包含十六进制值的char数组

c - 段错误 : 11 when using scanf. 无法读取过去的 UUN?

security - 谷歌CP : Allowing Public Ingress Web Traffic from the Load Balancer ONLY

c - 哪些工具可以检查完整的 C 项目中的缓冲区溢出?

c - C 中的堆栈粉碎/缓冲区溢出

c - 关于传递指针的问题

C编程 "To repeat particular steps after getting instead of terminating the program"