示例#1
0
int main(int argc, char **argv) {
	char Buf[256], *cps, *cph;

	Setup();
	ParseOptions(argc, argv);
	if (simple_to_from_hex)
		return simple_convert();

	// if no input redirection then give usage. I 'guess' we could allow
	// a user to type in hashes, but is that really likely?  It is almost
	// certain that if there is no input redirection, the user does not
	// know how to use the tool, so tell him how.
	if (isatty(fileno(stdin)))
		usage(argv[0]);

	FGETS(Buf, sizeof(Buf), stdin);
	while (!feof(stdin)) {
		strtok(Buf, "\r\n");
		if (!leading_salt) {
			cph = Buf;
			cps = &Buf[hash_len];
			if (salt_sep && *cps == salt_sep) ++cps;
		} else {
			cps = Buf;
			cph = &Buf[leading_salt];
			if (salt_sep && *cph == salt_sep) {*cph++ = 0;}
		}
		printf("$dynamic_%d$%*.*s$%s\n", dyna_num, hash_len,hash_len, cph, GetSalt(cps));
		FGETS(Buf, sizeof(Buf), stdin);
	}
	MEMDBG_PROGRAM_EXIT_CHECKS(stderr);
	return 0;
}
示例#2
0
void * mem_calloc_func(size_t count,
					   size_t size
#if defined(MEMDBG_ON)
					   ,
					   char * file,
					   int line
#endif
					   )
{
	void * res;

	if (!count || !size) return NULL;
#if defined(MEMDBG_ON)
	size *= count;
	res = (char *) MEMDBG_alloc(size, file, line);
	memset(res, 0, size);
#else
	res = calloc(count, size);
#endif
	if (!res)
	{
		fprintf(stderr,
				"mem_calloc(): %s trying to allocate " Zu " bytes\n",
				strerror(ENOMEM),
				count * size);
		MEMDBG_PROGRAM_EXIT_CHECKS(stderr);
		perror("mem_calloc");
	}

	return res;
}
示例#3
0
int keyring2john(int argc, char **argv)
{
	int i = 1;

	if (argc < 2)
		return usage();
	for (; i < argc; i++)
		process_file(argv[i]);

	MEMDBG_PROGRAM_EXIT_CHECKS(stderr);

	return 0;
}
示例#4
0
int kwallet2john(int argc, char **argv)
{
	int i;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <.kwl file(s)>\n", argv[0]);
		exit(-1);
	}

	for (i = 1; i < argc; i++)
		process_file(argv[i]);

	MEMDBG_PROGRAM_EXIT_CHECKS(stderr);
	return 0;
}
示例#5
0
文件: calc_stat.c 项目: mimaun/Rose
int main(int argc, char * * argv)
{
	FILE * fichier;
	char * ligne;
	int i;
	int j;
	int np;
	int npflag;
	int args;
	unsigned int nb_lignes;
	unsigned int nb_lettres;

	FILE * statfile;

	if( (argc!=3) && (argc!=4) )
	{
		fprintf(stderr, "Usage: %s [-p] dictionary_file statfile\n\t-p: include non printable and 8-bit characters\n", argv[0]);
		return -1;
	}

	if(argc==4)
	{
		if(strcmp(argv[1], "-p"))
		{
			fprintf(stderr, "Usage: %s [-p] dictionary_file statfile\n\t-p: include non printable and 8-bit characters\n", argv[0]);
			return -1;
		}
		args = 1;
		npflag = 1;
	}
	else
	{
		args = 0;
		npflag = 0;
	}

	fichier = fopen(argv[1+args], "r");
	if(!fichier)
	{
		fprintf(stderr, "could not open %s\n", argv[1+args]);
		return -1;
	}

	first = malloc( sizeof(unsigned int) * 256 );

	ligne = malloc(4096);

	proba2 = malloc(sizeof(unsigned int) * 256 * 256);
	proba1 = malloc(sizeof(unsigned int) * 256 );
	memset(proba2, 0, sizeof(unsigned int) * 256 * 256);
	memset(proba1, 0, sizeof(unsigned int) * 256 );

	statfile = fopen(argv[2+args], "w");

	nb_lignes = 0;
	while(fgets(ligne, 4096, fichier))
	{
		if (ligne[0] == 0)
			continue;
		i = strlen(ligne)-1;
		while( (i>0) && ((ligne[i]=='\n') || (ligne[i]=='\r')) )
		{
			ligne[i]=0;
			i--;
		}
		for(i=0;ligne[i];i++)
		{
			np = 0;
			if (!npflag) {
				if(C2I(ligne[i])<32)
				{
					fprintf(stderr,
					        "Warning, skipping non printable character 0x%02x line %d offset %d: %s\n",
					        (unsigned char)ligne[i], nb_lignes, i, ligne);
					np += 1;
				}
				if(C2I(ligne[i])>127)
				{
					fprintf(stderr,
					        "Warning, skipping non-ASCII character 0x%02x line %d offset %d: %s\n",
					        (unsigned char)ligne[i], nb_lignes, i, ligne);
					np += 1;
				}
				if((i>0) && (C2I(ligne[i-1])<32))
				{
					np += 2;
				}
				if((i>0) && (C2I(ligne[i-1])>127))
				{
					np += 2;
				}
			}
			if( (i==0) && ((np == 0) || (npflag == 1)) )
				proba1[C2I(ligne[0])]++;
			if( (i>0) && ((np == 0) || (npflag == 1)) )
				proba2[C2I(ligne[i-1])*256 + C2I(ligne[i])]++;
		}
		nb_lignes++;
	}

	for(i=0;i<256;i++)
	{
		if ( (proba1[i] == 0 ) || (i==0) )
		{
			proba1[i] = 1000;
		}
		else
		{
			if( (unsigned int) (- 10*log( (double) proba1[i] / (double) nb_lignes )) == 0)
			{
				fprintf(stderr, "zero -10*log proba1[%d] (%d) / %d converted to 1\n", i, proba1[i], nb_lignes);
				proba1[i] = 1;
			}
			else
				proba1[i] = (unsigned int) (- 10*log( (double) proba1[i] / (double) nb_lignes ));
			fprintf(statfile, "%d=proba1[%d]\n", proba1[i], i);
		}

		/* premiere passe : nb lettres */
		nb_lettres = 0;
		for(j=0;j<256;j++)
		{
			nb_lettres += proba2[i*256 + j];
		}

		first[i] = 255;

		/* maintenant, calcul des stats */
		for(j=0;j<256;j++)
		{
			if( proba2[i*256 + j] == 0 )
			{
				proba2[i*256 + j] = 1000;
			}
			else
			{
				if(first[i] == 255)
					first[i] = j;
				if((unsigned int) (- 10*log( (double) proba2[i*256+j] / (double) nb_lettres )) == 0)
				{
					fprintf(stderr, "zero -10*log proba2[%d*256+%d] (%d) / %d, converted to 1 to prevent infinite length candidates\n", i, j, proba2[i*256+j],nb_lettres );
					proba2[i*256 + j] = 1;
				}
				else
				{
					proba2[i*256 + j] = (unsigned int) (- 10*log( (double) proba2[i*256+j] / (double) nb_lettres ));
				}
				fprintf(statfile, "%d=proba2[%d*256+%d]\n", proba2[i*256+j], i, j);
			}
		}
	}

	fclose(statfile);

	MEM_FREE(proba1);
	MEM_FREE(proba2);

	MEM_FREE(first);

	MEM_FREE(ligne);
	fclose(fichier);

	MEMDBG_PROGRAM_EXIT_CHECKS(stderr);

	return 0;
}
示例#6
0
int main(int argc, char * * argv)
{
    FILE * fichier;
    char * ligne;
    unsigned int i;
    unsigned int j;
    unsigned int k;
    unsigned int l;
    unsigned long long index;
    unsigned char position[256];
    unsigned int charset;
    unsigned int nb_lignes;

    if(argc < 2 || argc > 3)
    {
        printf("Usage: %s statfile [pwdfile]\n", argv[0]);
        return -1;
    }

    fichier = fopen(argv[1], "r");
    if(!fichier)
    {
        fprintf(stderr, "could not open %s\n", argv[1]);
        return -1;
    }

    first = malloc( sizeof(unsigned char) * 256 );
    if(first == NULL)
    {
        perror("malloc first");
        return 3;
    }

    ligne = malloc(4096);
    if(ligne == NULL) {
        perror("malloc ligne");
        return 3;
    }
    proba2 = malloc(sizeof(unsigned char) * 256 * 256);
    if(proba2 == NULL) {
        perror("malloc proba2");
        free(ligne);
        return 3;
    }
    proba1 = malloc(sizeof(unsigned char) * 256 );
    if(proba1 == NULL) {
        perror("malloc proba1");
        free(ligne);
        return 3;
    }
    for(i=0; i<256*256; i++)
        proba2[i] = UNK_STR;
    for(i=0; i<256; i++)
        proba1[i] = UNK_STR;

    for(i=0; i<256; i++)
    {
        first[i] = 255;
        position[i] = 255;
    }

    nb_lignes = 0;
    charset = 0;
    fprintf(stderr, "reading stats ... [%p]\n", fichier);
    while(fgets(ligne, 4096, fichier))
    {
        if (ligne[0] == 0)
        {
            fprintf(stderr, "empty line?\n");
            continue;
        }
        ligne[strlen(ligne)-1] = 0; // chop
        if( sscanf(ligne, "%d=proba1[%d]", &i, &j) == 2 )
        {
            if( j>255 )
            {
                fprintf(stderr, "invalid line %s\n", ligne);
                continue;
            }
            proba1[j] = i;
            if(position[j] == 255)
            {
                position[j] = charset;
                charset++;
            }
        }
        else if( sscanf(ligne, "%d=proba2[%d*256+%d]", &i, &j, &k) == 3 )
        {
            if( (j>255) || (k>255) )
            {
                fprintf(stderr, "invalid line %s\n", ligne);
                continue;
            }
            if( (first[j]>k) && (i<UNK_STR))
                first[j] = k;
            proba2[j*256+k] = i;
            if(position[k] == 255)
            {
                position[k] = charset;
                charset++;
            }
        }
        else
            fprintf(stderr, "invalid line %s\n", ligne);
        nb_lignes++;
    }
    fprintf(stderr, "%d lines parsed [%p]\n", nb_lignes, fichier);
    fclose(fichier);

    if (argc == 3) {
        fichier = fopen(argv[2], "r");
        if(!fichier)
        {
            fprintf(stderr, "could not open %s\n", argv[2]);
            return -1;
        }
        fprintf(stderr, "scanning password file ...\n");
    } else {
        fichier = stdin;
        fprintf(stderr, "reading from stdin ...\n");
    }
    while(fgets(ligne, 4096, fichier))
    {
        if (ligne[0] == 0)
            continue;
        ligne[strlen(ligne)-1] = 0; // chop
        i=1;
        j=0;
        k=0;
        j = C2I(ligne[0]);
        k = proba1[j];
        if(ligne[0]==0)
            k = 0;
        printf("%s\t%d", ligne, k);
        l = 0;
        index = position[j];
        if(position[j]==255)
            index = 8.1E18;
        while(ligne[i])
        {
            if(index<8E18)
                index = (index*charset)+position[C2I(ligne[i])];
            if(position[C2I(ligne[i])]==255)
                index = 8.1E18;
            printf("+%d", proba2[j*256+C2I(ligne[i])]);
            k+=proba2[j*256+C2I(ligne[i])];
            if(l)
                l+=proba2[j*256+C2I(ligne[i])];
            if(i==2)
                l=proba1[C2I(ligne[i])];
            j = C2I(ligne[i]);
            i++;
        }
        if(index<8E18)
            printf("\t%d\t%d\t%"LLd"\t%d\n",k,i,index,l);
        else
            printf("\t%d\t%d\t-\t%d\n",k,i,l);
    }
    fprintf(stderr, "freeing stuff ...\n");

    fclose(fichier);

    MEM_FREE(proba1);
    MEM_FREE(proba2);

    MEM_FREE(first);

    MEM_FREE(ligne);

    fprintf(stderr, "charsetsize = %d\n", charset);

    MEMDBG_PROGRAM_EXIT_CHECKS(stderr);

    return 0;
}