【发布时间】:2012-11-04 18:14:59
【问题描述】:
我有一个小 C 程序可以利用。而且我也理解了要执行的攻击背后的逻辑。但是,尽管我尝试了,但它对我不起作用。
#include <stdio.h>
#include <stdlib.h>
#define SECRET1 0x44
#define SECRET2 0x55
int main(int argc, char *argv[]) {
char user_input[100];
int *secret;
int int_input;
int a, b, c, d; /* other variables, not used here.*/
/* The secret value is stored on the heap */
secret = (int *) malloc(2*sizeof(int));
/* getting the secret */
secret[0] = SECRET1; secret[1] = SECRET2;
printf("Please enter a decimal integer\n");
scanf("%d", &int_input); /* getting an input from user */
printf("Please enter a string\n");
scanf("%s", user_input); /* getting a string from user */
printf(user_input);
printf("\n");
/* Verify whether your attack is successful */
printf("The original secrets: 0x%x -- 0x%x\n", SECRET1, SECRET2);
printf("The new secrets: 0x%x -- 0x%x\n", secret[0], secret[1]);
return 0;
}
我只需要使用格式字符串“printf(user_input);”打印secret[0]的地址和值
我尝试过提供类似“\x6e\xaf\xff\xff%x%x%x%x%s”的内容。但它不工作。任何建议将不胜感激。非常感谢。
【问题讨论】:
-
如果你想打印某物的地址,你应该使用addressof操作符,
&。
标签: c buffer-overflow format-string fortify-source