人为漏洞的构造、文件的载入、验证机制的突破

上次我们构造了一个漏洞,但是不能输入自己想要的字符,所以这次我们另外构造一个漏洞,使用文件的方式读入数据,这样便可以输入我们想要的字符。

这样,我们的目标还是上次那个,绕过验证。

 1 // stack_overflow.cpp : Defines the entry point for the console application.
 2  //
 3  
 4  #include "stdafx.h"
 5  #define  PASSWORD "1234567"
 6  
 7  int verify_password(char *password)
 8  {
 9      int authenticated;   
10      char buffer[8];   
11      authenticated = strcmp(password,PASSWORD);   
12      strcpy(buffer,password);                     //溢出位置
13      return authenticated;                        
14  }
15  
16  void main()
17  {
18      int valid_flag = 0;
19      char password[1024];
20      FILE* fp;
21      if (!(fp = fopen("D:\\password.txt","rw+")))
22      {
23          exit(0);
24      }
25      fscanf(fp,"%s",password);
26      valid_flag = verify_password(password);
27      if (valid_flag)
28      {
29          printf("incorrect password!\n\n");
30      } 
31      else
32      {
33          printf("Congratulation!You have passed the verification!\n");
34      }
35      fclose(fp);
36  }
37  

当然,还有这个

1 #include <stdio.h>
2  #include <string.h>
3  #include <stdlib.h>

先找到我们要覆盖的地址:

0012FB24   00401104  返回到 stack_ov.main+74 来自 stack_ov.00401005

我们找到成功后指向的位置

0040111F  |> \68 28604200   push    00426028   ; /format = "Congratulation!You have passed the verification!",LF,""
00401124  |.  E8 F7020000   call    printf     ; \printf

也就是说,要把0012FB24处的00401104覆盖成0040111F。

构造文件内容如下

这样即可验证所需的长度和需要修改的位置。

重新构造的文件

执行后

返回地址就被覆盖了,也就是说,执行完verify_password这个函数后,返回到0040111F处(原本的位置被覆盖了)。

终于成功的绕过了验证,直接达到结果处。由于利用后堆栈出现了不平衡,所以会出现错误,后面我们会想办法解决这个问题。

 工程文件:https://files.cnblogs.com/tk091/stack_overflow.rar

感谢宝哥的大力支持。

原文地址:https://www.cnblogs.com/tk091/p/2713310.html