alpine 3.9
crypto weakness #14

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.

 static char * _hash_sha512(char const * password, char const * salt)
{
	const char prefix[] = "$ 6$ ";
	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;
	}
	len = sizeof(prefix) + strlen(salt);
	if((s = malloc(len)) == NULL)
	{
		_error("malloc", 1);
		free(p);
		return NULL;
	}
	snprintf(s, len, "%s%s", prefix, salt);
	ret = crypt(password, s);
	free(p);
	free(s);
	if(ret == NULL)
		_error("crypt", 1);
	else if(strncmp(ret, prefix, sizeof(prefix) - 1) != 0)
	{
		errno = ENOTSUP;
		_error("sha512", 1);
		ret = NULL;
	}
	else if((ret = strdup(ret)) == NULL)
		_error("malloc", 1);
	return ret;
}

static char * _hash_shmd5(char const * password, char const * salt)
{
	const char prefix[] = "$ 1$ ";
	const char characters[] = "!\"%&'()*+,-./ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		"abcdefghijklmnopqrstuvwxyz0123456789:;<=>?@[\\]^_'";
	char * ret;
	char * p = NULL;
	size_t len;
	char * s;
 

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.