예제 #1
0
static int single_process_buffer(struct db_salt *salt)
{
    struct db_salt *current;
    struct db_keys *keys;
    size_t size;

    if (crk_process_salt(salt))
        return 1;

    /*
     * Flush the keys list (since we've just processed the keys), but not the hash
     * table to allow for more effective checking for duplicates.  We could flush
     * the hash table too, such as by calling single_alloc_keys() here, which would
     * allow us to drop the update-hash-before-list-entry-reuse code from
     * single_add_key().  This would speed things up in terms of this source file's
     * code overhead, however it would allow more duplicates to pass.  The apparent
     * c/s rate (counting duplicates as if they were distinct combinations) would
     * be higher, but the number of passwords cracked per unit of time might be
     * lower or higher depending on many things including the relative speed of
     * password hash computations vs. the "overhead".
     */
    keys = salt->keys;
    keys->count = keys->count_from_guesses = 0;
    keys->ptr = keys->buffer;
    keys->lock++;

    if (guessed_keys->count) {
        keys = mem_alloc(size = sizeof(struct db_keys) - 1 +
                                length * guessed_keys->count);
        memcpy(keys, guessed_keys, size);

        keys->ptr = keys->buffer;
        do {
            current = single_db->salts;
            do {
                if (current == salt || !current->list)
                    continue;

                if (single_add_key(current, keys->ptr, 1))
                    return 1;
            } while ((current = current->next));
            keys->ptr += length;
        } while (--keys->count);

        MEM_FREE(keys);
    }

    keys = salt->keys;
    keys->lock--;
    if (!keys->count && !keys->lock)
        keys->rule = rule_number;

    return 0;
}
예제 #2
0
static int single_process_pw(struct db_salt *salt, struct db_password *pw,
                             char *rule)
{
    struct list_entry *first, *second;
    int first_number, second_number;
    char pair[RULE_WORD_SIZE];
    int split;
    char *key;

    if (!(first = pw->words->head))
        return -1;

    first_number = 0;
    do {
        if ((key = rules_apply(first->data, rule, 0, NULL)))
            if (ext_filter(key))
                if (single_add_key(salt, key, 0))
                    return 1;
        if (!salt->list)
            return 2;
        if (!pw->binary)
            return 0;

        if (++first_number > words_pair_max)
            continue;

        if (!CP_isLetter[(unsigned char)first->data[0]])
            continue;

        second_number = 0;
        second = pw->words->head;

        do
            if (first != second) {
                if ((split = strlen(first->data)) < length) {
                    strnzcpy(pair, first->data, RULE_WORD_SIZE);
                    strnzcat(pair, second->data, RULE_WORD_SIZE);

                    if ((key = rules_apply(pair, rule, split, NULL)))
                        if (ext_filter(key))
                            if (single_add_key(salt, key, 0))
                                return 1;
                    if (!salt->list)
                        return 2;
                    if (!pw->binary)
                        return 0;
                }

                if (first->data[1]) {
                    pair[0] = first->data[0];
                    pair[1] = 0;
                    strnzcat(pair, second->data, RULE_WORD_SIZE);

                    if ((key = rules_apply(pair, rule, 1, NULL)))
                        if (ext_filter(key))
                            if (single_add_key(salt, key, 0))
                                return 1;
                    if (!salt->list)
                        return 2;
                    if (!pw->binary)
                        return 0;
                }
            }
        while (++second_number <= words_pair_max &&
                (second = second->next));
    } while ((first = first->next));

    return 0;
}
예제 #3
0
static int single_process_pw(struct db_salt *salt, struct db_password *pw,
	char *rule)
{
	struct db_keys *keys;
	struct list_entry *first, *second;
	int first_number, second_number;
	char pair[RULE_WORD_SIZE];
	int split;
	char *key;
	unsigned int c;

	if (!(first = pw->words->head))
		return -1;

	keys = salt->keys;

	first_number = 0;
	do {
		if ((key = rules_apply(first->data, rule, 0, NULL)))
		if (ext_filter(key))
		if (single_add_key(keys, key))
		if (single_process_buffer(salt)) return 1;
		if (!salt->list) return 2;
		if (!pw->binary) return 0;

		if (++first_number > SINGLE_WORDS_PAIR_MAX) continue;

		c = (unsigned int)first->data[0] | 0x20;
		if (c < 'a' || c > 'z') continue;

		second_number = 0;
		second = pw->words->head;

		do
		if (first != second) {
			if ((split = strlen(first->data)) < length) {
				strnzcpy(pair, first->data, RULE_WORD_SIZE);
				strnzcat(pair, second->data, RULE_WORD_SIZE);

				if ((key = rules_apply(pair, rule, split, NULL)))
				if (ext_filter(key))
				if (single_add_key(keys, key))
				if (single_process_buffer(salt)) return 1;
				if (!salt->list) return 2;
				if (!pw->binary) return 0;
			}

			if (first->data[1]) {
				pair[0] = first->data[0];
				pair[1] = 0;
				strnzcat(pair, second->data, RULE_WORD_SIZE);

				if ((key = rules_apply(pair, rule, 1, NULL)))
				if (ext_filter(key))
				if (single_add_key(keys, key))
				if (single_process_buffer(salt)) return 1;
				if (!salt->list) return 2;
				if (!pw->binary) return 0;
			}
		} while (++second_number <= SINGLE_WORDS_PAIR_MAX &&
			(second = second->next));
	} while ((first = first->next));

	return 0;
}