1、打开控制台,进入虚拟环境。  ? 2、下面的程序要求用户提供输入数据,这些数据将会被保存在?user_input?缓冲区?buffer?中,程序将会使用?printf?打出缓冲区?buffer?中的数据,这个程序是一个?set-UID?程序,它以?root?权限运行。不幸地是,这个程序在?printf?打出?user_input?数据的过程中存在一个格式化漏洞。我们将会探索这些漏洞,并检验一下可以造成多大的危害。程序有两个秘密的值存在内存中,我们对这些秘密的值感兴趣。但是这些秘密值对我们来说是未知的,不可能通过读二进制代码来获取它们(实验中为了简单起见,硬编码这些秘密值为?0x44?和?0x55)。尽管我们不知道这些秘密的值,但是我们获取存放这些秘密值的内存地址倒不是特别困难,因为对大多数系统而言,每次运行程序,这些内存地址基本上是相同的。实验假设我们已经知道了这些内存地址,为了达到这个目的,程序特意为我们打出了这些地址。 注意:这些二进制代码对我们来说,只有只读和运行权限,我们没有办法修改它。也就是说在不能修改二进制代码的前提下,达到上述目标。幸运的是,我们可以有一份源码的拷贝,利用它,我们可以制定我们的攻击策略。 源码的拷贝程序如下: //vul_prog.c #define SECRET1 0x44 #define SECRET2 0x55 int?main(intargc,char *argv[]) { charuser_input[100]; int?*secret; intint_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 integern"); scanf("%d",&int_input); // getting an input from user printf("Please enter a stringn"); 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%xn",SECRET1,SECRET2); printf("The new secrets: 0x%x -- 0x%xn",secret[0],secret[1]); return 0; } 3、找到d:tools51elab5007BDebugvul_prog.exe双击,在实验环境下运行上述程序进行攻击,首先输入“1”,回车,然后输入10个“%S.”,回车。 攻击结果如下,发现程序崩溃:  ? 利用格式化字符函数引发非法指针访问内存,引起程序崩溃。 |