home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersguides-&-software / 40hex-11.zip / 40HEX-11.006 < prev    next >
Text File  |  1993-06-01  |  8KB  |  158 lines

  1. 40Hex Issue 11 Volume 3 Number 2                                      File 006
  2.  
  3.                              ─────────────────────
  4.                              SFT's and Their Usage
  5.                              ─────────────────────
  6.                                  By Dark Angel
  7.                                  Phalcon/Skism
  8.                              ─────────────────────
  9.  
  10.        A powerful though seldom-used technique in virus writing is the use of
  11.   the system file table, an internal DOS structure similar in some respects to
  12.   FCBs, albeit vastly more powerful.  The system file table holds the critical
  13.   information on the state of an open file, including the current pointer
  14.   location, the open mode, and the file size.  Manipulation of the system file
  15.   tables can often replace calls to corresponding DOS interrupt routines and
  16.   therefore, when combined with other techniques, reduces the effectiveness of
  17.   a TSR virus monitor and decreases code size.
  18.  
  19.        Each open file has a corresponding system file table.  The following
  20.   tables come from Ralf Brown's interrupt listing.
  21.  
  22.    Format of DOS 2.x system file tables:
  23.    Offset  Size    Description
  24.     00h    DWORD   pointer to next file table
  25.     04h    WORD    number of files in this table
  26.     06h  28h bytes per file
  27.        Offset  Size    Description
  28.         00h    BYTE    number of file handles referring to this file
  29.         01h    BYTE    file open mode (see AH=3Dh)
  30.         02h    BYTE    file attribute
  31.         03h    BYTE    drive (0 = character device, 1 = A, 2 = B, etc)
  32.         04h 11 BYTEs   filename in FCB format (no path, no period,
  33.                           blank-padded)
  34.         0Fh    WORD    ???
  35.         11h    WORD    ???
  36.         13h    DWORD   file size???
  37.         17h    WORD    file date in packed format (see AX=5700h)
  38.         19h    WORD    file time in packed format (see AX=5700h)
  39.         1Bh    BYTE    device attribute (see AX=4400h)
  40.        ---character device---
  41.         1Ch    DWORD   pointer to device driver
  42.        ---block device---
  43.         1Ch    WORD    starting cluster of file
  44.         1Eh    WORD    relative cluster in file of last cluster accessed
  45.        ------
  46.         20h    WORD    absolute cluster number of current cluster
  47.         22h    WORD    ???
  48.         24h    DWORD   current file position???
  49.  
  50.    Format of DOS 3.x system file tables and FCB tables:
  51.    Offset  Size    Description
  52.     00h    DWORD   pointer to next file table
  53.     04h    WORD    number of files in this table
  54.     06h  35h bytes per file
  55.        Offset  Size    Description
  56.         00h    WORD    number of file handles referring to this file
  57.         02h    WORD    file open mode (see AH=3Dh)
  58.                bit 15 set if this file opened via FCB
  59.         04h    BYTE    file attribute
  60.         05h    WORD    device info word (see AX=4400h)
  61.         07h    DWORD   pointer to device driver header if character device
  62.                else pointer to DOS Drive Parameter Block (see AH=32h)
  63.         0Bh    WORD    starting cluster of file
  64.         0Dh    WORD    file time in packed format (see AX=5700h)
  65.         0Fh    WORD    file date in packed format (see AX=5700h)
  66.         11h    DWORD   file size
  67.         15h    DWORD   current offset in file
  68.         19h    WORD    relative cluster within file of last cluster accessed
  69.         1Bh    WORD    absolute cluster number of last cluster accessed
  70.                0000h if file never read or written???
  71.         1Dh    WORD    number of sector containing directory entry
  72.         1Fh    BYTE    number of dir entry within sector (byte offset/32)
  73.         20h 11 BYTEs   filename in FCB format (no path/period, blank-padded)
  74.         2Bh    DWORD   (SHARE.EXE) pointer to previous SFT sharing same file
  75.         2Fh    WORD    (SHARE.EXE) network machine number which opened file
  76.         31h    WORD    PSP segment of file's owner (see AH=26h)
  77.         33h    WORD    offset within SHARE.EXE code segment of
  78.                sharing record (see below)  0000h = none
  79.  
  80.    Format of DOS 4+ system file tables and FCB tables:
  81.    Offset  Size    Description
  82.     00h    DWORD   pointer to next file table
  83.     04h    WORD    number of files in this table
  84.     06h  3Bh bytes per file
  85.        Offset  Size    Description
  86.         00h    WORD    number of file handles referring to this file
  87.         02h    WORD    file open mode (see AH=3Dh)
  88.                bit 15 set if this file opened via FCB
  89.         04h    BYTE    file attribute
  90.         05h    WORD    device info word (see AX=4400h)
  91.                bit 15 set if remote file
  92.                bit 14 set means do not set file date/time on closing
  93.         07h    DWORD   pointer to device driver header if character device
  94.                else pointer to DOS Drive Parameter Block (see AH=32h)
  95.                or REDIR data
  96.         0Bh    WORD    starting cluster of file
  97.         0Dh    WORD    file time in packed format (see AX=5700h)
  98.         0Fh    WORD    file date in packed format (see AX=5700h)
  99.         11h    DWORD   file size
  100.         15h    DWORD   current offset in file
  101.        ---local file---
  102.         19h    WORD    relative cluster within file of last cluster accessed
  103.         1Bh    DWORD   number of sector containing directory entry
  104.         1Fh    BYTE    number of dir entry within sector (byte offset/32)
  105.        ---network redirector---
  106.         19h    DWORD   pointer to REDIRIFS record
  107.         1Dh  3 BYTEs   ???
  108.        ------
  109.         20h 11 BYTEs   filename in FCB format (no path/period, blank-padded)
  110.         2Bh    DWORD   (SHARE.EXE) pointer to previous SFT sharing same file
  111.         2Fh    WORD    (SHARE.EXE) network machine number which opened file
  112.         31h    WORD    PSP segment of file's owner (see AH=26h)
  113.         33h    WORD    offset within SHARE.EXE code segment of
  114.                sharing record (see below)  0000h = none
  115.         35h    WORD    (local) absolute cluster number of last clustr
  116.                  accessed (redirector) ???
  117.         37h    DWORD   pointer to IFS driver for file, 0000000h if native DOS
  118.  
  119.        In order to exploit this nifty structure in DOS, the virus must first
  120.   find the location of the appropriate system file table.  This may be easily
  121.   accomplished with a few undocumented DOS calls.  Given the file handle in
  122.   bx, the following code will return the address of the corresponding system
  123.   file table:
  124.  
  125.        mov  ax,1220h  ; Get job file table entry to ES:DI
  126.        int  2fh       ; DOS 3+ only
  127.  
  128.        mov  bl,es:di  ; get number of the SFT for the file handle
  129.                       ; -1 = handle not open
  130.        mov  ax,1216h  ; get address of the system file table
  131.        int  2fh       ; entry number bx
  132.        ; ES:DI now points to the system file table entry
  133.  
  134.        Now that the system file table entry address is known, it is a trivial
  135.   matter to alter the various bytes of the entry to fit your particular needs.
  136.   Most viruses must first clear a file's attributes in order to open the file
  137.   in read/write mode, since it would otherwise not be able to write to a read-
  138.   only file.  This handicap is easily overcome by opening the file in read-
  139.   only mode (al = 0) and changing the byte (or word) referring to the file's
  140.   open mode to 2.  This has the added benefit of bypassing some resident
  141.   alarms, which generally do not go off if a file is opened in read only mode.
  142.   It is also possible to set a file's pointer by altering the double word at
  143.   offset 15h (in DOS 3+).  So a quick and easy way to reset the file pointer
  144.   is:
  145.        mov  es:di+15h,0
  146.        mov  es:di+17h,0
  147.  
  148.        It is acceptable to ignore the DOS 2.X system file table format.  DOS
  149.   2.X is not in common use today and many programs simply refuse to run under
  150.   such primitive versions.  Most of the useful offsets are constant in DOS
  151.   3.X+, which simplifies the code tremendously.
  152.  
  153.        This is only a surface treatment of a topic which warrants further
  154.   investigation.  Numerous opportunities exist for the enterprising virus
  155.   author to exploit the power of the system file tables.  But the only way to
  156.   find these opportunities is to experiment.  Have fun!
  157.  
  158.