TechKnowSurge
CompTIA Security+ 1.4 ISC2 CISSP 3.7 NIST 800-53 IA-5 EC-Council CEH 9.1 ISC2 CISSP 3.6 CompTIA SecurityX 2.3
VideoSecurityFree

Salt, Pepper, Key-Stretching

Salting, peppering, and key stretching are cryptographic techniques used to strengthen password storage and defend against common hash-cracking methods such as rainbow table lookups and brute-force attacks.

Complete this video to capture a CTF flag worth 1 point.

About this video

Hashing converts plaintext passwords into fixed-length values before storage, but hashed credentials are not immune to attack. Adversaries who obtain a password database can use rainbow tables, which are precomputed mappings of plaintext passwords to their hash equivalents, to recover credentials quickly, particularly when users have chosen weak or common passwords. Brute-force and dictionary attacks present a similar threat, systematically testing large volumes of candidate passwords until a matching hash is found. Salting addresses the rainbow table threat by appending a unique random value to each password before it is hashed. Because the salt changes the input, even identical passwords produce entirely different hash outputs, rendering precomputed tables useless. Each salt value must be stored alongside the user record so the system can reconstruct the hash during authentication. This storage requirement means that if the database is compromised, the salt values are exposed as well, leaving salted hashes still vulnerable to targeted guessing attacks where an attacker simply factors the known salt into each attempt. Peppering introduces a secondary secret value that functions similarly to a salt but is stored outside the credential database, typically within application code or a separate hardware location. If the database is stolen without the pepper, an attacker lacks a critical input needed to validate guesses, significantly raising the difficulty of cracking the hashes. Key stretching adds another layer by passing the password and its associated salt or pepper through the hashing algorithm many times in succession, increasing the computational cost of each verification attempt. This overhead is calibrated to remain acceptable for legitimate authentication while making large-scale automated cracking prohibitively slow. Used in combination, salting, peppering, and key stretching provide a practical, defense-in-depth approach to protecting stored password data.

What you'll learn

What's covered

Salting, Peppering & Key Stretching

Aligned to

CompTIA Security+
1.4 Explain the importance of using appropriate cryptographic solutions.
ISC2 CISSP
3.7 Understand methods of cryptanalytic attacks
3.6 Select and determine cryptographic solutions
NIST 800-53
IA-5 Authenticator Management
EC-Council CEH
9.1 Cryptography
CompTIA SecurityX
2.3 Given a scenario, implement appropriate cryptographic protocols and algorithms.

Key terms

Hash Function
A mathematical algorithm that converts input data of any size into a fixed-size output value used to verify data integrity.
Rainbow Table
A precomputed lookup table used to reverse cryptographic hash functions, allowing attackers to recover plaintext passwords from stolen hashed credentials. Rainbow table attacks are defeated by adding a unique salt to each password before hashing.
Brute Force Attack
An attack method that systematically tries all possible combinations of passwords or keys until the correct one is found.
Salting
The practice of appending a unique random value to a password before hashing to prevent rainbow table lookups and ensure identical passwords produce different hash outputs.
Peppering
The practice of appending a secret value to a password before hashing, where that value is stored separately from the password database to add a layer of protection against database theft.
Key Stretching
A technique that increases the computational cost of hashing by running the hash function many times, slowing down brute-force guessing attacks.

Topics

Cryptography Password Hashing Salting Peppering Key Stretching Rainbow Table Attacks Brute Force Attacks

Transcript

The scenario

In our scenario we have a database, and on that database we have a table with both usernames and passwords on there. So obviously this is bad: there's somebody out there that now has our usernames and passwords.

Thankfully, the way we stored our passwords was using a hashing algorithm. So the passwords got put into a hashing algorithm and then we store the hash values here instead of the actual clear text password. That's going to make it more difficult for any hacker to be able to hack these passwords.

So what are they going to do? They're going to run a program against this that's going to try all sorts of combinations, perhaps thousands or hundreds of thousands or millions of different combinations, to see if it will crack this. It'll try dictionary words, patterns, common substitutions. It will just try a bunch of different combinations of things, passwords that are out there, to see if it can figure out what the passwords are.

Rainbow tables

Not only are they going to use software to try to guess at the passwords associated with these different hashes, but they're also going to use a rainbow table. What we've done is we've used some sort of algorithm, perhaps it's SHA, to switch the password into a hash. Well, there are tables out there that already have this compiled for them, so a password has already been converted into a hash, and all they need to do is look up the hash to find out what the password is.

So for this instance we have G house right here, who is in this rainbow table, and so they can look up the password. This is going to be for anybody that has bad password management or bad ways of creating their passwords, and that's going to be the majority of people unless they've been trained well, or unless they've been forced to create good passwords. So this is going to be a problem, because the rainbow tables are going to be very effective on many of the users. The majority of users aren't going to have great passwords unless they've been properly trained or they're forced to create good passwords.

Salting

So what we can do as part of our system is something called salting. What salting is, is adding an additional value to the password before it gets hashed. Once it gets hashed, the value is going to look quite a bit different than if it was just the password alone, and that's what's going to get stored in the password database. Now when a user logs in, they're going to type in their password, it's going to add the salt value to that, put it through the algorithm, and then compare it against the password table to authenticate, or make sure that that person is who they are.

Rainbow tables do have their limits. They have to be pre-populated, so it goes through a lot of different combinations of passwords and then it figures out the hashes for those, and at some point in time longer passwords become unfeasible to really create a hashing table from, or a rainbow table from. So longer passwords are what gets rid of, or doesn't get rid of it entirely, but helps mitigate against rainbow table attacks. By adding the salting to this, we added so much length to it that it becomes a lot less likely that it's going to show up in these rainbow tables.

Salting does have some limitations though. Although it guards against these rainbow table attacks, these values need to be stored somewhere. The salt values need to be stored somewhere, and it's per user, so because it's per user it's probably going to be stored on the same table or same database that these usernames and passwords are stored on. So if somebody steals the database, they've now stolen the salt value with that. It still guards against the rainbow table in this scenario, but it doesn't guard against guessing, because they still can guess a lot of different passwords and just add the salt value that's inside of this database, and then be able to figure out what the hashed value is, or guess against the hash value. So it still doesn't guard against guessing.

Pepper

Pepper is a very similar concept. It creates a pepper value that, with the password, creates a very unique hash here. But the difference is that instead of storing this pepper value with the table or in the database, it stores it in another location. Perhaps it's some sort of hardware location, perhaps it's within the code. So it's stored in another location instead of with this information, so if this information is stolen, the pepper value is not compromised, and it becomes that much more difficult for an attacker to be able to figure out what these passwords are.

There are a couple of problems with pepper though. Number one is that to store this in a separate location for each one of your users could have a compute problem with it. It could slow down this whole process of authentication and be problematic, plus take up a lot of resources, so it could just be resource intensive. What we can do often to combat that is we just have one pepper and we store it inside the code or somewhere else. The problem with that though is that if that one pepper gets compromised, it makes it easier for a hacker to be able to hack these, because it's just a known value. It's one of the reasons why we'd want to do both a salt and a pepper. But it still doesn't guard against something like an internal threat who has access to both of those.

Key stretching

One thing we can add to all of this is called key stretching. If this was a stolen database and somebody was trying to figure out the password to this user right here, they could try a bunch of different values to see if they come up with the same hash value, and they're going to try a lot of different calculations to do that, a lot of different passwords to do that. But if, on every iteration, every time they try to guess at a password, we can stretch how long that takes to computationally figure out, that is going to create a barrier for the person trying to hack these databases, trying to figure out what these hashes are.

So what we do is we create this computational load on there that's high enough that somebody can't make a lot of guesses over and over and over again, but doesn't create such a big load on it that we have difficulty calculating it ourselves. So we need to make sure we keep that in mind as well.

There are multiple ways that we can stretch out the processing power of this, but one example is maybe that instead of just putting it through our hashing algorithm once, we put it through a hundred times, or maybe it's a thousand times, or it's a lot of times that we're going to put it through this whole process. So that whole process of taking the pepper or the salt and adding it to the password and then running it through our hashing algorithm takes a much longer computational time to be able to figure out what this hash is, therefore slowing down somebody's ability to test a lot of passwords against a lot of users all at the same time.

Pulling it together

We started out with the scenario of our database getting stolen that had usernames and passwords on it. We talked about how using salt with the password before it gets hashed can help mitigate or help guard against the use of rainbow tables. We also talked about how adding pepper will help guard against the brute force attacks of just guessing a bunch of different passwords, and how key stretching can help add additional levels of security to our database in case it ever got stolen.

About TechKnowSurge

TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.

Explore free tools and programs →