home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / XINE-1.ZIP / XINE-1.007 < prev    next >
Text File  |  1996-10-25  |  22KB  |  503 lines

  1.  
  2.                                         /-----------------------------\
  3.                                         | Xine - issue #1 - Phile 007 |
  4.                                         \-----------------------------/
  5.  
  6.  
  7.                       ...........................
  8.                .TBScan Heuristics Flags.
  9.                       .      b0z0/iKx       .
  10.                          .....................
  11.  
  12. a) Whassap?
  13. -----------
  14.   TBScan is, from my point of view, one of the best heuristic scanners in 
  15. our days. The heuristic scanning based on small strings is very effective 
  16. versus new viruses, expecially ones with no encryption. I had a lot of 
  17. problems to fool TBScan heuristics flags, so i decided to write this 
  18. little article that describes any (or anyway the ones that may be a real 
  19. danger for our viruses) of those. The used TBScan is the 7.04 one.
  20.   I already saw two articles (but maybe that are other ones :) ) that 
  21. described this flags, but that are currently quite old and also some 
  22. flags (that were added lately) weren't covered or were covered just
  23. partially. So here again to describe them :)
  24.  
  25. b) Here we go!
  26. --------------
  27.  Finally here with the flags description. 
  28. With _seg_ want to say every segment register CS,DS,ES,SS.
  29. With _reg_ every register and with _reg16_ every 16 bits register. With
  30. _reg16l_ i think the low 8 bits of a 16 bits register and with _reg16h_
  31. the 8 high ones. Finally _imm8_ means an immediate 8bit value and _imm16_
  32. means an immediate 16bit value. 
  33.  
  34.  Pay attention, the precedence of some operations generally isn't
  35. important, but sometimes is :) So a:
  36.  
  37.      mov    ax,1a00h
  38.     mov    dx,80h
  39.     int    21h
  40.  
  41.  will cause a flag in the same manner as a:
  42.  
  43.     mov    dx,80h
  44.     mov    ax,1a00h
  45.     int    21h
  46.  
  47.  The flags will be also triggered if between the suspect passages there 
  48. is some junk or code that doesn't do anything important. So:
  49.  
  50.     mov    dx,80h
  51.     sub    cx,cx        ;doesn't infect dx
  52.     mov    ax,1a00h    
  53.     inc    ax        ;
  54.     dec    ax        ;ax is the same at the end
  55.     int    21h    
  56.  
  57. will be triggered at the same manner like the precedent ones.
  58. Also:
  59.  
  60.     mov    dx,80h
  61.     mov    ax,1a00h
  62.     add    ax,0f0f0h
  63.     int    21h
  64.  
  65. will trigger the flag, non considering the value of the register AX at 
  66. the call of the int :)) Anyway we will talk a little more about this after
  67. the flags. 
  68.  
  69. c) The flags!
  70. -------------
  71.  
  72. <------------------------------------------
  73. * -F- Suspicious file access.
  74. mov    ax,4301h                ; Set file attributes int 21h call
  75. int    21h                     ;
  76. or                              ;
  77. mov    ax,5701h                ; Set file time/date int 21h call
  78. int    21h                     ;
  79. or                              ;
  80. mov    cx,03   ;or also 04     ; Write 3 (or 4) bytes to the file.
  81. mov    ah,40h                    ; used in com infectors. 
  82. int    21h                     ; 
  83. or                              ; 
  84. mov    cx,1ch                  ; Write 1ch bytes to the file.
  85. mov    ah,40h                  ; Used in EXE infectors to rewrite
  86. int    21h                     ; the new header.
  87. or                              ;
  88. mov    ax,1a00h                ; 
  89. mov    dx,80h                  ; set DTA. Used in runtime viruses
  90. int    21h                     ; 
  91. or                              ;
  92. mov    ah,1ah                  ; again set DTA to ds:80h
  93. mov    dx,80h                  ;
  94. int    21h                     ;
  95. or                              ;
  96. mov    ah,4eh                  ; findfirst file function 
  97. int    21h                     ;
  98.  
  99. <------------------------------------------
  100. * -M- Memory resident code. 
  101. mov    ax,2521h                ; Set Int21h int 21h call. 
  102. int    21h                     ;
  103. or                              ; 
  104. mov    ax,2513h                ; Set Int13h int 21h call.
  105. int    21h                     ; 
  106. or                              ; 
  107. mov    ax,2508h                ; Set Int08h int 21h call.
  108. or                              ;
  109. mov    word ptr _seg_:[86h],_seg_      ;direct int21h man. (just segment)
  110. or                                      ;
  111. mov    word ptr _seg_:[4eh],_seg_      ;direct int13h man. (just segment)
  112. or                                      ;
  113. mov    word ptr _seg_:[22h],_seg_      ;direct int08h man. (just segment)
  114. or                                      ;
  115. lds    _reg16_,_seg_:[84h]             ; for int 21h
  116. or                                      ;
  117. lds    _reg16_,_seg_:[4ch]             ; for int 13h
  118. or                                      ;
  119. les    _reg16_,_seg_:[84h]             ; again for 21h    
  120. or                                      ;
  121. les    _reg16_,_seg_:[4ch]             ; again for 13h
  122.  
  123.  
  124. <--------------------------------------------
  125. * -O- Found code that can be used to overwrite/move a program in memory 
  126. mov    di,0100h                ; Very used when restoring original 
  127.                                 ; COM file bytes or just when copying
  128.                                 ; our virus in memory. But may be also
  129.                                 ; used accidentally.
  130.  
  131. <--------------------------------------------
  132. * -t- Program contains a time or date triggered event. 
  133. mov    ah,2ah                  ; Get system time int 21h call
  134. int    21h                     ;
  135. or                              ;
  136. int    1ah                     ; Get time from BIOS
  137.  
  138.  
  139. <--------------------------------------------
  140. * -X- Stealth capabilities. 
  141. cmp    ah,11h            ; only if both are founded in a file at the same 
  142. cmp    ah,12h            ; time the flag will be triggered. this two cmps
  143. or                      ; are generally used for the stealth on the dir
  144.                         ; DOS command
  145. mov    al,_imm8_       ; used as an antidebug tech
  146. out    21h,al          ; kbd
  147. or                      ;
  148. mov    ah,13h          ; get/set dos disk int handler
  149. int    2fh             ;
  150. or                      ;
  151. mov    ax,13xxh        ; 
  152. int    2fh             ;
  153. or                      ;
  154. mov    ax,12yyh        ; when yy in both cases is a value between 00 and 
  155. int    2fh             ; 20. 
  156. or                      ;
  157. mov    ah,12h          ;
  158. mov    al,yyh          ;
  159. int    2fh             ;
  160. or                      ;
  161. mov    ax,0fa01h       ; Disable VSafe
  162. int    16h             ;
  163. or                      ;
  164. mov    ah,0fah         ; again
  165. mov    al,01h          ;
  166. int    16h             ;
  167. or                      ;
  168. mov    _reg16_,0fa01h  ; the same but passing trought another register
  169. xchg    ax,_reg16_      ;
  170. int    16h             ;
  171. or                      ;
  172. mov    _reg16h_,0fah   ;
  173. mov    _reg16l_,01h    ;
  174. xchg    ax,_reg16_      ;
  175. int    16h             ;
  176.     
  177. <---------------------------------------------
  178. * -Z- EXE/COM determination 
  179. cmp    word ptr _seg_:some_data,'ZM'   ; check somewhere in the mem
  180.                                         ; where we copied the first few
  181.                                         ; bytes of the file that is going
  182.                                         ; to be infected if it seems to be
  183.                                         ; an EXE file    
  184. or                                      ;
  185. cmp    _reg16_,'ZM'                    ; same as the other but in another
  186.                                         ; way from a register, 16b of 
  187. or                                      ; course
  188. cmp    word ptr _seg_:[_reg16_],'ZM'   ; well, here the _reg16_ may only
  189.                                         ; be BX/DI/SI of course.
  190.  
  191. <----------------------------------------------
  192. * -E- Flexible Entry-point 
  193.     call    doff           ; if a POP is founded after a CALL and there
  194. doff:    pop    _reg16_           ; wasn't a PUSH before the flag will be 
  195.                                ; triggered. between the CALL and the POP 
  196.                                ; there may be also a lot of other code.
  197.                                ; this is used to find the code delta offset.
  198.  
  199. <----------------------------------------------
  200. * -S- Contains a routine to search for executable files. 
  201. exemask    db    '*.ex'          ; quite obvisious. there is a mask that
  202. or                              ; may be used to search for files to be
  203. commask db    '*.co'          ; infected. generally only present in 
  204.                                 ; runtime viruses
  205.  
  206. <----------------------------------------------
  207. * -D- Disk Write access. 
  208. int    26h                     ; this is the absolute disk write int, so
  209. or                              ; it is obvisious why the flag is set :)
  210. mov    ah,03h                  ; or anyway also using disk write of the
  211. int    13h                     ; int 13h will give an alarm.
  212. or                              ;
  213. mov    ax,03??h                ;
  214. int    13h                     ;
  215. or                              ;
  216. mov    sp,7c00h                ; this is a tipical way to change the
  217.                                 ; stack pointer in boot infectors so it
  218.                                 ; wouldn't write on the virus code. the
  219.                 ; interesting thing is that the flag isn't triggered if
  220.                 ; this MOV is founded in the boot sector but only if
  221.                 ; founded on files...
  222.  
  223. <----------------------------------------------
  224. * -A- Suspicious Memory Allocation. 
  225. cmp    byte ptr _seg_:[0],'Z'   ; used when testing if we reached the
  226. or                               ; last MCB
  227. sub    word ptr _seg_:[3],_imm16_ ; shrink the MCB
  228. or                                 ;
  229. mov    word ptr _seg_:[3],ax    ; change the length of the MCB to the AX
  230. or                               ; value
  231. mov    word ptr _seg_:[413h],ax ; change avaiable memory
  232. or                               ;
  233. mov    ax,word ptr _seg_:[413h] ; get mem size
  234. or                               ;
  235. sub    word ptr _seg_:[413h],_imm16_    ; reduce memory
  236. or                                       ;
  237. int    12h                      ; get amount of memory and prepare CL to
  238. mov    cl,_imm8_                ; be used to shift AX for some times
  239.  
  240. <----------------------------------------------
  241. * -K- Unusual stack. 
  242. This flag is generally set in all the EXE infectors. The flag is set 
  243. because in the header the stack pointer points a lot after the executable 
  244. code.
  245.  
  246. <----------------------------------------------
  247. * -1- Found instructions which require a 80186 processor or above. 
  248. This is set when a non 8088 instruction is founded, ie.: LEAVE
  249.  
  250. <----------------------------------------------
  251. * -L- The program traps the loading of software. 
  252. cmp    ah,4bh                    ; if a compare of the AX register with
  253. jmp    somewhere               ; the 4b00h (load and execute) or a cmp
  254. or                              ; of the AH with the 4bh is founded before
  255. cmp    ax,4b00h                ; a jump (indifferently which) the flag
  256. jmp    somewhere               ; is triggered. this code is usually used
  257.                                 ; in interrupt 21h handlers.
  258.  
  259. <----------------------------------------------
  260. * -B- Back to entry point. 
  261. mov    _reg16_,0100h           ; this is typically used when we want to
  262. jmp    _reg16_                    ; give again the control to the victim 
  263. or                              ; file in COM infections.
  264. mov    _reg16_,0100h           ; just the same
  265. push    _reg16_                 ;
  266. ret                             ;
  267.  
  268. <----------------------------------------------
  269. * -N- Wrong name extension 
  270. The file is an EXE but the extension is .COM or the file is a COM but has 
  271. an EXE extension.
  272.  
  273. <----------------------------------------------
  274. * -?- Inconsistent exe-header. 
  275. The header is inconsistent. This may occour with a COM file that has the 
  276. first two bytes equal to 'MZ', so TBSCAN will first think it is an EXE, 
  277. but then he will found an inconsistence in the "header". This flag may 
  278. also occour if the file size calculated from the header is bigger than 
  279. the real file on the disk.
  280.  
  281. <----------------------------------------------
  282. * -U- Undocumented interrupt/DOS call. 
  283. This flag is set then a strange interrupt or a strange dos system call is 
  284. used.
  285.  
  286. <----------------------------------------------
  287. * -#- Found a code decrytion routine or debugger trap 
  288. loopy:        mov    [_reg16_],_reg_       ; this flag is set when a
  289.         dec    _reg_                 ; loop of some instructions
  290.                                               ; that changes something in
  291.         jnz    loopy                 ; memory. also a counter or
  292. or                                            ; something like must occour
  293. ourloop:    xor      word ptr _seg_:[_reg16_],_reg16_ ; to give more 
  294.         inc    _reg16_            ; credibility to the loop :)
  295.         loop    ourloop            ; if we are using loop then TBScan
  296.                                         ; will check what is in the CX
  297.                           ; register. If the value is greater of 10h
  298.                 ; then the flag will be triggered. The same thing occours
  299.                 ; if we use another register as a counter (let's say DX)
  300.                 ; and we decrement it and then check for the desired
  301.                 ; condition (ie. if it is zero). If we don't define DX or
  302. or              ; if DX is greater than 10h then the flag will be
  303.                 ; triggered. Then if we use a two layer encryption, when
  304.                 ; the first encrypts (of course if it doesn't trigger
  305.                 ; accidently other flags such as "D" or "U", because for
  306.                 ; the user 11 flags are the same as 10 :) ) the entire
  307.                 ; virus body (or file or something else) and the second,
  308.                 ; which will be unencrypted, encrypt just the other
  309.                 ; decryption loop (of course <= 10h) then TBscan wouldn't
  310.                 ; pay attention to it at all.
  311. mov    ax,2501h        ; this sets the Int 01h handler to another
  312. int    21h             ; routine. This may be used to crash some
  313. or                      ; debuggers    
  314. mov    word ptr _seg_:[06h],_seg_      ; manipulate Int 01h segment
  315.  
  316.     
  317. <----------------------------------------------
  318. * -R- Relocator.
  319. rep    _movs instr_      ; the flag will be se if a rep of a movs 
  320. retf                      ; instruction (movsb, movsw, movsd) is  founded
  321.                            ; *near the start* (or anyway is called 
  322.                            ; from somewhere at the start). this may seems
  323. or                         ; that the program copies itself somewhere 
  324.                            ; and then uses a RETF (a push may be
  325.                            ; present to have a real effect) to jump
  326.                            ; somewhere else for example to the newly
  327.                            ; copied code.
  328. push    _reg16_            ; here we push a register (with a memory
  329. ret                        ; location for example) and jump to it
  330.                            ; with a ret                    
  331. or                              ;
  332. push    _imm16_                    ; we just push a immediate (a mem loc
  333. ret                             ; maybe) and then return there with a ret
  334. or                              ;
  335. sub    sp,_imm16_              ; this may occour if we put our location
  336. ret                             ; in the stack and then we want to jump
  337. or                              ; there with the ret
  338. sub    sp,_reg16_              ; again... attention, _reg16_ must be 
  339. ret                             ; inizialized somewhere to trigger the
  340. or                              ; flag.
  341. add    sp,_imm16_              ; this is basically the same as the
  342. ret                             ; precedent
  343. or                              ;
  344. add    sp,_reg16_              ; another one
  345. ret                             ;
  346. or                              ;
  347. inc    sp                      ; also more than one inc. identic to the 
  348. ret                             ; add one
  349. or                              ;
  350. dec    sp                      ; again
  351. ret                             ;
  352. or                              ;
  353. mov    sp,_imm16_              ; move SP somewhere where we may store the
  354. ret                             ; adress where we want to jump with this
  355. or                              ; ret    
  356. shr    sp,_imm16_              ; yet another R flag :) _imm16_ has a max    
  357. ret                             ; value. 
  358. or                              ;
  359. shl    sp,_imm16_              ;
  360. ret                             ;
  361. or                              ;
  362. neg    sp                      ; if we put our return value on ss:neg(sp)
  363. ret                             ; 
  364.                                 ; so basically the R flag is triggered 
  365.                 ; everytime that the SP is modified before a call. The 
  366.                 ; flag will be also triggered for example if we call a
  367.                 ; procedure (which will change our CS:IP), then we POP 
  368.                 ; more times than PUSH, so the SP at the RET wouldn't be
  369.                 ; the same as it has been at CALL time.
  370.  
  371. <----------------------------------------------
  372. * -!- Invalid opcode or out-of-range branch.
  373. This occours when a invalid opcode (such as 66h for example) is founded 
  374. or if a jump of the code point somewhere out of it.
  375.  
  376. <----------------------------------------------
  377. * -G- Garbage instructions. 
  378.  this flag is triggered if there is one of this operations but before it
  379. in the registers it seems that there isn't anything logical into them. If
  380. a MOV to a register is encountered before the operation (also if the MOV
  381. is into another register, not the used one) the flag would not be
  382. triggered! TBScan put the G flag only if any of this instruction is
  383. founded (without a MOV initialisation) in the first few bytes (about 30).
  384.  AAA
  385.  AAS
  386.  ADD  _reg_,_reg_
  387.  ADD  _reg_,_imm_        
  388.  ADC  _reg_,_reg_
  389.  ADC  _reg_,_imm_
  390.  AND  _reg_,_reg_
  391.  AND  _reg_,_imm_
  392.  CBW
  393.  CWD
  394.  CLC
  395.  CMP  _reg_,_reg_
  396.  DAA
  397.  DAS
  398.  DEC  _reg16_
  399.  INC  _reg16_
  400.  OR   _reg_,_reg_
  401.  OR   _reg_,_imm_
  402.  POPF
  403.  STC
  404.  XCHG _reg16_,_reg16_
  405.  XOR  _reg16_,_reg16_
  406.  XOR  _reg16_,_imm_
  407.  
  408. <----------------------------------------------
  409. * -@-  Encountered instructions which are not likely to be generated by an 
  410. assembler, but by some code generator like a polymorphic virus. 
  411.  This is triggered when a strange operation, quite unused, is encountered.
  412. Some examples of stange operations may be:
  413.  
  414. HLT
  415. AAA
  416.  
  417. <----------------------------------------------
  418. * -J-  Suspicious jump construct. 
  419.  This flag is triggered when a jump that points on another jump
  420. somewhere in the code is founded near the entry point of the program.
  421. For example:
  422. start:
  423.   jmp    foolit
  424. i_am_back:
  425.  .
  426.  .  ;
  427.  .  ; here is some data/code
  428.  .  ;
  429.  .
  430. foolit:
  431.   jmp i_am_back
  432.  
  433. d) Flags on boot sectors
  434. ------------------------
  435.  TBScan is very unfriendly with tipical boot sector viruses :) Infact even
  436. only a "413h" in the boot sector will trigger two flags, the A and the M
  437. ones.
  438.  For example:
  439.  
  440. mov    _reg16_,word ptr _seg_:[413h]     ; trigger flags AM
  441. dec    word ptr _seg_:[413h]             ; trigger flags AM    
  442.  
  443.  but also a
  444.  
  445. db 90h,13h,04h,90h
  446.  
  447.  trigger 2 flags in a row :) so pay attention when allocating memory!
  448. TBScan of course doesn't use the same search strings as for files when
  449. scanning boot sectors. Let's give a look to the suspicious instructions
  450. that we can't use in our BS viruses:
  451.  
  452. mov     ax,3xx            ; Write xx sectors will trigger the D flag
  453. int    13h               ;
  454.                                 ;
  455. mov    cx,_imm16_              ; this will trigger the O flag. this may 
  456. rep    movsb                   ; be a piece of a routine which is used to
  457.                                 ; copy our virus in memory or something
  458.                                 ; like.
  459.                                 ;
  460. mov    cx,_imm16_              ; again the O flag. 
  461. rep    movsw                   ;
  462.                                 ;
  463. mov    word ptr _seg_:[004eh],_seg_  ; put our segment instead of the
  464.                                 ; original segment of the int13h. this
  465.                                 ; will trigger A and M flags
  466. mov    word ptr _seg_:[004ch],_reg16_  ; put offset of our handler 
  467.                                 ; instead of the original one. this will
  468.                                 ; trigger A and M flags
  469. mov    word ptr _seg_:[004ch],_imm16_  ; set new int13h offset
  470.                                         ; trigger A and M flags
  471. mov    word ptr _seg_:[004eh],_imm16_  ; set new int13h segment
  472.                                         ; trigger A and M flags
  473. int    12h                             ; get amount of memory
  474.                                 ; this will trigger the A flag.
  475. int    1ah                     ; will trigger the 't' flag also here
  476.                                 ;
  477.  
  478.  Well, as in the files viriis also in boot sectors strange calls will be
  479. flagged with the U flag.
  480.  And finally if the BS/MBR marker 55aah isn't present TBScan will trigger
  481. the Y flag.
  482.  
  483. e) Fooling the flags
  484. --------------------
  485.  For almost any of the described flags the way to fool them is to do the
  486. same operation in another way. For example:
  487.  
  488.     Triggered:                            Not Triggered:
  489. cmp     ah,4bh                    ;       push    bx
  490. je      somewhere               ;       mov     bh,4bh
  491.                                 ;       cmp     ah,bh
  492.                                 ;       je      somewhere
  493.                                 ;       pop     bx
  494.  
  495.  This example gives you an idea of how you can fool almost any of the
  496. flags. Of course the resulting code wouldn't be pretty and short like the
  497. original one, but it won't be flagged. Anyway there are many ways to
  498. change in this way the code, and some are also quite efficent and
  499. optimized, so just have a little of imagination or don't cry if TBScan
  500. catches your virus :) 
  501.  
  502.  
  503.