Introduction
Hashcat is a world-renowned password recovery tool, capable of leveraging the immense processing power of GPUs to crack hashes at incredible speeds. However, to get the most out of your hardware, you need to know how to properly configure and tune it. Using the wrong settings can lead to suboptimal performance or even hardware instability.
In this lab, you will learn how to use several of Hashcat's OpenCL-related flags to manage and optimize your GPU's performance. You will practice listing available devices, selecting a specific GPU for a task, implementing thermal safeguards, and experimenting with performance-tuning options. These skills are essential for anyone looking to use Hashcat effectively and safely.
List Available OpenCL Devices with --opencl-devices
In this step, you will learn how to identify the computational devices that Hashcat can use. Before you can assign a task to a GPU or CPU, you need to know how the system recognizes it. Hashcat provides a specific flag for this purpose.
The --opencl-devices flag queries the system's OpenCL (Open Computing Language) framework and lists all compatible devices, such as GPUs and CPUs. Each device is assigned a unique ID, which you will use in later steps to target it specifically.
Execute the following command in your terminal to list all available OpenCL devices:
hashcat --opencl-devices
You will see an output similar to the following. The exact details, especially the device names and platform information, will vary depending on the lab environment's hardware.
hashcat (v6.2.6) starting
OpenCL Info:
Platform ID #1
Vendor : The pocl project
Name : Portable Computing Language
Version : OpenCL 3.0 PoCL 3.1+g3a94695b, LLVM 14.0.0, RELOC, SLEEF, DISTRO, POCL_DEBUG
Device ID #1
Type : CPU
Vendor ID : 1024
Vendor : GenuineIntel
Name : 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
Version : OpenCL 3.0 PoCL 3.1+g3a94695b, LLVM 14.0.0, RELOC, SLEEF, DISTRO, POCL_DEBUG
Processor(s) : 8
Clock : 3000
...
Platform ID #2
Vendor : NVIDIA Corporation
Name : NVIDIA CUDA
Version : OpenCL 3.0 CUDA 12.2.142
Device ID #2
Type : GPU
Vendor ID : 4318
Vendor : NVIDIA Corporation
Name : NVIDIA T4
Version : OpenCL 3.0 CUDA
Processor(s) : 40
Clock : 1590
...
Take note of the Device ID for each entry. In this example, Device ID #2 is the NVIDIA T4 GPU, which is ideal for hash cracking.
Select a Specific GPU for Cracking with -d
In this step, you will learn how to instruct Hashcat to use a specific device for a cracking task. This is particularly useful in systems with multiple GPUs or when you want to avoid using the CPU, which is generally much slower for this type of work.
The -d (or --devices) flag allows you to specify which device ID(s) to use. You can find the correct ID from the output of the command in the previous step.
We will now run a simple cracking task targeting the GPU. We'll use the hash.txt and wordlist.txt files prepared in your ~/project directory. The command specifies the hash type (-m 0 for MD5), attack mode (-a 0 for a dictionary attack), and the target device. Assuming the GPU is Device ID #2 from our previous example, the command would be:
hashcat -m 0 -a 0 ~/project/hash.txt ~/project/wordlist.txt -d 2
If your GPU has a different ID, please adjust the number after -d accordingly.
After running the command, Hashcat will start the attack exclusively on the specified device and should quickly find the password.
...
Session..........: hashcat
Status...........: Cracked
Hash.Name........: MD5
Hash.Target......: 5d41402abc4b2a76b9719d911017c592
Time.Started.....: ...
Time.Estimated...: ...
Guess.Base.......: File (wordlist.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#2.........: 104.6 kH/s (0.00ms) @ Accel:128 Loops:128 Thr:1024 Vec:1
Recovered........: 1/1 (100.00%) Digests
Progress.........: 2/2 (100.00%)
Rejected.........: 0/2 (0.00%)
Restore.Point....: 1/2 (50.00%)
Restore.Sub.#2...: Salt:0 Amplifier:0-1 Iteration:0-1
Candidates.#2....: wrongpass -> password
Hardware.Mon.#2..: Temp: 40c Fan: 30% Util: 13% Core:1410MHz Mem:5000MHz Bus:16
5d41402abc4b2a76b9719d911017c592:password
Started: ...
Stopped: ...
The output confirms the hash has been cracked and the password is password.
Understand the --gpu-temp-retain Flag
In this step, you will learn about a crucial safety feature for protecting your hardware. Running a GPU at 100% utilization for extended periods generates a significant amount of heat. If not managed, high temperatures can cause thermal throttling (where the GPU slows down to cool off) or even permanent damage.
The --gpu-temp-retain flag tells Hashcat to monitor the GPU's temperature and automatically adjust the workload to keep it at or below a specified Celsius value. This is an excellent way to ensure stability and longevity for your hardware during long cracking sessions.
Let's run the same attack as before, but this time we'll add the flag to keep the GPU temperature at or below 85°C. This is a generally safe temperature for most GPUs under load.
hashcat -m 0 -a 0 ~/project/hash.txt ~/project/wordlist.txt -d 2 --gpu-temp-retain=85
Because our cracking task is very short, you won't see the temperature management in action. However, the command will be accepted, and Hashcat will enable the feature. On a multi-hour or multi-day cracking job, this flag would be actively working in the background, potentially reducing the speed slightly in exchange for thermal safety.
The output will be the same as in the previous step, as the password is found almost instantly. The key takeaway is knowing how to apply this protective setting.
Session..........: hashcat
Status...........: Cracked
...
5d41402abc4b2a76b9719d911017c592:password
...
Experiment with --opencl-vector-width to Find Optimal Setting
In this step, you will explore a performance-tuning option. The --opencl-vector-width flag controls how many "threads" or work items are bundled together for processing in a single instruction. This is also known as SIMD (Single Instruction, Multiple Data) width.
The optimal value for this setting is highly dependent on the specific GPU architecture and the type of hash being cracked. The only way to find the best setting is to experiment. Allowed values are typically powers of two, such as 1, 2, 4, 8, or 16.
To test the effect of this flag, we can use Hashcat's built-in benchmark mode (-b). Let's run a benchmark for MD5 (-m 0) and set the vector width to 4.
hashcat -m 0 -b --opencl-vector-width 4
Hashcat will run a benchmark and display the speed for each device. Pay attention to the Speed line for your GPU.
...
Hashtype: MD5
Speed.#2.........: 480.3 MH/s (94.38ms) @ Accel:256 Loops:1024 Thr:256 Vec:4
...
Now, try running the benchmark again with a different vector width, for example, 8:
hashcat -m 0 -b --opencl-vector-width 8
Compare the Speed from this run to the previous one. By testing different values, you can determine the optimal vector width for your specific hardware and hash combination, allowing you to maximize your cracking performance. For this lab, simply experimenting with the command is sufficient.
Monitor GPU Temperature and Fan Speed During an Attack
In this final step, you will learn how to monitor your GPU's vital signs in real-time while Hashcat is running. This is essential for diagnosing performance issues and ensuring your thermal settings are working as expected.
We will use the nvidia-smi (NVIDIA System Management Interface) utility, a powerful command-line tool for managing and monitoring NVIDIA GPUs. To see the stats update live, we'll run it with the watch command.
First, you need to open a second terminal window. You can do this by clicking the "+" icon in the terminal tab bar at the bottom of the screen.
In your new (second) terminal, run the following command. It will execute nvidia-smi every second and refresh the screen with the latest data.
watch -n 1 nvidia-smi
You will see a dashboard showing the GPU's name, temperature, fan speed, power usage, and memory utilization.
Now, go back to your original (first) terminal. Start a heavy benchmark to put the GPU under a significant load. We'll use the -w 4 (workload profile 4, for "Insane") flag to maximize the load.
hashcat -m 0 -b -w 4
Switch your view back to the second terminal running watch. You should see the Temp, Pwr, and GPU-Util values increase significantly as the GPU works hard on the benchmark. This gives you a live view of your hardware's status.
Once you are done observing, press Ctrl+C in the first terminal to stop the Hashcat benchmark, and then press Ctrl+C in the second terminal to stop the watch command.
Summary
In this lab, you gained hands-on experience with several key Hashcat flags for managing and tuning GPU performance.
You learned how to:
- List all available OpenCL-compatible devices using
--opencl-devices. - Target a specific GPU for a task with the
-dflag. - Protect your hardware from overheating by setting a thermal limit with
--gpu-temp-retain. - Experiment with the
--opencl-vector-widthflag in benchmark mode to find optimal performance settings. - Monitor your GPU's real-time statistics using
nvidia-smiandwatchduring a heavy workload.
Mastering these commands allows you to move from a basic user to an advanced practitioner, capable of maximizing cracking speed while ensuring the safety and stability of your hardware.


