问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
最经典的蠕虫病毒刨析
学习学习
0x01 前言 ======= 最近比较空闲,在网上看到了一个比较经典的病毒样本,本着认真学习的态度,学习分析一下这个样本,有不足的地方希望大家指导一下,我分析的病毒样本Ramnit是一种蠕虫病毒。拥有多种传播方式,不仅可以通过网页进行传播,还可以通过感染计算机内可执行文件进行传播。 0x02 初步信息收集 =========== 2.1样本基本信息 --------- | | | |---|---| | MD5 | ff5e1f27193ce51eec318714ef038bef | | SHA-1 | b4fa74a6f4dab3a7ba702b6c8c129f889db32ca6 | | SHA-256 | fd6c69c345f1e32924f0a5bb7393e191b393a78d58e2c6413b03ced7482f2320 | | File size | 55kb | | File type | Win32 EXE | 2.2样本主要行为 --------- ### 2.2.1沙箱分析 先通过沙箱简单观察一下病毒的主要行为:可以看到有连接网络和释放文件的行为。   ### 2.2.2虚拟机中动态执行 保存好现场环境后,动态执行观察现象发许多文件的图标闪动了一下,通过工具可以观察不同文件感染症状。 1\. 通过工具观察可以看到被感染的\*.exe 和\*.dll 程序自身后面都多了一个名为.rmnet的区段  2\. 且每次打开被感染的程序,当前目录会生成一个 “母体名+Srv.exe”的程序  3\. 被感染的.htm和.html文件会被添加以下内容  4\. 被感染的autorun.inf会被写入以下内容  5\. 被感染的网络状态  ### 2.2.3分析总结 1、创建互斥 “KyUffThOkYwRRtgPP” 2、投放文件并且运行 “C:\\Program Files\\Microsoft\\DesktopLayer.exe” 3、写入Autorun.inf 自动播放 进行感染 4、启动并注入iexplore.exe。通过Hook‘ZwWriteVirtualMemory’并方式来进行写入内存改变EIP执行 5、收集数据。连接C&C服务器为443端口,此为HTTPS 访问端口,用来躲避行为检测,将收集到的用户数据发送到fget-career.com。 6、劫持 winlogon 系统项的userinit来运行感染病毒母体 7、感染目标文件。遍历全盘感染后缀为 “.exe”“.dll”“.htm”“.html”的文件。 主机被感染流程图如下:  0x03 详细分析 ========= 3.1脱壳 ----- 自解压。首先对样本进行信息查询,此样本使用UPX壳,所以直接使用ESP定律脱壳即可  脱壳后在IDA进行静态分析,大致浏览后未发现关键可疑行为,怀疑该程序可能还有壳,于是使用x64dbg进行调试分析。 首先进行解码,对比解码前后内容变化    根据上述数据内容判断此时在解码后应该还包含UPX壳,在入口处下ESP断点后进行跟踪,经过几次F9查看上下文汇编后发现UPX壳位置,此时再次使用ESP定律脱壳即可得到样本  使用IDA直接静态分析最终脱壳后的样本。首先大致预览该样本行为  3.1创建互斥体 -------- 创建名称为“KyUffThOkYwRRtgPP”的互斥体。防止病毒重复运行  3.2备份文件 ------- 获取运行程序的全路径,判断自身是否是DesktopLayer.exe,不是时拷贝自身文件到备选路径,名称DesktopLayer.exe并启动,启动后退出自身   获取备选路径  拷贝文件并启动拷贝后的文件  3.3从ntdll中获取API ---------------    3.4iexplore远程执行shellcode ------------------------ 验证过程由于太长所以放到附录中,如果想看验证过程可以去附录中查看。 打开注册表查询iexplore.exe浏览器路径。在取得系统浏览器iexplore.exe路径后,首先Hook “ZwWriteVirtualMemory”。  在调用CreateProcessA函数来启动进程,当调用此函数的时候,就会进入到Hook的处理程序里面来,因为CreateProcessA 是经过封装处理的,ZwWriteVirtualMemory是其CreateProcessA的内部函数。 这个hook处理程序首先会从自身内存中解密出一个PE文件,通过远程写内存函数写入到iexplore.exe进程当中,其中还会远程写入一段shellcode代码给iexplore.exe内存PE文件进行初始化操作,大致就是申请内存----对齐区段---初始化导入表--修复重定位-修复入口点等。  3.5核心层 ------ 这层核心代码则为远程写入iexplore.exe的这段内存,实则为一个DLL文件使用CFF工具查看PE格式,确定此PE为32位Dll,且无壳   从入口上看这个DLL一共创建了6个线程来进行工作,每个线程负责不同的恶意操作。 1.创建“KyUffThOkYwRRtgPP”互斥体 2.每隔一秒判断winlogon.exe的通过循环查询注册表userinit是否启动的是感染母体 3.访问google.com:80 网站来进行取当前时间,并且判断 4.取感染时间保存到 “dmlconf.dat” 5.连接C&C服务器”fget-career.com”,发送窃取的数据 6.遍历全盘文件进行感染,主要感染类型 .exe.dll.htm.html文件 7.主要遍历驱动器根目录写autorun.inf方式 进行感染   创建“KyUffThOkYwRRtgPP”互斥体,使dll可以单例执行  ### 3.5.1线程一(劫持winlogon.exe注册表项 来启动感染母体) 通过分析我们可以知道,此线程主要通过注册表 查询winlogon目录的userinit 的来判断自身母体是否被能被开机运行,这种劫持方法,在开机启动项里面是查不到的.  并且每隔1秒查询一次,无限循环。  ### 3.5.2线程二(获取当前时间) 通过访问google.com:80来获取时间)如果google.com访问失败,则还会进行以下几个网站来获取   ### 3.5.3线程三(取感染时间保存到文件”dmlconf.dat”)  通过 SystemTimeAsFileTime 函数取得感染时间  写入到文件”dmlconf.dat” ### 3.5.4线程四(发送窃取数据线程) 首先会取计算机一些相关信息  接着会解密出一个名为”fget-career.com”的域名地址,且端口为443端口 ,为了躲避安全软件而伪装成HTTPS协议  接着进行数据组合 20406F46000121F800000A28000000050000000186 分区序列号:20406F46 分区序列号:000121F8 系统build版本:00000A28 主版本号:00000005 次版本号:00000001 国家代码:86 接着进行MD5加密字符串,发送给C&C服务器 fget-career.com 443端口 数据包首次使用固定ff 00 ?? 00 00 00 进行对C&C服务器的握手连接 在进行把20406F46000121F800000A28000000050000000186 和组合的MD5字符串发送给C&C服务器 ### 3.5.5线程五(感染全盘文件 .exe .dll .htm .html) 我们可以看到,此感染文件线程每隔30秒感染一次  首先排除感染目录  接下来就是全盘搜索文件进行感染,我们可以看到此感染母体搜索“ \*.\* ”全部文件。  当搜索到以下文件类型时候进行感染   感染.exe和.dll文件时候, 首先会读取文件区段.如果比较最后一个区段为.rmnet的话,则会停止操作,防止被重复感染.  进行感染操作使用文件映射方式把文件加载到内存,在进行添加区段.rmnet,此区段包括感染母体。  感染.htm .html文件是否 判断结尾是否为 </SCRIPT> ,如果为这个字符串则不会感染  被感染的htm和html文件 则会被添加以下内容  ### 3.6.6线程六(感染驱动器自动播放文件 autorun.inf) 首先会遍历所有驱动器路径,挨个进行判断,感染。 我们可以很清楚的看到首先遍历所有驱动器路径。然后删选出 “可移动磁盘”和没有没感染的磁盘来进行感染.  针对可移动磁盘  并且读取每个可移动磁盘的autorun.inf 文件,判断结尾是否是”RmN”,如果是则已经是被感染过的。  感染autorun.inf文件内容,可以看出是一个自动运行感染母体的代码。并且在尾巴添加 RmN 防止重复操作  0x04 总结 ======= 从感染方式就可以看到低版本的系统和安全配置不安全的系统容易会感染蠕虫病毒建议,大家使用电脑的时候有空闲的使用就升级一下电脑系统,或者安装正规的杀毒如软件。 处理这个蠕虫病毒的方式: 首先遍历每个进程的句柄表,来看看哪个进程创建了互斥名为:“KyUffThOkYwRRtgPP”。创建此互斥的进程一定是现在正在进行感染文件的进程,我们先结束掉这个进程,然后自己创建这个互斥,这个时候病毒的感染操作就已经算被终止。接下来就是全盘搜索被感染的文件来进行修复了。恢复原始入口点,删除.rmnet感染节区,修复文件校验和。 0x05 附录 ======= 远程注入iexplorer的验证过程 在调用CreateProcess时会调用该API,该样本使用此特性对启动的iexplorer.exe进行注入    在启动iexplorer.exe后对Hook的ntdll.ZwWriteVirtualMemory进行还原。参数中g\_srcASMofZW对应结构体中的btASMCode字段,所以在以下还原代码中使用指针偏移寻址进行访问数据    现在在仔细分析Hook的回调函数。g\_srcAMSofZW此全局变量为Hook的ntdll.ZwWriteVirtualMemory,而这里对应新汇编指令,所以此处的调用参数及调用约定与原本的ZwWriteVirtualMemory是一致的  通过PE文件结构获取到入口地址。通过修改入口地址达成代码注入  拷贝注入代码。使注入后的代码可以正常调用API   将PE数据拷贝完后在进行写入汇编指令使代码能够执行  在上面的g\_PEdata是一段PE数据。由于我使用插件无法正常dump,所以采用手工dump的方式 
发表于 2022-06-17 09:39:27
阅读 ( 9448 )
分类:
其他
0 推荐
收藏
0 条评论
请先
登录
后评论
初学者
2 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!