我有一个缓冲区溢出问题,我需要解决。下面的问题是,在底部是我的问题:缓冲区溢出缓冲区长度
#include <stdio.h>
#include <string.h>
void lan(void) {
printf("Your loyalty to your captors is touching.\n");
}
void vulnerable(char *str) {
char buf[LENGTH]; //Length is not given
strcpy(buf, str); //str to fixed size buf (uh-oh)
}
int main(int argc, char **argv) {
if (argc < 2)
return -1;
vulnerable(argv[1]);
return 0;
}
(gdb) disass vulnerable
0x08048408: push %ebp
0x08048409: mov %esp, %ebp
0x0804840b: sub $0x88, %esp
0x0804840e: mov 0x8(%ebp), %eax
0x08048411: mov %eax, 0x4(%esp)
0x08048415: lea -0x80(%ebp), %eax
0x08048418: mov %eax, (%esp)
0x0804841b: call 0x8048314 <strcpy>
0x08048420: leave
0x08048421: ret
End of assembler dump.
(gdb) disass lan
0x080483f4: push %ebp
0x080483f5: mov %esp, %ebp
0x080483f7: sub $0x4, %esp
0x080483fa: movl $0x8048514, (%esp)
0x08048401: call 0x8048324 <puts>
0x08048406: leave
0x08048407: ret
End of assembler dump.
然后我们有以下信息:
(gdb) break *0x08048420
Breakpoint 1 at 0x8048420
(gdb) run 'perl -e' print "\x90" x Length' 'AAAABBBBCCCCDDDDEEEE'
Breakpoint 1, 0x08048420 in vulnerable
(gdb) info reg $ebp
ebp 0xffffd61c 0xffffd61c
(gdb) # QUESTION: Where in memory does the buf buffer start?
(gdb) cont
Program received signal SIGSEGV, Segmentation fault.
最后,perl的命令是编写出的字符长度副本速记0×90。
我已经完成了这样的一些问题,但是这里阻碍了我的下列问题:“通过查看汇编代码,LENGTH的价值是什么?
我不知道如何从给定的汇编代码中找到它。我所知道的是......我们写入的缓冲区位于堆栈的位置-128(%ebp)(其中-128是十进制数)。但是,我不确定从哪里去获得缓冲区的长度。
谢谢@Jester,这就是我的想法(阻止我回答问题)。这是来自我的学校的一次旧考试中的一个问题,当我不知道编译器放在那里有多少填充时,我觉得(并且仍然觉得)回答有多大的LENGTH是很奇怪的。 – user2451412