如何在任意内存地址中写入

时间:2013-11-24 10:28:53

标签: c memory-management gdb buffer-overflow

关于“写入任意记忆地址”的主题来自黑客攻击艺术“。

当我发出更改test_val的值时,但test_val的值不会改变。任何人都可以帮助我如何在我使用x64_ubuntu_v12.10的地方更改text_val的值。

-[*] test_val @ 0x00601058 = -72 0xffffffb8
-./fmt_vuln $(printf "\x58\x10\x60\x00")%x%x%100x%n

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
char text[1024];
static int test_val = -72;
if(argc < 2) {
printf("Usage: %s <text to print>\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);
}

谢谢,如果有人能帮助我解决这个问题。

输出:     root @ ubuntu:〜/ gcc #fmt_vuln AAAA%08x。%08x。%08x。%08x     打印用户控制输入的正确方法:AAAA%08x。%08x。%08x。%08x     打印用户控制输入的错误方法:AAAA75820000.755fcad0.75328900.75820017     [*] test_val @ 0x00601058 = -72 0xffffffb8

root@ubuntu:~/gcc# fmt_vuln $(printf "\x58\x10\x60\x00")%08x.%08x.%08x.%n
The right way to print user-controlled input: X`%08x.%08x.%08x.%n
The wrong way to print user-controlled input: X`faa82000.fa85ead08a900.
[*] test_val @ 0x00601058 = -72 0xffffffb8

1 个答案:

答案 0 :(得分:0)

我实际上是在现代64位处理器上尝试这些漏洞方法,您必须按gcc禁用SSP。

示例:gcc -m32 -fno-stack-protector <myprogram.c>