【发布时间】:2018-05-25 19:20:54
【问题描述】:
我正在尝试编写一个示例程序来理解堆栈缓冲区溢出,并且我有以下程序。
溢出.s:
.section .data
.section .text
.globl _start
_start:
call sum
movl %eax, %ebx
movl $15, %ebx
movl $1, %eax
int $0x80
.type sum, @function
sum:
pushl %ebp # save the current base pointer
movl %esp, %ebp # store current stack pointer to %ebp
subl $4, %esp # inc the stack pointer by 4 bytes for local variable
movl $5, -8(%ebp) # store value 5 from 8 bytes of %ebp 4 bytes beyond stack pointer
addl $5, -8(%ebp) # add 5 to the value store beyond of stack pointer
movl -8(%ebp), %eax # store the value in %eax
movl %ebp, %esp
popl %ebp
ret
组装和链接程序:
as -gstabs+ overflow.s -o oveflow.o
ld overflow.o -o overflow
./overflow
echo $?
15 <============= the result
我希望我得到一些垃圾或段错误。但它似乎按预期工作。因此,在 sum 函数中,当我将堆栈指针增加 4 个字节并从基指针存储值 5 8 个字节时,我期待这是对溢出的模拟。上面的程序是不是用堆栈缓冲区溢出的例子是错误的。 ?
【问题讨论】:
-
顺便说一句,GAS 中的注释字符是
#,而不是;。我认为您在复制代码后添加了 cmets,因为那实际上不会组装。 (;像换行符一样工作,因此您可以使用它在宏或其他东西的一行中放置多个指令或指令。)
标签: assembly buffer-overflow gnu-assembler