栈溢出绕过验证

栈溢出绕过验证

自己动手通过反汇编分析的一个栈溢出的案例。

1.程序代码

/*****************************************************************************
      To be the apostrophe which changed "Impossible" into "I'm possible"!
		
POC code of chapter 2.2 in book "Vulnerability Exploit and Analysis Technique"
 
file name	: stack_overflow_var.c
author		: failwest  
date		: 2006.9.20
description	: demo show nearby var overrun in stack
			  input 8 letters to bypass authentication  
Noticed		: complied with VC6.0 and build into begug version
version		: 1.0
E-mail		: [email protected]
		
	Only for educational purposes    enjoy the fun from exploiting :)
******************************************************************************/
#include <stdio.h>

#define PASSWORD "1234567"

int verify_password (char *password)
{
	int authenticated;
	char buffer[8];// add local buff
	authenticated=strcmp(password,PASSWORD);
	strcpy(buffer,password);//over flowed here!	
	return authenticated;
}


main()
{
	int valid_flag=0;
	char password[1024];
	while(1)
	{
		printf("please input password:       ");
		
		scanf("%s",password);
		
		valid_flag = verify_password(password);
		
		if(valid_flag)
		{
			printf("incorrect password!nn");
		}
		else
		{
			printf("Congratulation! You have passed the verification!n");
			break;
		}
	}
}

2.分析过程

  • 利用OllyDbg打开已经编译好的stack_overflow_var.exe程序
  • 找到main函数入口。从GetCommandLineA往下数,第5个Call一般就是程序入口点的Call,F7进入。

在这里插入图片描述

  • 一路F8,输入字符串12345678,然后往下几步到verify_password函数入口

在这里插入图片描述

  • 进入verify_password函数,函数栈帧如下图所示

在这里插入图片描述

  • 继续往下执行,下图为strcmp函数入口地址,以及结果保存位置,局部变量的第一个位置

在这里插入图片描述

  • 下图中0019FAD0为栈中第一个位置保存的为strcmp结果,为1

在这里插入图片描述

  • 继续往下执行,来到strcpy函数入口

在这里插入图片描述

  • 0019FAD0处原本保存的是strcmp结果1,执行完strcpy函数后值被覆盖为0,如下图

在这里插入图片描述

  • 行完verify_password后,返回到main函数中继续执行,判断strcmp的结果为0,成功绕过验证

在这里插入图片描述
over!

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>