Unpacking Storm Worm : Code and Import Address Table onto the heap

快速解包Storm蠕虫
本文介绍了一种快速解包Storm蠕虫所使用的加载器的方法,即使恶意代码被加载到堆上并进行了重定位。文章详细说明了如何找到原始入口点、如何转储真实代码以及如何修复已转储的可执行文件。
 As part of my series of blogs about custom packers, this blog presents techniques to quickly unpack the Storm Worm packer, even if the unpacked code is executed onto the heap, the code is relocated, and the Import Address Table is also on allocated memory.

Storm Worm attackers have been using many different packers, and even if their primary goal isn't to protect against reverse engineering, they have introduced various techniques to slow down analysis. Today's main trick is the execution of code onto the heap. This prevents process dumpers from working, because they dump to disk only the code loader (the actual process you are executing), and not the malicious code.

This is by no means a new technique, but I haven't seen many tutorials about unpacking packers that load code onto the heap. In the example you are about to view, the attackers' implementation is flawed, and it allows unpacking in a very short time. For obvious reasons, I'm not going to discuss the flaws, but I will show you how to unpack the file quickly.

Finding the Original Entry Point

The packer loader is rather linear, so finding the "jump" to the entry point is fairly trivial. Because it's all linear, simply scroll down through the code, until you find suspicious code like this:

We can put a breakpoint there and then execute the malware. By looking at the content of EBX, we see an address that is below the process image space. In my case, the address was 0x332DC8, and this is obviously not inside our executable image.

The loader allocated memory, then moved the code to be executed onto the heap, applied relocation, and then emulated the Windows loader to load the imports. (Emulate sounds exciting, but it's basically just doing the Windows PE loader job, and every packer does that.) The relocation is applied because the file never knows exactly where it will be executed from, since the code is executed onto the heap.

Dumping the real code

Because the executed code isn't within the process, standard memory dumpers won't dump the interesting bit, just the malware loader. Standard memory dumpers simply read the process memory and dump from ImageBase to ImageBase+SizeOfImage. In order to dump this one, you can use LordPE and use Dump Memory Region.

Just select the memory region corresponding to the original entry point address. In my case, since our address was 0x382DC8, the best memory region to dump is the one starting at 0x380000:

After a quick look at our dump with a hex editor, we realize that we have complete headers of the original unpacked file. Pretty much as we saw in my last blog, we have different headers in memory, one PE file for the malware, and one PE file for the "packed" loader.

Fixing the dumped executable

Since we have the original headers, we don't have to bother recreating them from scratch. We simply need to update them, since they are still in their original state, which means that the Raw Address of every section is not matching its Virtual Address equivalent. Indeed, when you dump a PE file from memory, the Raw information of every section must be updated so that it matches its virtual counterpart.

We also need to fix the import table. The packer loader updated the imports with Windows function addresses; therefore, our dump has hardcoded pointers to Windows functions. The file can still run, but the import table isn't really valid. We don't even have to use Import Reconstructor for this; we can do it statically with LordPE too.

The reason we can do it statically is because of the way the imports are working. If you are interested, I invite you to read about FirstThunk and OriginalFirstThunk in your favorite PE file format documentation.

So, open LordPE, go into Options, and check/uncheck as shown on the next picture. Basically you just have to uncheck the option for Wipe Relocation, and check FixDump (this is the Raw = Virtual fixing thing). You can see the settings here:

Also, don't forget to update the ImageBase of your file. By default it was 0x400000, but we have seen that the file was relocated. In my case, it was loaded at 0x380000, so I changed the ImageBase to 0x380000.

At this point, our file is totally unpacked. Imports were reconstructed (because we had all the needed information), the sections were realigned, and everything was nicely fixed. As you can see below, the file can now be analyzed in IDA with no problem:

Because of its design flaws, this packer was definitely very easy to unpack, probably a lot more so than the authors initially thought. Hopefuly, this blog gives you some hints on how to unpack packers that move the code and Import Address Table onto the heap.

Security Researcher: Nicolas Brulez

基于51单片机,实现对直流电机的调速、测速以及正反转控制。项目包含完整的仿真文件、源程序、原理图和PCB设计文件,适合学习和实践51单片机在电机控制方面的应用。 功能特点 调速控制:通过按键调整PWM占空比,实现电机的速度调节。 测速功能:采用霍尔传感器非接触式测速,实时显示电机转速。 正反转控制:通过按键切换电机的正转和反转状态。 LCD显示:使用LCD1602液晶显示屏,显示当前的转速和PWM占空比。 硬件组成 主控制器:STC89C51/52单片机(与AT89S51/52、AT89C51/52通用)。 测速传感器:霍尔传感器,用于非接触式测速。 显示模块:LCD1602液晶显示屏,显示转速和占空比。 电机驱动:采用双H桥电路,控制电机的正反转和调速。 软件设计 编程语言:C语言。 开发环境:Keil uVision。 仿真工具:Proteus。 使用说明 液晶屏显示: 第一行显示电机转速(单位:转/分)。 第二行显示PWM占空比(0~100%)。 按键功能: 1键:加速键,短按占空比加1,长按连续加。 2键:减速键,短按占空比减1,长按连续减。 3键:反转切换键,按下后电机反转。 4键:正转切换键,按下后电机正转。 5键:开始暂停键,按一下开始,再按一下暂停。 注意事项 磁铁和霍尔元件的距离应保持在2mm左右,过近可能会在电机转动时碰到霍尔元件,过远则可能导致霍尔元件无法检测到磁铁。 资源文件 仿真文件:Proteus仿真文件,用于模拟电机控制系统的运行。 源程序:Keil uVision项目文件,包含完整的C语言源代码。 原理图:电路设计原理图,详细展示了各模块的连接方式。 PCB设计:PCB布局文件,可用于实际电路板的制作。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值