808
debate about which of these is the most effective, they are all stronger than using salts with
hash functions with very little computing overhead. Note that using these functions can have an
impact on performance, so they require special consideration to avoid denial-of-service attacks.
However, their configurability provides finer control over how much CPU and memory is used, so
it could be adjusted to suit the environment's needs.
Effectiveness = High
Demonstrative Examples
Example 1:
In both of these examples, a user is logged in if their given password matches a stored password:
Example Language: C (Bad)
unsigned char *check_passwd(char *plaintext) {
ctext = simple_digest("sha1",plaintext,strlen(plaintext), ... );
//Login if hash matches stored hash
if (equal(ctext, secret_password())) {
login_user();
}
}
Example Language: Java (Bad)
String plainText = new String(plainTextIn);
MessageDigest encer = MessageDigest.getInstance("SHA");
encer.update(plainTextIn);
byte[] digest = password.digest();
//Login if hash matches stored hash
if (equal(digest,secret_password())) {
login_user();
}
This code relies exclusively on a password mechanism (CWE-309) using only one factor of
authentication (CWE-308). If an attacker can steal or guess a user's password, they are given full
access to their account. Note this code also uses SHA-1, which is a weak hash (CWE-328). It also
does not use a salt (CWE-759).
Example 2:
In 2022, the OT:ICEFALL study examined products by 10 different Operational Technology (OT)
vendors. The researchers reported 56 vulnerabilities and said that the products were "insecure by
design" [REF-1283]. If exploited, these vulnerabilities often allowed adversaries to change how the
products operated, ranging from denial of service to changing the code that the products executed.
Since these products were often used in industries such as power, electrical, water, and others,
there could even be safety implications.
At least one OT product used weak hashes.
Example 3:
The example code below is taken from the JTAG access control mechanism of the Hack@DAC'21
buggy OpenPiton SoC [REF-1360]. Access to JTAG allows users to access sensitive information in
the system. Hence, access to JTAG is controlled using cryptographic authentication of the users.
In this example (see the vulnerable code source), the password checker uses HMAC-SHA256
for authentication. It takes a 512-bit secret message from the user, hashes it using HMAC, and
compares its output with the expected output to determine the authenticity of the user.
Example Language: Verilog (Bad)
...
logic [31:0] data_d, data_q
logic [512-1:0] pass_data;
CWE Version 4.14
CWE-328: Use of Weak Hash
CWE-328: Use of Weak Hash