How to launch an Executable from within memory

本文介绍了一种在内存中直接启动并运行可执行文件的方法。通过使用Windows API和调试寄存器设置断点,文章详细展示了如何创建进程并在内存中加载及执行EXE文件,实现了不依赖磁盘I/O的操作。

 How to launch an Executable from within memory

 

#define WIN32_NO_STATUS
#include <windows.h>
#undef WIN32_NO_STATUS


namespace NT {
    extern "C" {


#pragma warning(disable: 4005) // macro redefinition
#include <ntddk.h>
#pragma warning(default: 4005)


    }
}
using NT::NTSTATUS;


typedef struct _DEBUG_CONTROL {
    ULONG L0 : 1;
    ULONG G0 : 1;
    ULONG L1 : 1;
    ULONG G1 : 1;
    ULONG L2 : 1;
    ULONG G2 : 1;
    ULONG L3 : 1;
    ULONG G3 : 1;
    ULONG LE : 1;
    ULONG GE : 1;
    ULONG : 3;
    ULONG GD : 1;
    ULONG : 2;
    ULONG RWE0 : 2;
    ULONG LEN0 : 2;
    ULONG RWE1 : 2;
    ULONG LEN1 : 2;
    ULONG RWE2 : 2;
    ULONG LEN2 : 2;
    ULONG RWE3 : 2;
    ULONG LEN3 : 2;
} DEBUG_CONTROL, *PDEBUG_CONTROL;

 

VOID preppatch()
{
    CONTEXT context = {CONTEXT_DEBUG_REGISTERS};


    PDEBUG_CONTROL dr7 = PDEBUG_CONTROL(&context.Dr7);


    context.Dr0 = ULONG(GetProcAddress(GetModuleHandle("ntdll.dll"),
"ZwCreateThread"));


    dr7->L0 = 1, dr7->RWE0 = 0, dr7->LEN0 = 0;


    SetThreadContext(GetCurrentThread(), &context);
}


LONG patch(PEXCEPTION_POINTERS ep)
{
    if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP) {


        HANDLE hProcess = PHANDLE(ep->ContextRecord->Esp)[4];


        PCONTEXT context = ((PCONTEXT*)(ep->ContextRecord->Esp))[6];


        NT::PROCESS_BASIC_INFORMATION pbi;


        NT::NtQueryInformationProcess(hProcess, NT::ProcessBasicInformation,
&pbi, sizeof pbi, 0);


        PVOID x; ReadProcessMemory(hProcess, PCHAR(pbi.PebBaseAddress) + 8,
&x, sizeof x, 0);


        NT::ZwUnmapViewOfSection(hProcess, x);


        HRSRC hRsrc = FindResource(0, "Image", "EXE");


        HGLOBAL hGlobal = LoadResource(0, hRsrc);


        PVOID p = LockResource(hGlobal);


        PIMAGE_NT_HEADERS nt = PIMAGE_NT_HEADERS(PCHAR(p) +
PIMAGE_DOS_HEADER(p)->e_lfanew);


        PVOID q = VirtualAllocEx(hProcess,
                                 PVOID(nt->OptionalHeader.ImageBase),
                                 nt->OptionalHeader.SizeOfImage,
                                 MEM_RESERVE | MEM_COMMIT,
PAGE_EXECUTE_READWRITE);


        WriteProcessMemory(hProcess, PCHAR(q), PCHAR(p), 0x1000, 0);


        PIMAGE_SECTION_HEADER sect = IMAGE_FIRST_SECTION(nt);


        for (ULONG i = 0; i < nt->FileHeader.NumberOfSections; i++)


            WriteProcessMemory(hProcess,
                               PCHAR(q) + sect[i].VirtualAddress,
                               PCHAR(p) + sect[i].PointerToRawData,
                               sect[i].SizeOfRawData, 0);


        WriteProcessMemory(hProcess, PCHAR(pbi.PebBaseAddress) + 8, &q,
sizeof q, 0);


        context->Eax = ULONG(q) + nt->OptionalHeader.AddressOfEntryPoint;


        ep->ContextRecord->Dr7 = 0;


        return EXCEPTION_CONTINUE_EXECUTION;
    }


    return EXCEPTION_CONTINUE_SEARCH;
}


int main(int argc, char *argv[])
{
    PROCESS_INFORMATION pi;
    STARTUPINFO si = {sizeof si};


    __try {
        preppatch();


        CreateProcess(0, "Explorer", 0, 0, FALSE, 0, 0, 0, &si, &pi);
    }
    __except (patch(GetExceptionInformation())) {}


    return 0;
}

 

 

### ENSP Server Configuration and Usage #### Overview of ENSP The Enterprise Network Simulation Platform (ENSP) is a powerful tool designed to simulate complex enterprise-level networks, allowing users to design, configure, test, and troubleshoot various networking scenarios without the need for physical devices[^1]. #### Installation Requirements To install and run an ENSP server effectively, ensure that the system meets minimum requirements including sufficient CPU power, memory, storage space, as well as having installed necessary software dependencies such as Java Runtime Environment or specific versions of Python depending on which version of ENSP one intends to deploy. #### Initial Setup Process After downloading and installing ENSP from official sources, launch the application through its executable file. During first-time setup, follow prompts carefully while configuring basic parameters like language settings, installation path selection, etc., until reaching the main interface where further configurations can be made according to project needs. #### Configuring Virtual Devices Within ENSP's graphical user interface, add virtual routers, switches, firewalls, servers, workstations, and other network components by dragging them onto the canvas area provided within the workspace window. Connect these elements using drag-and-drop lines representing different types of connections between nodes based upon desired topology designs. For each added device, specify detailed properties via context menus accessible after selecting individual items placed inside scenes created earlier during scene creation stages; this includes setting IP addresses, subnet masks, default gateways, DNS server information among others relevant attributes required when building realistic simulated environments closely resembling real-world counterparts found across diverse industries ranging from telecommunications service providers down to small businesses operating locally only. #### Running Simulations & Troubleshooting Common Issues Once all hardware pieces have been properly configured along with their interconnections established accordingly, start running simulations directly from menu options available at top bars located near toolbar sections positioned horizontally above drawing areas used previously throughout entire processes described so far hereunder. If any issues arise concerning connectivity problems experienced whilst performing tests over newly constructed models built up till now then consider checking cable link statuses shown visually alongside connection paths drawn manually before proceeding forward towards deeper analysis involving packet capture tools integrated into platforms themselves too if needed eventually though usually simple checks suffice most times around indeed! ```bash # Example command line instruction for starting ENSP simulation ./start_simulation.sh ``` --related questions-- 1. What are some common troubleshooting steps taken when encountering errors in ENSP? 2. How does ENSP compare against alternative network simulation solutions currently present within marketplaces today regarding features offered versus cost efficiency ratios achieved overall? 3. Can you provide examples demonstrating how enterprises leverage ENSP specifically toward enhancing cybersecurity measures implemented internally across organizational structures?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值