close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

Changeset 115


Ignore:
Timestamp:
Aug 21, 2007, 10:22:59 PM (19 years ago)
Author:
rainer
Message:

Fix the problem that new suid/sgid file found by the file system check already will not be quarantined in the suid check (ticket #71).

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/Changelog

    r114 r115  
    112.3.6:
     2        * introduce 'fflags' flag for suid files to detect new files already found
     3          in regular file check (problem reported by J. Crutchfield); also add
     4          regression test to ascertain that files in baseline database are not
     5          quarantined erroneously
    26        * sh_hash.c: replace check for prefix 'K' with check for not prefix'/'
    37          to allow for arbitrary module-specific store/lookup in db
  • trunk/include/samhain.h

    r114 r115  
    131131#define SH_FFLAG_CHECKED   (1<<3)
    132132#define SH_FFLAG_REPORTED  (1<<3)
     133#define SH_FFLAG_SUIDCHK   (1<<4)
    133134
    134135#define SH_FFLAG_ALLIGNORE_SET(a)   (((a) & SH_FFLAG_ALLIGNORE) != 0)
    … …  
    147148#define SET_SH_FFLAG_REPORTED(a)    ((a) |= SH_FFLAG_REPORTED)
    148149#define CLEAR_SH_FFLAG_REPORTED(a)  ((a) &= ~SH_FFLAG_REPORTED)
     150
     151#define SH_FFLAG_SUIDCHK_SET(a)     (((a) & SH_FFLAG_SUIDCHK) != 0)
     152#define SET_SH_FFLAG_SUIDCHK(a)     ((a) |= SH_FFLAG_SUIDCHK)
     153#define CLEAR_SH_FFLAG_SUIDCHK(a)   ((a) &= ~SH_FFLAG_SUIDCHK)
    149154
    150155
  • trunk/include/sh_hash.h

    r22 r115  
    8484void sh_hash_pushdata_memory (file_type * theFile, char * fileHash);
    8585
     86/* Get file flags from in-memory database
     87 */
     88int sh_hash_getflags (char * filename);
     89
     90/* Set file flags in in-memory database
     91 */
     92int sh_hash_setflags (char * filename, int flags);
     93
     94/* Set a file flag in in-memory database
     95 */
     96void sh_hash_addflag  (char * filename, int flag);
     97
    8698/* Compare a file with its status in the database.
    8799 */
  • trunk/src/sh_hash.c

    r114 r115  
    10541054  memcpy( &(*p).theFile, &ft, sizeof(sh_filestore_t) );
    10551055
    1056   p->fflags = 0;
    1057 
     1056  /* init fflags, such that suid files in
     1057   * database are recognized as such
     1058   */
     1059  {
     1060    mode_t mode = (mode_t) ft.mode;
     1061
     1062    if (S_ISREG(mode) &&
     1063        (0 !=(S_ISUID & mode) ||
     1064#if defined(HOST_IS_LINUX)
     1065         (0 !=(S_ISGID & mode) &&
     1066          0 !=(S_IXGRP & mode))
     1067#else 
     1068         0 !=(S_ISGID & mode)
     1069#endif
     1070         )
     1071        )
     1072      p->fflags = SH_FFLAG_SUIDCHK;
     1073
     1074    else
     1075      p->fflags = 0;
     1076  }
     1077     
    10581078  p->modi_mask = 0L;
    10591079  p->fullpath  = fullpath;
    … …  
    18121832  sh_file_t * p;
    18131833
    1814   SL_ENTER(_("sh_hash_have_it"));
     1834  SL_ENTER(_("sh_hash_have_it_int"));
    18151835
    18161836  if (newname == NULL)
    1817     SL_RETURN( (NULL), _("sh_hash_have_it"));
     1837    SL_RETURN( (NULL), _("sh_hash_have_it_int"));
    18181838
    18191839  if (IsInit != 1)
    … …  
    18241844    p = hashsearch ( sh_tiger_hash(newname, TIGER_DATA, sl_strlen(newname)) );
    18251845  if (p == NULL)
    1826      SL_RETURN( (NULL), _("sh_hash_have_it"));
     1846     SL_RETURN( (NULL), _("sh_hash_have_it_int"));
    18271847  /*
    18281848  if (p->allignore == S_FALSE &&
    … …  
    18311851    SL_RETURN( (1), _("sh_hash_have_it"));
    18321852  */
    1833   SL_RETURN( (p), _("sh_hash_have_it"));
     1853  SL_RETURN( (p), _("sh_hash_have_it_int"));
    18341854}
    18351855
    … …  
    18601880  return 0;
    18611881}
    1862  
     1882
     1883int sh_hash_getflags (char * filename)
     1884{
     1885  sh_file_t * p = sh_hash_have_it_int (filename);
     1886  if (!p)
     1887    return (-1);
     1888  return (p->fflags);
     1889}
     1890
     1891int sh_hash_setflags (char * filename, int flags)
     1892{
     1893  sh_file_t * p = sh_hash_have_it_int (filename);
     1894  if (!p)
     1895    return (-1);
     1896  p->fflags = flags;
     1897  return 0;
     1898}
     1899
     1900/* needs lock to be threadsafe
     1901 */
     1902void sh_hash_addflag (char * filename, int flag_to_set)
     1903{
     1904  int fflags = sh_hash_getflags(filename);
     1905
     1906  if (fflags >= 0)
     1907    {
     1908      fflags |= flag_to_set;
     1909      sh_hash_setflags(filename, fflags);
     1910    }
     1911  return;
     1912}
    18631913
    18641914/*****************************************************************
    … …  
    21062156
    21072157  memcpy( &(*fp).theFile, &p, sizeof(sh_filestore_t) );
    2108   fp->fflags    = 0;
     2158  fp->fflags    = 0;  /* init fflags */
    21092159  fp->modi_mask = 0L;
    21102160
  • trunk/src/sh_suidchk.c

    r114 r115  
    831831  struct stat     buf;
    832832  int             status;
     833  int             fflags;
    833834  char          * fs;
    834835  long            sl_status = SL_ENONE;
    … …  
    910911      ++FileLimTotal;
    911912
     913      /* Rate limit (Fps == Files per second)
     914       */
    912915      if ((ShSuidchkFps > 0 && FileLimNum > ShSuidchkFps && FileLimTotal > 0)&&
    913916          (ShSuidchkYield == S_FALSE))
    … …  
    995998              else
    996999                {
    997                   if (sh.flag.update == S_TRUE &&
     1000
     1001                  if ( sh.flag.update   == S_TRUE &&
    9981002                      (sh.flag.checkSum == SH_CHECK_INIT  ||
    9991003                       sh.flag.checkSum == SH_CHECK_CHECK))
    10001004                    {
     1005                      /* Updating database. Report new files that
     1006                       * are not in database already. Then compare
     1007                       * to database and report changes.
     1008                       */
    10011009                      if (-1 == sh_hash_have_it (tmpcat))
    10021010                        {
    … …  
    10171025                          sh_hash_pushdata_memory (&theFile, fileHash);
    10181026                        }
     1027                     
     1028                      sh_hash_addflag(tmpcat, SH_FFLAG_SUIDCHK);
     1029                     
    10191030                    }
     1031
    10201032                  else if (sh.flag.checkSum == SH_CHECK_INIT  &&
    10211033                           sh.flag.update == S_FALSE )
    10221034                    {
     1035                      /* Running init. Report on files detected.
     1036                       */
    10231037                      sh_hash_pushdata (&theFile, fileHash);
    10241038                      sh_error_handle ((-1), FIL__, __LINE__,
    10251039                                       0, MSG_SUID_FOUND, tmp );
    10261040                    }
     1041
    10271042                  else if (sh.flag.checkSum == SH_CHECK_CHECK )
    10281043                    {
     1044                      /* Running file check. Report on new files
     1045                       * detected, and quarantine them.
     1046                       */
    10291047                      sh_error_handle (SH_ERR_ALL, FIL__, __LINE__,
    10301048                                       0, MSG_SUID_FOUND, tmp );
    1031                       if (-1 == sh_hash_have_it (tmpcat))
     1049
     1050                      fflags = sh_hash_getflags(tmpcat);
     1051
     1052                      if ( (-1 == fflags) || (!SH_FFLAG_SUIDCHK_SET(fflags)))
    10321053                        {
    1033                           report_file(tmpcat, &theFile, timestrc, timestra, timestrm);
     1054                          if (-1 == fflags)
     1055                            report_file(tmpcat, &theFile, timestrc, timestra, timestrm);
    10341056
    10351057                          /* Quarantine file according to configured method
    … …  
    10631085                                                       _("[SuidCheck]"),
    10641086                                                       ShSuidchkSeverity);
     1087
     1088                              sh_hash_addflag(tmpcat, SH_FFLAG_SUIDCHK);
     1089
    10651090                            }
    10661091                        }
    10671092                      else
    10681093                        {
     1094                          /* File exists. Check for modifications.
     1095                           */
    10691096                          (void) sh_hash_compdata (SH_LEVEL_READONLY,
    10701097                                                   &theFile, fileHash,
    10711098                                                   _("[SuidCheck]"),
    10721099                                                   ShSuidchkSeverity);
     1100                         
     1101                          sh_hash_addflag(tmpcat, SH_FFLAG_SUIDCHK);
     1102
    10731103                        }
    10741104                    }
  • trunk/test/testrun_1c.sh

    r55 r115  
    173173chk_suiddata_5 () {
    174174    one_sec_sleep
     175    if [ ! -f "${BASE}/a/a/x" ]; then
     176        [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/x (erroneously deleted)";
     177        return 1
     178    fi
    175179    if [ -f "${BASE}/a/a/y" ]; then
    176180        [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y (not deleted)";
    … …  
    310314    test -f "${RCFILE}" || touch "${RCFILE}"
    311315    eval echo '"$'"SUIDPOLICY_$1"'"' >>"${RCFILE}"
     316    if [ "x$1" = "x5" ]; then
     317        chmod 4755 "${BASE}/a/a/x"
     318    fi
    312319}
    313320
Note: See TracChangeset for help on using the changeset viewer.