C roothelper/sudo


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.  * Run commands as root
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <crypt.h>
  9.  
  10. int main(int argc, char *argv[]) {
  11. char key[9], command[512];
  12. int i;
  13.  
  14. if(argc < 2) {
  15. printf("Usage: %s <password> <command ...>\n", argv[0]);
  16. return 0;
  17. }
  18.  
  19. if (strlen(argv[1]) > 8) {
  20. printf("Sorry, incorrect password\n");
  21. return 0;
  22. }
  23.  
  24. strcpy (key, argv[1]);
  25.  
  26. if (!strcmp(crypt(key,"eZZ"),"8585bb4893n2jmnd")) {
  27. } else {
  28. printf("Sorry, incorrect password\n");
  29. return 0;
  30. }
  31.  
  32. setuid(0);
  33.  
  34. command[0] = '\0';
  35.  
  36. for(i=2;i<argc;i++) {
  37. strcat(command,argv[i]);
  38. strcat(command," ");
  39. }
  40.  
  41. system(command);
  42.  
  43. return 0;
  44. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.