alpine 3.9
crypto weakness #13

4

Weakness Breakdown


Definition:

This weakness involves creating non-standard or non-tested algorithms, using weak algorithms or applying cryptographic algorithms incorrectly. Algorithms that were once considered safe are commonly later found to be unsafe, as the algorithms were broken.

Warning code(s):

The crypt functions use a poor one-way hashing algorithm; since they only accept passwords of 8 characters or fewer and only a two-byte salt, they are excessively vulnerable to dictionary attacks given today's faster computing equipment.

File Name:

makepasswd/src/makepasswd-0.5.3/src/makepasswd.c

Context:

The highlighted line of code below is the trigger point of this particular Alpine 3.9 crypto weakness.

 	char * p = NULL;
	size_t len;
	char * s;

	if(iterations <= 0)
#if 0 /* XXX ideal situation */
		iterations = rand() % (1 << 31);
#else /* more realistic */
		iterations = rand() % (1 << 18);
#endif
	if(salt == NULL)
	{
		if((p = _makepasswd_password(characters, 8, 64)) == NULL)
			return NULL;
		salt = p;
	}
	len = sizeof(prefix) + 11 + strlen(salt) + 1;
	if((s = malloc(len)) == NULL)
	{
		_error("malloc", 1);
		free(p);
		return NULL;
	}
	snprintf(s, len, "%s%u%c%s", prefix, iterations, '$ ', salt);
	ret = crypt(password, s);
	free(p);
	free(s);
	if(ret == NULL)
		_error("crypt", 1);
	else if((ret = strdup(ret)) == NULL)
		_error("malloc", 1);
	return ret;
}

static char * _hash_sha256(char const * password, char const * salt)
{
	const char prefix[] = "$ 5$ ";
	const char characters[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		"abcdefghijklmnopqrstuvwxyz0123456789./";
	char * ret;
	char * p = NULL;
	size_t len;
	char * s;

	if(salt == NULL)
	{
		if((p = _makepasswd_password(characters, 16, 16)) == NULL)
			return NULL;
		salt = p;
	} 

The registered trademark Linux® is used pursuant to a sublicense from the Linux Foundation, the exclusive licensee of Linus Torvalds, owner of the mark on a world­wide basis.