Changeset 364

Show
Ignore:
Timestamp:
03/06/06 15:30:46 (3 years ago)
Author:
common
Message:

Nepenthes:
- added support for linux capabilities
as capabilities do not work when the kernel module capability is not loaded, but using capabilities when availible is recommended, using capabilities is default
when the kernel module is not loaded, setting capabilities will fail, but nepenthes will not fail
if you want to make nepenthes stopp when using capabilities, use the -C flag to enforce capabilities
enforcing capabilities will stopp the process upon error

when using capabilities, don't change the process user or group with the -u -g flags, it breaks the capabilities

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/nepenthes-core/include/Nepenthes.hpp

    r332 r364  
    196196                bool changeGroup(); 
    197197 
     198                bool setCapabilties(); 
     199 
    198200                bool changeRoot(char *path); 
    199201    }; 
  • nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp

    r359 r364  
    4343#include <dirent.h> 
    4444#include <sys/utsname.h> 
     45 
     46#undef _POSIX_SOURCE 
     47#include <sys/capability.h> 
     48 
    4549 
    4650#include "Nepenthes.hpp" 
     
    172176        char *chRoot = NULL; 
    173177        const char *consoleTags = 0, *diskTags = 0; 
     178        bool forcesetcaps=false; 
    174179 
    175180 
     
    188193                static struct option long_options[] = { 
    189194            { "config",                 1, 0, 'c' }, 
     195                        { "capabilities",       0, 0, 'C' }, 
    190196                        { "disk-log",           1, 0, 'd' },    // FIXME 
    191197                        { "file-check",         1, 0, 'f' },    // FIXME 
     
    207213                }; 
    208214 
    209                 int32_t c = getopt_long(argc, argv, "c:d:f:g:hHikl:Lor:Ru:vVw:", long_options, (int *)&option_index); 
     215                int32_t c = getopt_long(argc, argv, "c:Cd:f:g:hHikl:Lor:Ru:vVw:", long_options, (int *)&option_index); 
    210216                if (c == -1) 
    211217                        break; 
     
    217223                        basedir = optarg; 
    218224                        break; 
     225 
     226                case 'C': 
     227                        forcesetcaps = true; 
     228                        break; 
     229 
    219230 
    220231                case 'c': 
     
    667678        } 
    668679 
     680        if ( run == true  ) 
     681        { 
     682                if ( setCapabilties() == false) 
     683                { 
     684                        if ( forcesetcaps == true ) 
     685                        { 
     686                                logCrit("%s","As you asked to force capabilities, this is a critical error and we will terminate right now\n"); 
     687                                run = false; 
     688                        } 
     689                } 
     690        } 
    669691 
    670692        if ( run == true && chRoot != NULL ) 
     
    13211343 
    13221344} 
     1345 
     1346 
     1347bool Nepenthes::setCapabilties() 
     1348{ 
     1349        logPF(); 
     1350 
     1351#ifdef HAVE_LIBCAP 
     1352        // set caps 
     1353        cap_t caps = cap_init(); 
     1354        cap_value_t capList[4] = 
     1355        {  
     1356                CAP_SYS_CHROOT,                 // chroot() 
     1357                CAP_NET_BIND_SERVICE,   // bind() ports < 1024  
     1358                CAP_SETUID,                     // setuid() 
     1359                CAP_SETGID                              // setgid() 
     1360        }; 
     1361 
     1362        unsigned num_caps = 4; 
     1363 
     1364        cap_set_flag(caps, CAP_EFFECTIVE,       num_caps, capList, CAP_SET); 
     1365        cap_set_flag(caps, CAP_INHERITABLE, num_caps, capList, CAP_SET); 
     1366        cap_set_flag(caps, CAP_PERMITTED,       num_caps, capList, CAP_SET); 
     1367 
     1368        if ( cap_set_proc(caps) ) 
     1369        { 
     1370                cap_free(caps); 
     1371                logCrit("Could not set capabilities '%s'\n",strerror(errno)); 
     1372                logCrit("%s","Maybe you did not load the kernel module 'capability' ?\n"); 
     1373                logCrit("%s","Try 'modprobe capability' \n"); 
     1374                return false; 
     1375        } 
     1376        cap_free(caps); 
     1377 
     1378        // print caps 
     1379        caps = cap_get_proc(); 
     1380        ssize_t y = 0; 
     1381        logInfo("The process %d was given capabilities %s\n",(int) getpid(), cap_to_text(caps, &y)); 
     1382        fflush(0); 
     1383        cap_free(caps); 
     1384 
     1385        return true; 
     1386#else 
     1387        logCrit("%s","Compiled without support for capabilities, no way to run capabilities\n"); 
     1388        return false; 
     1389#endif  // HAVE_LIBCAP 
     1390 
     1391} 
     1392 
     1393 
    13231394 
    13241395/** 
     
    15331604        { 
    15341605        {"c",   "config",                       "give path to Config File",                             SYSCONFDIR "/nepenthes.conf"    }, 
     1606                {"C",   "capabilities",         "force kernel 'security' capabilities", ""                                              }, 
    15351607                {"d",   "disk-log",                     "disk logging tags, see -L",                    "(no filter)"                   }, 
    15361608                {"f",   "file-check",           "check file for known shellcode rmknown,rmnonop",   ""                                          },