Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

SV.WEAK_CRYPTO.WEAK_HASH

Weak password vulnerability

Brute-force password cracking is one of the most dangerous threats to password security. If the software's encryption scheme isn't strong enough for the level of protection needed, brute-force attacks can succeed using current attack methods and resources. The SV.WEAK_CRYPTO.WEAK_HASH checker flags encrypt, crypt*, and setkey encryption sequences that use DES encryption, which doesn't provide sufficient protection against brute-force password attacks.

Vulnerability and risk

When sensitive data is protected insufficiently, it can lead to loss of the secrecy or integrity of the data. DES encryption can be cracked using brute-force attacks. The MD5-based algorithm is slightly more secure, so it's preferred over the DES-based algorithm, but even the newer SHA-1 algorithm has been cracked. Hash algorithms like the SHA-256 and SHA-512, which are approved by Federal Information Processing Standards (FIPS), are considered more secure. It's important to use a cryptographic algorithm that is currently considered to be the best by experts in the field.

Mitigation and prevention

To avoid poor encryption issues:

  • Use the strongest encryption algorithm possible from proven, secure crypto libraries.
  • If your code is accessing an existing privileged service, let the service handle authentication.
  • Don't hard-code sensitive data or store encryption keys.
  • If you use MD5-based encryption, make sure you include a salt parameter (a string starting with "$1$") to vary the encryption algorithm.

Vulnerable code example

1   #include <stdio.h>
2   #include <time.h>
3   #include <unistd.h>
4   #include <crypt.h>
5    
6   int
7   main(void)
8   {
9     unsigned long seed[2];
10    char salt[] = "$1$........";
11    const char *const seedchars =
12      "./0123456789ABCDEFGHIJKLMNOPQRST"
13      "UVWXYZabcdefghijklmnopqrstuvwxyz";
14    char *password;
15    int i;
16   
17    /* Generate a (not very) random seed.
18       You can do it better than this... */
19    seed[0] = time(NULL);
20    seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);
21   
22    /* Turn it into printable characters from ‘seedchars’. */
23    for (i = 0; i < 8; i++)
24      salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];
25  
26    /* Read in the user’s password and encrypt it. */
27    password = crypt(getpass("Password:"), salt); // SV.WEAK_CRYPTO.WEAK_HASH is reported here
28  
29    /* Print the results. */
30    puts(password);
31    return 0;
32  }