Advertisement
Guest User

Untitled

a guest
Mar 4th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. /* Credits to zC00l; Edited using Dirty c0w exploit*/
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <crypt.h>
  6. #include <string.h>
  7. const char* salt = "zc00l";
  8. const char* common_passwd_file = "/etc/passwd";
  9. struct Userinfo {
  10. char *username;
  11. char *hash;
  12. int user_id;
  13. int group_id;
  14. char *info;
  15. char *home_dir;
  16. char *shell;
  17. };
  18. char *generate_password_hash(char *plaintext_pw) {
  19. return crypt(plaintext_pw, salt);
  20. }
  21. char *generate_passwd_line(struct Userinfo u) {
  22. const char *format = "%s:%s:%d:%d:%s:%s:%s\n";
  23. int size = snprintf(NULL, 0, format, u.username, u.hash,
  24. u.user_id, u.group_id, u.info, u.home_dir, u.shell);
  25. char *ret = malloc(size + 1);
  26. sprintf(ret, format, u.username, u.hash, u.user_id,
  27. u.group_id, u.info, u.home_dir, u.shell);
  28. return ret;
  29. }
  30. int main(int argc, char **argv)
  31. {
  32. struct Userinfo user;
  33. user.username = "root";
  34. user.user_id = 0;
  35. user.group_id = 0;
  36. user.info = "root";
  37. user.home_dir = "/root";
  38. user.shell = "/bin/sh";
  39. char* plaintext_pw;
  40. if (argc >= 2) {
  41. plaintext_pw = argv[1];
  42. printf("Please enter the new password: %s\n", plaintext_pw);
  43. } else {
  44. plaintext_pw = getpass("Please enter the new password: ");
  45. }
  46. user.hash = generate_password_hash(plaintext_pw);
  47. char *complete_passwd_line = generate_passwd_line(user);
  48. strtok(complete_passwd_line, "\n");
  49. printf("User line: %s/", complete_passwd_line);
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement