博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Dynamic Forking of Win32 EXE
阅读量:4034 次
发布时间:2019-05-24

本文共 4012 字,大约阅读时间需要 13 分钟。

Introduction

This Proof-Of-Concept (POC) code demonstrates the dynamic loading of a Win32 EXE into the memoryspace of a process that was created using the CreateProcess API with the CREATE_SUSPENDED parameter. Thiscode also shows how to perform manual relocation of a Win32 EXE and how to unmap the original image of an EXEfrom its process space.

Description of Technique

Under Windows, a process can be created in suspend mode using the CreateProcess API with the CREATE_SUSPENDED parameter. The EXE image will be loaded into memory by Windows but execution will not begin until the ResumeThread API is used. Before calling ResumeThread, it is possible to read and write this process's memory space using APIs like ReadProcessMemory and WriteProcessMemory. This makes it possible to overwrite the image of the original EXE with the image of another EXE, thus enabling the execution of the second EXE within the memory space of the first EXE. Thiscan be achieved with the following sequence of steps.

  1. Use the CreateProcess API with the CREATE_SUSPENDED parameter to create a suspended process from any EXE file. (Call this the first EXE).
  2. Call GetThreadContext API to obtain the register values (thread context) of the suspended process. The EBX registerof the suspended process points to the process's PEB. The EAX register contains the entry point ofthe process (first EXE).
  3. Obtain the base-address of the suspended process from its PEB, i.e. at [EBX+8]
  4. Load the second EXE into memory (using ReadFile) and perform the neccessary alignment manually. This is required if the file alignment is different from the memory alignment
  5. If the second EXE has the same base-address as the suspended process and its image-size is <= to theimage-size of the suspended process, simply use the WriteProcessMemory function to write the image of the second EXE into thememory space of the suspended process, starting at the base-address.
  6. Otherwise, unmap the image of the first EXE using ZwUnmapViewOfSection (exported by ntdll.dll) anduse VirtualAllocEx to allocate enough memory for the second EXE within the memory space of the suspended process. The VirtualAllocEx API must be supplied with the base-address of the second EXE to ensure thatWindows will give us memory in the required region. Next, copy the image of the second EXE into the memory space of the suspended process starting at the allocated address (using WriteProcessMemory).
  7. If the unmap operation failed but the second EXE is relocatable (i.e. has a relocation table), then allocateenough memory for the second EXE within the suspended process at any location. Performmanual relocation of the second EXE based on the allocated memory address. Next, copy the relocated EXE into thememory space of the suspended process starting at the allocated address (using WriteProcessMemory).
  8. Patch the base-address of the second EXE into the suspended process's PEB at [EBX+8].
  9. Set EAX of the thread context to the entry point of the second EXE.
  10. Use the SetThreadContext API to modify the thread context of the suspended process.
  11. Use the ResumeThread API to resume execute of the suspended process.

转载自:http://www.security.org.sg/code/loadexe.html

源码下载http://download.csdn.net/detail/sdcxyz/6482053

 

Techniques Demonstrated by POC Code

  1. Manual relocation of an EXE using its Relocation Table.
  2. Unmapping the image of the original EXE using ZwUnmapViewOfSection.
  3. Reading and Writing to a process's memory space using ReadProcessMemory and WriteProcessMemory.
  4. Changing the base-address of a process by modifying its value in the process's PEB.

 

Usage

loadEXE.exe <EXE filename>

This POC code will use the CreateProcess API to create a process in suspend mode from calc.exe. It would then load and align the EXE file given by the "EXE filename" commandline parameter. Following this, it would copy the aligned EXE image into calc.exe's memory space and resume execution.

 

 

Contacts

For further enquries or to submit malicious code for our analysis, email them to the following.

你可能感兴趣的文章
本地服务方式搭建etcd集群
查看>>
安装k8s Master高可用集群
查看>>
忽略图片透明区域的事件(Flex)
查看>>
忽略图片透明区域的事件(Flex)
查看>>
AS3 Flex基础知识100条
查看>>
Flex动态获取flash资源库文件
查看>>
flex中设置Label标签文字的自动换行
查看>>
Flex 中的元数据标签
查看>>
flex4 中创建自定义弹出窗口
查看>>
01Java基础语法-11. 数据类型之间的转换
查看>>
01Java基础语法-13. if分支语句的灵活使用
查看>>
01Java基础语法-15.for循环结构
查看>>
01Java基础语法-16. while循环结构
查看>>
01Java基础语法-17. do..while循环结构
查看>>
01Java基础语法-18. 各种循环语句的区别和应用场景
查看>>
01Java基础语法-19. 循环跳转控制语句
查看>>
Django框架全面讲解 -- Form
查看>>
socket,accept函数解析
查看>>
今日互联网关注(写在清明节后):每天都有值得关注的大变化
查看>>
”舍得“大法:把自己的优点当缺点倒出去
查看>>