我正在尝试在Mac OS X 10.6 64位上使用C语言编写一个简单的缓冲区溢出。以下是该概念:
void function() {
char buffer[64];
buffer[offset] += 7; // i'm not sure how large offset needs to be, or if
// 7 is correct.
}
int main() {
int x = 0;
function();
x += 1;
printf("%d\n", x); // the idea is to modify the return address so that
// the x += 1 expression is not executed and 0 gets
// printed
return 0;
}
这是main函数汇编代码的一部分:
...
0x0000000100000ebe <main+30>: callq 0x100000e30 <function>
0x0000000100000ec3 <main+35>: movl $0x1,-0x8(%rbp)
0x0000000100000eca <main+42>: mov -0x8(%rbp),%esi
0x0000000100000ecd <main+45>: xor %al,%al
0x0000000100000ecf <main+47>: lea 0x56(%rip),%rdi # 0x100000f2c
0x0000000100000ed6 <main+54>: callq 0x100000ef4 <dyld_stub_printf>
...
我想跳过movl
指令,这意味着我需要将返回地址增加42-35=7(正确吗?)。现在我需要知道返回地址存储的位置,以便计算正确的偏移量。我已经尝试手动搜索正确的值,但要么打印1,要么出现
abort trap
- 可能有某种缓冲区溢出保护正在进行吗?
在我的机器上使用偏移量88可以工作。我使用了Nemo的方法找到返回地址。