【发布时间】:2019-09-04 04:35:03
【问题描述】:
我正在阅读Tim Newsham's white paper 的格式字符串漏洞利用,发现一开始有些部分难以理解。
正在讨论以下计划。
/*
* fmtme.c
* Format a value into a fixed-size buffer
*/
#include <stdio.h>
int
main(int argc, char **argv)
{
char buf[100];
int x;
if(argc != 2)
exit(1);
x = 1;
snprintf(buf, sizeof buf, argv[1]);
buf[sizeof buf - 1] = 0;
printf("buffer (%d): %s\n", strlen(buf), buf);
printf("x is %d/%#x (@ %p)\n", x, x, &x);
return 0;
}
作者说“本文档中的所有示例实际上都是在 x86 BSD/OS 4.1 上执行的”,这是一个 little-endian 机器。
程序是这样执行的
% ./fmtme "%x %x %x %x"
buffer (15): 1 f31 1031 3133
x is 1/0x1 (@ 0x804745c)
论文说:
"A quick analysis of the program will reveal that the stack layout of the
program when the snprintf function is called is:
Address Contents Description
fp+8 Buffer pointer 4-byte address
fp+12 Buffer length 4-byte integer
fp+16 Format string 4-byte address
fp+20 Variable x 4-byte integer
fp+24 Variable buf 100 characters
The four values output in the previous test were the next four arguments on
the stack after the format string: the variable x, then three 4-byte
integers
taken from the uninitialized buf variable."
这里的fp 是什么?文件指针?
为什么它从 fp+8 而不是 fp+4 开始,而其他任何地方(4 字节地址)的增量都是 4?
这里,更大的地址意味着值在堆栈的上层还是下层?
“内容”下的名称是什么意思?
当我运行上面的程序时,x 的值,即1,没有被打印出来。可能是因为架构不同?
我是这样的
./fmtme "%x %x %x %x"
buffer (34): cd512860 b3356d80 b3356d80 8247ee8
x is 1/0x1 (@ 0x7ffc08247d8c)
谁能帮忙?
【问题讨论】:
-
@user3386109 我们能以某种方式将旧架构与新架构联系起来吗?如果这有什么不同?
标签: c security exploit format-string