Tag: crypt
crypt() Tool
12. November 2012 04:29

Tool, welches crypt() nutzt, um MD5 und DES Unix-Shadow Passwörter zu erzeugen.

                    /*
 * 	Simple crypt()
 * 	Sebastian Kricner
 * 	tuxwave.net
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <crypt.h>
#include <string.h>

static void usage(char *arg);

int main(int argc, char *argv[], char *envp[])
{

	if(argc == 1) usage(argv[0]);
	char *password, *salt;
	int opt;
	while((opt = getopt(argc, argv, "hp:s:")) != -1)
	{
		switch(opt)
		{
			case 'p':
				password = optarg;
				break;
			case 's':
				salt = optarg;
				break;
			case 'h':
			case '?':
				usage(argv[0]);
				break;
		}
	}
	if(password != (void *)0 && salt != (void *)0)
	{
		char *result = crypt(password, salt);
		printf("DES: %s\n", result);

		char *buff = malloc(strlen(salt)+4);
		memcpy(buff, "$1$", 3);
		memcpy(buff+3, salt, strlen(salt));
		result = crypt(password, buff);
		if(strlen(salt) > 8)
		{
			fprintf(stderr, "Warning: MD5 does only use up to "
			"8 characters in salt\n");
		}
		printf("MD5: %s\n", result, buff);
	}
	exit(EXIT_SUCCESS);
}

void usage(char *arg)
{
	printf("Usage:\n");
	printf("%s -p password -s salt\n", arg);
	exit(EXIT_SUCCESS);
}

                    
        
Download