【发布时间】:2021-10-04 10:36:26
【问题描述】:
我正在尝试测试缓冲区溢出,但即使缓冲区足够大,程序似乎也会崩溃,我不明白为什么
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int bowfunc(char *string) {
char buffer[1024];
strcpy(buffer, string);
return 1;
}
int main(int argc, char *argv[]) {
bowfunc(argv[1]);
printf("Done.\n");
return 1;
}
用bowfun() 正确调整rsp 通过在gdb 反汇编中减去0x410。构建为gcc -o exec1 -fno-stack-protector -z execstack -g exec1.c 运行为./exec1 $(python3 -c "print('\xaa' * 600)") 导致崩溃,实际崩溃似乎发生在(500 到 600 字节)之间。我看不到,为什么 gdb 返回这个错误
0x000055555555519e in bowfunc (string=0x7fffffffdcd4 'ª' <repeats 100 times>...) at exec1.c:10
xargs --show-limits </dev/null 给出的最大命令长度和参数大小似乎也没问题:
Your environment variables take up 4531 bytes
POSIX upper limit on argument length (this system): 2090573
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2086042
Size of command buffer we are actually using: 131072
Maximum parallelism (--max-procs must be no greater): 2147483647
【问题讨论】:
-
字符串正在使用 UTF-8 编码打印,所以它是 1201 字节。
-
@Barmar 为什么当我告诉 python 以十六进制值打印数据时会发生这种情况
\xaa是一个字节,而a是 UTF 编码
标签: c linux gdb buffer-overflow