Changeset 364
- Timestamp:
- 03/06/06 15:30:46 (3 years ago)
- Files:
-
- nepenthes/trunk/nepenthes-core/include/Nepenthes.hpp (modified) (1 diff)
- nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nepenthes/trunk/nepenthes-core/include/Nepenthes.hpp
r332 r364 196 196 bool changeGroup(); 197 197 198 bool setCapabilties(); 199 198 200 bool changeRoot(char *path); 199 201 }; nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp
r359 r364 43 43 #include <dirent.h> 44 44 #include <sys/utsname.h> 45 46 #undef _POSIX_SOURCE 47 #include <sys/capability.h> 48 45 49 46 50 #include "Nepenthes.hpp" … … 172 176 char *chRoot = NULL; 173 177 const char *consoleTags = 0, *diskTags = 0; 178 bool forcesetcaps=false; 174 179 175 180 … … 188 193 static struct option long_options[] = { 189 194 { "config", 1, 0, 'c' }, 195 { "capabilities", 0, 0, 'C' }, 190 196 { "disk-log", 1, 0, 'd' }, // FIXME 191 197 { "file-check", 1, 0, 'f' }, // FIXME … … 207 213 }; 208 214 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); 210 216 if (c == -1) 211 217 break; … … 217 223 basedir = optarg; 218 224 break; 225 226 case 'C': 227 forcesetcaps = true; 228 break; 229 219 230 220 231 case 'c': … … 667 678 } 668 679 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 } 669 691 670 692 if ( run == true && chRoot != NULL ) … … 1321 1343 1322 1344 } 1345 1346 1347 bool 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 1323 1394 1324 1395 /** … … 1533 1604 { 1534 1605 {"c", "config", "give path to Config File", SYSCONFDIR "/nepenthes.conf" }, 1606 {"C", "capabilities", "force kernel 'security' capabilities", "" }, 1535 1607 {"d", "disk-log", "disk logging tags, see -L", "(no filter)" }, 1536 1608 {"f", "file-check", "check file for known shellcode rmknown,rmnonop", "" },
