Advertisement
Guest User

Untitled

a guest
Aug 10th, 2015
2,210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.94 KB | None | 0 0
  1. /*
  2. GID inconsistency bruteforcer
  3. This can be used to detect LD_PRELOAD rootkit that hide fds, procs and files based on GID
  4. Since GID is an unsigned int, it is finite and thus bruteforceable, however it might take a while.
  5. This took less than 20mins on my system, this may vary based on your setup.
  6.  
  7. NOTE: the rkit could detect it is under GID bruteforce attack and switch GIDs, however this is not easy to perform.
  8.  
  9. This will detect Umbreon and other GID based rkits
  10.  
  11. Have fun!
  12.  
  13. gcc fuckumbreon.c -o fuckumbreon
  14. */
  15.  
  16. #include <fcntl.h>
  17. #include <sys/stat.h>
  18. #include <stdio.h>
  19. #include <limits.h>
  20. #include <stdlib.h>
  21. #include <errno.h>
  22. #include <time.h>
  23.  
  24. int main()
  25. {
  26.   if(getuid() != 0) //maybe not getuid?
  27.   {
  28.     printf("You must run this program as root.");
  29.     return 0;
  30.   }
  31.  
  32.   unsigned int i, overflow_value = (UINT_MAX + 1);
  33.   int fd;
  34.   double time_diff;
  35.   double percent_done;
  36.   char tmp_template[] = "/dev/shm/tmp.XXXXXXXX";
  37.   time_t start_time = time(0);
  38.   time_t last_time = time(0);
  39.  
  40.   fd = mkstemp(tmp_template);
  41.   for (i = 1; i != overflow_value; i++)
  42.   {
  43.     if((i % 100000) == 0)
  44.     {
  45.       time_t now = time(0);
  46.       time_diff = (double) difftime(now, last_time);
  47.       if (time_diff > 0)
  48.       {
  49.         time_diff = (double) difftime(now, start_time);
  50.         percent_done = (double)((double)i / (double)UINT_MAX) * (double)100;
  51.         printf("Elapsed seconds: %g, current gid %u, %f percent complete\n", time_diff, i, percent_done);
  52.         last_time = time(0);
  53.       }
  54.     }
  55.  
  56.     int resp = fchown(fd, geteuid(), i);
  57.  
  58.     if (resp == -1 || errno == ENOENT)
  59.     {
  60.       printf("GID-based fd hiding detected (GID: %u)\n", i);
  61.       return 1;
  62.     }
  63.   }
  64.  
  65.   int resp = fchown(fd, geteuid(), 0);
  66.  
  67.   if(resp == -1) // this is repetitive
  68.   {
  69.     printf("GID-based fd hiding detected (probably GID %u)\n", UINT_MAX);
  70.     return 1;
  71.   }
  72.  
  73.   printf("No inconsistencies detected\n");
  74.   return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement