iT邦幫忙

2021 iThome 鐵人賽

DAY 22
2
Security

Kali Linux 工具筆記系列 第 22

Day 22 Password Attacks - 密碼攻擊(hashcat)

前言

昨天體驗過搭配密碼字典的工具來暴力破解,直覺能想到簡易的破解的方法,就是針對密碼字典裡面的密碼,一個個經過各種雜湊法來跟目標字串比對,比對到了就同時找到了密碼以及它使用的雜湊方法,所以說如果沒有密碼字典去猜測的話,也可以透過列舉的方式來做比對,例如以8位純數字密碼,只要能列舉00000000999999999每個組合的雜湊值,總有命中的時候,這種預先計算各種組合雜湊值的表就是彩虹表

考慮到密碼的組合可以配上大小寫英文讓組合更加複雜,加上雜湊方法有很多,更別提有加鹽機制的雜湊方法了,這樣的排列組合非常非常之多,要想能列舉並破解在古早時候受限於計算能力會需要非常久的時間,而這種列舉的手法放到區塊鏈熱門的今日來說,透過GPU來大量生成雜湊來取得彩虹表也不是不可能的事了。

工具介紹

今天要介紹的工具是hashcat,就是能用到GPU來快速產生並比對雜湊值,且它用的是OpenCL,所以支援的顯卡相對較多,且它支援的雜湊方法也非常多,透過hashcat -h可以看到支援的雜湊法或是模式,介紹很長,所以這邊只列出基本用法

- [ Basic Examples ] -

  Attack-          | Hash- |
  Mode             | Type  | Example command
 ==================+=======+==================================================================
  Wordlist         | $P$   | hashcat -a 0 -m 400 example400.hash example.dict
  Wordlist + Rules | MD5   | hashcat -a 0 -m 0 example0.hash example.dict -r rules/best64.rule
  Brute-Force      | MD5   | hashcat -a 3 -m 0 example0.hash ?a?a?a?a?a?a
  Combinator       | MD5   | hashcat -a 1 -m 0 example0.hash example.dict example.dict

其中-m是指定雜湊方法的類型,後方帶的數字代表的類型都可以在hashcat -h看到

- [ Hash modes ] -
    # | Name                                             | Category ======+==================================================+================
  900 | MD4                                              | Raw Hash
    0 | MD5                                              | Raw Hash
  400 | phpass                                           | Generic KDF

-a代表的是破解模式

- [ Attack Modes ] -
  # | Mode
 ===+======
  0 | Straight             #直接字典破解
  1 | Combination          #組合破解
  3 | Brute-force          #暴力破解

接著先產出一個簡單的md5來破解看看

echo -n 'abcdef' | md5sum | cut -d " " -f 1 > /tmp/hash

這邊單純體驗,所以很明確告訴hashcat要使用md5,然後使用暴力破解格式為6個英文小寫

hashcat -m 0 -a 3 /tmp/hash ?l?l?l?l?l?l   

結果如下,因為縮小了很多範圍,所以7秒就找到了密碼

hashcat (v6.1.1) starting...

OpenCL API (OpenCL 1.2 pocl 1.6, None+Asserts, LLVM 9.0.1, RELOC, SLEEF, DISTRO, POCL_DEBUG) - Platform #1 [The pocl project]
=============================================================================================================================
* Device #1: pthread-Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz, 1423/1487 MB (512 MB allocatable), 2MCU

Minimum password length supported by kernel: 0
Maximum password length supported by kernel: 256

Hashes: 1 digests; 1 unique digests, 1 unique salts
Bitmaps: 16 bits, 65536 entries, 0x0000ffff mask, 262144 bytes, 5/13 rotates

Applicable optimizers applied:
* Zero-Byte
* Early-Skip
* Not-Salted
* Not-Iterated
* Single-Hash
* Single-Salt
* Brute-Force
* Raw-Hash

ATTENTION! Pure (unoptimized) backend kernels selected.
Using pure kernels enables cracking longer passwords but for the price of drastically reduced performance.
If you want to switch to optimized backend kernels, append -O to your commandline.
See the above message to find out about the exact limits.

Watchdog: Hardware monitoring interface not found on your system.
Watchdog: Temperature abort trigger disabled.

Host memory required for this attack: 64 MB

e80b5017098950fc58aad83c8c14978e:abcdef          
                                                 
Session..........: hashcat
Status...........: Cracked
Hash.Name........: MD5
Hash.Target......: e80b5017098950fc58aad83c8c14978e
Time.Started.....: Thu Oct  7 11:06:30 2021 (3 secs)
Time.Estimated...: Thu Oct  7 11:06:33 2021 (0 secs)
Guess.Mask.......: ?l?l?l?l?l?l [6]
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........: 87634.3 kH/s (7.63ms) @ Accel:512 Loops:676 Thr:1 Vec:8
Recovered........: 1/1 (100.00%) Digests
Progress.........: 249892864/308915776 (80.89%)
Rejected.........: 0/249892864 (0.00%)
Restore.Point....: 368640/456976 (80.67%)
Restore.Sub.#1...: Salt:0 Amplifier:0-676 Iteration:0-676
Candidates.#1....: sadnqk -> xqfpef

Started: Thu Oct  7 11:06:27 2021
Stopped: Thu Oct  7 11:06:34 2021

而如果再次執行同一個破解過的hash,工具會建議你使用--show來看,因為破解的結果已經被儲存在了/home/kali/.hashcat/hashcat.potfile

hashcat -m 0 -a 3 /tmp/hash ?l?l?l?l?l?l  --show

接著稍微修改一下密碼重新產生md5來試試看

echo -n 'abzdef' | md5sum | cut -d " " -f1 > /tmp/hash2

然後再次使用hashcat

hashcat -m 0 -a 3 /tmp/hash2 ?l?l?l?l?l?l

發現還是一樣飛快

Started: Thu Oct  7 11:15:18 2021
Stopped: Thu Oct  7 11:15:26 2021

試著不給格式,同一個密碼試試看,但要記得先移除先前的結果

rm /home/kali/.hashcat/hashcat.potfile #移除檔案
hashcat -m 0 -a 3 /tmp/hash2

這次解開的時間稍微多了一些

Started: Thu Oct  7 11:15:56 2021
Stopped: Thu Oct  7 11:16:30 2021

從上面簡單的實驗可知,6碼的密碼長度真的短到完全沒有安全性可言,但即使密碼長度夠長,如果透過更多更強的GPU提供強大算力,也有可能成功破解,所以就要回頭過來檢討雜湊方法本身了,像md5sha1這樣的老牌雜湊法,已經被證明了安全性不足,所以才會有所謂加鹽機制或是延伸出的動態雜湊的方法,不知道會不會有一天破解的速度會快到追不上呢?我只知道不會有我放棄快


上一篇
Day 21 Password Attacks - 密碼攻擊(hash-identifier, john)
下一篇
Day 23 Password Attacks - 密碼攻擊 (hydra, pw-inspector)
系列文
Kali Linux 工具筆記31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言