Use of a One-Way Hash without a Salt

Incomplete Variant
Structure: Simple
Description

This vulnerability occurs when a system uses a one-way hash function (like MD5 or SHA-256) to protect sensitive data like passwords, but fails to add a unique random value called a salt before hashing.

Extended Description

Without a salt, identical passwords produce identical hash values. This allows attackers to use pre-computed tables of common password hashes, known as rainbow tables, to quickly reverse the hash and discover the original password. Salting ensures every hash is unique, even for identical passwords, rendering these pre-computed attacks ineffective. However, it's important to understand that salting alone is not a complete defense against determined attackers with significant resources, like cloud computing or specialized hardware. While it prevents rainbow table attacks, it doesn't significantly slow down targeted brute-force or dictionary attacks if the underlying hash function is fast to compute. For true password security, a salt must be combined with intentionally slow, adaptive hash functions designed for password storage (like bcrypt, scrypt, or Argon2), as detailed in CWE-916.

Common Consequences 1
Scope: Access Control

Impact: Bypass Protection MechanismGain Privileges or Assume Identity

If an attacker can gain access to the hashes, then the lack of a salt makes it easier to conduct brute force attacks using techniques such as rainbow tables.

Detection Methods 6
Automated Static Analysis - Binary or BytecodeSOAR Partial
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Bytecode Weakness Analysis - including disassembler + source code weakness analysis Binary Weakness Analysis - including disassembler + source code weakness analysis
Manual Static Analysis - Binary or BytecodeSOAR Partial
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Binary / Bytecode disassembler - then use manual analysis for vulnerabilities & anomalies
Manual Static Analysis - Source CodeHigh
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Focused Manual Spotcheck - Focused manual analysis of source Manual Source Code Review (not inspections)
Automated Static Analysis - Source CodeHigh
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Source code Weakness Analyzer Context-configured Source Code Weakness Analyzer
Automated Static AnalysisSOAR Partial
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Configuration Checker
Architecture or Design ReviewHigh
According to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Formal Methods / Correct-By-Construction ``` Cost effective for partial coverage: ``` Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)
Potential Mitigations 3
Phase: Architecture and Design
Use an adaptive hash function that can be configured to change the amount of computational effort needed to compute the hash, such as the number of iterations ("stretching") or the amount of memory required. Some hash functions perform salting automatically. These functions can significantly increase the overhead for a brute force attack compared to intentionally-fast functions such as MD5. For example, rainbow table attacks can become infeasible due to the high computing overhead. Finally, since computing power gets faster and cheaper over time, the technique can be reconfigured to increase the workload without forcing an entire replacement of the algorithm in use. Some hash functions that have one or more of these desired properties include bcrypt [REF-291], scrypt [REF-292], and PBKDF2 [REF-293]. While there is active 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

Phase: Architecture and Design
If a technique that requires extra computational effort can not be implemented, then for each password that is processed, generate a new random salt using a strong random number generator with unpredictable seeds. Add the salt to the plaintext password before hashing it. When storing the hash, also store the salt. Do not use the same salt for every password.

Effectiveness: Limited

Phase: ImplementationArchitecture and Design
When using industry-approved techniques, use them correctly. Don't cut corners by skipping resource-intensive steps (Missing Cryptographic Step). These steps are often essential for preventing common attacks.
Demonstrative Examples 2

ID : DX-101

In both of these examples, a user is logged in if their given password matches a stored password:

Code Example:

Bad
C
c

//Login if hash matches stored hash* if (equal(ctext, secret_password())) { ``` login_user(); } }

Code Example:

Bad
Java
java

//Login if hash matches stored hash* if (equal(digest,secret_password())) { ``` login_user(); }

This code relies exclusively on a password mechanism (Use of Password System for Primary Authentication) using only one factor of authentication (Use of Single-factor Authentication). 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 (Use of Weak Hash). It also does not use a salt (Use of a One-Way Hash without a Salt).

ID : DX-207

In this example, a new user provides a new username and password to create an account. The program hashes the new user's password then stores it in a database.

Code Example:

Bad
Python
python

UpdateUserLogin returns True on success, False otherwise*

python
While it is good to avoid storing a cleartext password, the program does not provide a salt to the hashing function, thus increasing the chances of an attacker being able to reverse the hash and discover the original password if the database is compromised.
Fixing this is as simple as providing a salt to the hashing function on initialization:

Code Example:

Good
Python
python

UpdateUserLogin returns True on success, False otherwise*

python
Note that regardless of the usage of a salt, the md5 hash is no longer considered secure, so this example still exhibits Use of a Broken or Risky Cryptographic Algorithm.
Observed Examples 2
CVE-2008-1526Router does not use a salt with a hash, making it easier to crack passwords.
CVE-2006-1058Router does not use a salt with a hash, making it easier to crack passwords.
References 18
bcrypt
Johnny Shelley
ID: REF-291
Tarsnap - The scrypt key derivation function and encryption utility
Colin Percival
ID: REF-292
RFC2898 - PKCS #5: Password-Based Cryptography Specification Version 2.0
B. Kaliski
2000
ID: REF-293
How To Safely Store A Password
Coda Hale
31-01-2010
ID: REF-294
How Companies Can Beef Up Password Security (interview with Thomas H. Ptacek)
Brian Krebs
11-06-2012
ID: REF-295
Password security: past, present, future
Solar Designer
2012
ID: REF-296
Our password hashing has no clothes
Troy Hunt
26-06-2012
ID: REF-297
Password Storage Cheat Sheet
OWASP
ID: REF-631
Enough With The Rainbow Tables: What You Need To Know About Secure Password Schemes
Thomas Ptacek
10-09-2007
ID: REF-632
The Importance of Being Canonical
Robert Graham
02-02-2009
ID: REF-633
Password Hashing
James McGlinn
ID: REF-634
Rainbow Hash Cracking
Jeff Atwood
08-09-2007
ID: REF-635
Speed Hashing
Jeff Atwood
06-04-2012
ID: REF-636
Rainbow table
Wikipedia
03-03-2009
ID: REF-637
Writing Secure Code
Michael Howard and David LeBlanc
Microsoft Press
04-12-2002
ID: REF-7
The Art of Software Security Assessment
Mark Dowd, John McDonald, and Justin Schuh
Addison Wesley
2006
ID: REF-62
State-of-the-Art Resources (SOAR) for Software Vulnerability Detection, Test, and Evaluation
Gregory Larsen, E. Kenneth Hong Fong, David A. Wheeler, and Rama S. Moorthy
07-2014
ID: REF-1479
Modes of Introduction
Implementation