Hackers are constantly searching for new ways to exploit systems and filter passwords, also in hash form. Demanding brute-force attacks powered by high-end GPUs can execute millions of password attempts per second. However, Ubuntu and Debian users are not completely helpless. There are ways to protect the hashed password to better ward off Hashcat attacks.
Why would an attacker steal my sudo password?
Root permissions are usually required to access the / etc / shadow file in Ubuntu and Debian systems that use hash files. Passwords are stored. An attacker extracting this data indicates that he already has root privileges. Access to the root level can be obtained without knowledge of the destination's password up to physically exploiting the operating system or device.
For example, Linux kernel vulnerabilities are exposed several times a year without needing to know the password of the target root shell. Likewise, the single user mode feature is often misused to embed nefarious cronjobs. It can be configured with just a few minutes of physical access to the target device and does not require a password.
If an attacker obtained root access in other ways, why do you still need the sudo password? Well, there can be many reasons for that. The attacker may try to do one of the following:
- Switch to other devices or services on the network and learn the password scheme used (for example, Hunter321
- Encrypt encrypted Firefox browser passwords stored in Chrome. These encrypted passwords are sometimes protected by the user's login password.
- See if the password can be reused for popular social media and banking sites.
- Physically access the device to log in hash, they may try to crack themselves to log in if the target device is not being monitored.
There is no telling how far an attacker can pan with a single password that has been reused in accounts, websites, and network services.  How Debian and Ubuntu Safely Keep Passwords
The / etc / shadow file stores information about the password of the destination, salt, the hash algorithm, the expiration date of the password, and so on. You can grep the following command Run with the variable $ USER and the terminal will automatically search for the username of the target in the / etc / shadow file.
sudo grep $ USER /etc/shadow
The sections are separated by colons ( : ) As shown below. We will focus on section 2. The other sections are not relevant to the defense against Hashcat attacks (brute-force attacks), so I will skip them for the time being.
tokyoneon: $ 6 $ oHP9lHDM $ DyxrXl6U / t3A91eA4FWpc4n / Tn3tI.Cb1YRZT / p76kdcyTUiWTNMBDp1YrCFpJJtBRxfh71aGOZZHcXfY9qeN0: 17762: 0: 99999: 7 :: ---- 1 ----- | ----------------------------------- -------------- 2 ------------------------------- ----------- | --- 3 --- | -4- | --- 5 --- | -6- | -7- | -8- |
Section 2 is .t. TTT TT <T <T <D65 <T <T <D65 <T <D <D <D </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y < / Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ Y </ U3 B> </ <-Yes.
| 1 | —- 2 — | ————————————– -3 ———- ———————————— |  These sections consist of the hash type ( 1 ), salt ( 2 ) and the hash password ( 3 ). The hash type 6 stands for SHA-512, but the type 5 (SHA-256) is also common. Salts are random values used to create strong, unique hashes. By today's standards, this hash password is stored relatively securely. However, it can still be the subject of a targeted brute force attack.
EVGA GeForce RTX 2080 Best of Password Cracking (GPU) from 2018 (Best of Password Cracking): Buy from Amazon | Best Buy | Walmart
Step 1: Test the Hash against Hashcat
Out of curiosity, I wanted to find out how many passwords a second Hashcat can run against the hash created in Ubuntu 18. This was tested with a generic Nvidia GeForce GTX 1060 GPU. The GPU is not high-end, but is standard in many consumer desktops these days. It would not be unreasonable to believe that most hackers with dedicated password-cracking machines can perform more calculations per second with a superior GPU.
hashcat -a 3 -m 1800 /tmp/password_hash.txt? l? l? l? l
hashcat (v5.1.0) is started ... OpenCL Platform # 1: NVIDIA Corporation ======================================= * Device # 1: GeForce GTX 1060 3GB, 754/3018 MB assignable, 9MCU Session ..........: hashcat Status ...........: Running Hash.Type ........: sha512crypt $ 6 $, SHA512 (Unix) Hash.Target ......: $ 6 $ oHP9lHDM $ DyxrXl6U / t3A91eA4FWpc4n / Tn3tI.Cb1YRZT / p ... Y9qeN0 Time.Started .....: Tue Mar 5 02:25:23 2019 (15 seconds) Time.Estimated ...: Tue Mar 5 03:36:19 2019 (1 hour, 10 minutes) Guess.Mask .......:? L? L? L? L? L? L  Guess.Queue ......: 1/1 (100.00%) Speed # 1 .........: 72631 H / s (403.13 ms) @ Acceleration: 1024 Loops: 512 Thr: 32 Vec: 1 Recovered ........: 0/1 (0.00%) digests, 0/1 (0.00%) salts Progress .........: 884736/308915776 (0.29%) Rejected .........: 0/884736 (0,00%) Restore.Point ....: 0/11881376 (0,00%) Restore.Sub. # 1 ...: salt: 0 amps: 3-4 iteration: 3072-3584 Candidates. # 1 ....: barier -> bjuhgi Hardware.Mon. # 1 ..: Temp: 62c Fan: 35% Operating Voltage: 100% Core: 1847 MHz Mem: 3802 MHz Bus: 16 [s] tatus [p] ause [b] ypass [c] Tail point [q] uit =>
The above command Hashcat performs a mask attack ( -a 3 ) using the SHA-512 Unix hash type ( -m 1800 ) with any possible combination of six letters (? L ). As we can see, 72.631 hashes per second (H / s) can be done. At this speed, it would only take an hour to try all six lowercase letters. As we have already learned, passwords with six characters are very common. With 72,600 H / s crisp eight- and nine-digit password hashes with a generic Nvidia GPU are quite in the realm of reality.
Step 2: Harden the password hash
Of course with a long and complex password that would prevent most brute force attacks. But let us take a different approach by increasing the hashish "SHA rounds". SHA rounds (better known as iterations) are used as the "slowdown factor", which essentially results in CPUs and GPUs taking much longer to compute a single password attempt. The higher this value is, the longer Hashcat has to work to crack the hash.
By default, Ubuntu and Debian use the SHA-512 crypt method with 5,000 SHA rounds. As we see in the Hashcat edition above, 5,000 SHA rounds correspond to nearly 73,000 password attempts per second. Which is not good news for Ubuntu and Debian users. Fortunately, the number of SHA rounds can be manually increased to better protect brute force attacks. This can be done with the command chpasswd .
Chpasswd is a password management utility, like passwd . It is designed to change many passwords in bulk while specifying the hash type and the number of SHA rounds (among others). Use the following command to secure a password hash with chpasswd.
Warning (Read Before Continue):
If your CPU is older than an Intel i3, you should not use more than 750,000 SHA rounds. Intel i7 users should not exceed 30,000,000 SHA rounds. A significant increase in this value may require a lot of CPU processing and may take minutes (possibly hours). If you pause the command before it completes, the system may become unstable. Use the following command with care, as setting too high may make it difficult to log in or out of the system. Gradually increase the number of SHA rounds if you want to test the limitations of your CPU.
sudo chpasswd -s 10000000 -c SHA512 <<< username: password; history -c
The above chpasswd command uses 10,000,000 SHA rounds ( -s ) using the SHA-512 encryption method ( -c ). The characters <<< indicate a string that will be used as input data. In this case, the input is the username and the desired password. To prevent the new password from being displayed in the terminal history, add the command to delete it ( -c ). grep the / etc / shadow file again to find a new section between the hash and salt that reads laps = 10000000 . This is a character of the chpasswd command succeeded
sudo grep $ user / etc / shadow
tokyoneon :. $ 6 $ round = $ 10000000 h6JNZ / CRSFfBbu $ 4ZcBt2md4dd3GsrL7jUv / 269dMPP4k9PEQVbMOnThbRC3kFnOKIjHHDK3qg / kh1BNcPNU9EJtfggqPn4 / 8nSN0: 17960: 0: 99999: 7 :::
Leave Feed this new hash into Hashcat with 10,000,000 SHA rounds and watch the number of password attempts it can make.
hashcat -a 3 -m 1800 /tmp/hardened_password_hash.txt? l? l? l? l? l? l
hashcat (v5.1.0) is started ... OpenCL Platform # 1: NVIDIA Corporation ======================================= * Device # 1: GeForce GTX 1060 3GB, 754/3018 MB assignable, 9MCU [s] tatus [p] ause [b] ypass [c] Tail point [q] uit => s Session ..........: hashcat Status ...........: Running Hash.Type ........: sha512crypt $ 6 $, SHA512 (Unix) Hash.Target ......: $ 6 $ rounds = $ 10000000 cHi6OvAYRy $ x8Z0kLn.JYAPOWQkH3RMy ... 2i3G30 Time.Started .....: Tue Mar 5 03:16:28 2019 (7 seconds) Time.Estimated ...: Tue Jul 30 05:46:22 2019 (147 days, 1 hour) Guess.Mask .......:? L? L? L? L? L? L  Guess.Queue ......: 1/1 (100.00%) Speed # 1 .........: 24 H / s (410.36 ms) @ Acceleration: 1024 Loops: 512 Thr: 32 Vec: 1 Recovered ........: 0/1 (0.00%) digests, 0/1 (0.00%) salts Progress .........: 0/308915776 (0,00%) Rejected .........: 0/0 (0.00%) Restore.Point ....: 0/11881376 (0,00%) Restore.Sub. # 1 ...: Salt: 0 amp: 0-1 iteration: 8704-9216 Candidates. # 1 ....: sarian -> sjuhgi Hardware.Mon. # 1 ..: Temp: 56c Fan: 29% Operating Voltage: 100% Core: 1873MHz Mem: 3802MHz Bus: 16 [s] tatus [p] ause [b] ypass [c] heckpoint [q] uit =>
This hardened hash can only be countered with 24 hashes per second, which can make weak passwords like "zxcvbn" elastic against Hashcat, weeks of time to crack the hash.
This is not a recommendation or an argument for using weak passwords with 10,000,000 SHA rounds. Readers should increase the number of SHA rounds and use strong passwords. I use an absurdly high value in this article to show how far this type of hardening can go. All SHA Round Values above 5,000 will help defend brute force attacks. Even if it is only a little.
SHA rounds in excess of 1,000,000 will most likely result in a completely inadequate attack vector. Higher values make it very difficult for an attacker in the system to learn the password. Increasing SHA rounds reduces the number of passwords per second that Hashcat can perform.
The main drawback to increasing SHA rounds is the CPU processing required to execute a single sudo command or log in to the account. For higher SHA rounds (eg 10,000,000), calculating a sudo command on a modern Intel i7 CPU can take up to 10 seconds. Older CPUs could take much longer. The trick is to find a sweet spot where calculating the SHA rounds takes only about two seconds. In this way, brute-force attackers are still thwarted, but it does not take forever to execute a sudo command.
If you liked this article, follow me on Twitter @tokyoneon_ and GitHub to stay with my current projects. For questions and concerns leave a comment or send me a tweet.