# hashcat soruce code [hashcat build](https://hackmd.io/@hlajungo/H16GoX6pA) ## src [include](https://github.com/hashcat/hashcat/tree/master/include) [include/types.h](https://github.com/hashcat/hashcat/blob/master/include/types.h) [src](https://github.com/hashcat/hashcat/tree/master/src) [src/hashcat.c](https://github.com/hashcat/hashcat/blob/master/src/hashcat.c) [src/backend.c](https://github.com/hashcat/hashcat/blob/master/src/backend.c) [OpenCL](https://github.com/hashcat/hashcat/tree/master/OpenCL) ## command tree -d -L 3 >dir only, depth 3 ## chatgpt dir ``` 需要深入分析的目錄: src/ 說明:存放核心源代碼的目錄。這裡是Hashcat的主要運行邏輯所在,包含如hashcat.c、backend.c、types.h等重要文件。 學習任務:分析所有核心功能的源代碼文件,特別是破解流程、內存管理、參數解析等代碼。 modules/ 說明:Hashcat支持的不同Hash算法的實現都在這裡。每個算法有自己的模塊文件,這裡的代碼負責處理特定Hash類型。 學習任務:分析不同Hash算法的實現,理解如何為Hashcat新增一個自定義Hash算法。 OpenCL/ 說明:包含OpenCL的kernel代碼,這些代碼負責在GPU上執行特定的哈希算法運算。 學習任務:深入閱讀OpenCL的kernel文件,理解GPU加速的邏輯,並分析其性能優化策略。 不需要深入分析,但可以了解的目錄: charsets/ 說明:存放不同字符集文件,用於不同破解場景中的字符集定義。 學習任務:理解這些文件如何被用作遮罩攻擊的一部分,但不需要深入代碼層面。 masks/ 說明:包含預定義的遮罩文件,用於遮罩攻擊。 學習任務:了解這些遮罩文件如何作為攻擊模式的輸入。 rules/ 說明:存放Hashcat的規則文件,用於字典攻擊時修改密碼的規則。 學習任務:大致了解規則文件的結構和使用方法,理解如何編寫自定義規則。 tunings/ 說明:包含優化文件,根據不同硬體平台進行調整。 學習任務:了解文件如何用來微調Hashcat的性能,不需要深入分析代碼。 可以跳過或簡單了解的目錄: deps/ 說明:外部依賴庫的源碼或已編譯庫文件,主要用於構建過程。 學習任務:這部分不需要深入學習,只需了解其依賴的庫是什麼。 docs/ 說明:存放Hashcat的文檔與使用說明。 學習任務:僅用作參考,這部分不涉及代碼學習。 extra/、tools/、layouts/、obj/ 說明:這些目錄可能包含額外的工具、編譯過程的中間文件等。 學習任務:除非有特定需求,可以忽略這些目錄的學習。 重點學習的目錄總結: 核心目錄:src/、modules/、OpenCL/ 輔助目錄:charsets/、masks/、rules/、tunings/ ``` ## tree ### src ``` ├── affinity.c affinity.h ├── autotune.c autotune.h ├── backend.c backend.h ├── benchmark.c benchmark.h ├── bitmap.c bitmap.h ├── bitops.c bitops.h ├── brain.c brain.h ├── combinator.c combinator.h ├── common.c common.h ├── convert.c convert.h ├── cpt.c cpt.h ├── cpu_crc32.c cpu_crc32.h ├── debugfile.c debugfile.h ├── dictstat.c dictstat.h ├── dispatch.c dispatch.h ├── dynloader.c dynloader.h ├── emu_general.c emu_general.h ├── emu_inc_bignum_operations.c emu_inc_bignum_operations.h ├── emu_inc_cipher_aes.c emu_inc_cipher_aes.h ├── emu_inc_cipher_camellia.c ├── emu_inc_cipher_des.c emu_inc_cipher_des.h ├── emu_inc_cipher_kuznyechik.c ├── emu_inc_cipher_serpent.c ├── emu_inc_cipher_twofish.c ├── emu_inc_common.c ├── emu_inc_ecc_secp256k1.c emu_inc_ecc_secp256k1.h ├── emu_inc_hash_base58.c emu_inc_hash_base58.h ├── emu_inc_hash_md4.c emu_inc_hash_md4.h ├── emu_inc_hash_md5.c emu_inc_hash_md5.h ├── emu_inc_hash_ripemd160.c ├── emu_inc_hash_sha1.c emu_inc_hash_sha1.h ├── emu_inc_hash_sha224.c ├── emu_inc_hash_sha256.c emu_inc_hash_sha256.h ├── emu_inc_hash_sha384.c ├── emu_inc_hash_sha512.c emu_inc_hash_sha512.h ├── emu_inc_hash_streebog256.c ├── emu_inc_hash_streebog512.c ├── emu_inc_hash_whirlpool.c ├── emu_inc_platform.c ├── emu_inc_rp.c emu_inc_rp.h ├── emu_inc_rp_optimized.c emu_inc_rp_optimized.h ├── emu_inc_scalar.c ├── emu_inc_simd.c ├── event.c event.h ├── ext_ADL.c ext_ADL.h ├── ext_cuda.c ext_cuda.h ├── ext_hip.c ext_hip.h ├── ext_hiprtc.c ext_hiprtc.h ├── ext_iokit.c ext_iokit.h ├── ext_lzma.c ext_lzma.h ├── ext_metal.m ext_metal.h ├── ext_nvapi.c ext_nvapi.h ├── ext_nvml.c ext_nvml.h ├── ext_nvrtc.c ext_nvrtc.h ├── ext_OpenCL.c ext_OpenCL.h ├── ext_sysfs_amdgpu.c ext_sysfs_amdgpu.h ├── ext_sysfs_cpu.c ext_sysfs_cpu.h ├── filehandling.c filehandling.h ├── folder.c folder.h ├── hashcat.c hashcat.h ├── hashes.c hashes.h ├── hlfmt.c hlfmt.h ├── hwmon.c hwmon.h ├── induct.c induct.h ├── interface.c interface.h ├── keyboard_layout.c keyboard_layout.h ├── locking.c locking.h ├── logfile.c logfile.h ├── loopback.c loopback.h ├── main.c ├── Makefile ├── memory.c memory.h ├── modules ├── monitor.c monitor.h ├── mpsp.c mpsp.h ├── outfile.c outfile.h ├── outfile_check.c outfile_check.h ├── pidfile.c pidfile.h ├── potfile.c potfile.h ├── restore.c restore.h ├── rp.c rp.h ├── rp_cpu.c rp_cpu.h ├── selftest.c selftest.h ├── shared.c shared.h ├── slow_candidates.c slow_candidates.h ├── status.c status.h ├── stdout.c stdout.h ├── straight.c straight.h ├── terminal.c terminal.h ├── thread.c thread.h ├── timer.c timer.h ├── tuningdb.c tuningdb.h ├── usage.c usage.h ├── user_options.c user_options.h └── wordlist.c wordlist.h ``` ``` ├── emu_inc_radmin3_constants.h ├── sort_r.h ├── modules.h ├── types.h ``` ## chatgpt ``` ├── affinity.c affinity.h cpu加速 ├── autotune.c autotune.h 不知道,可能是自動調整 功能:自動調整 Hashcat 的性能參數,優化 cracking 的效率。 用處:根據硬件環境自動調整 cracking 設置。 ├── backend.c backend.h 後端 ├── benchmark.c benchmark.h benchmark ├── bitmap.c bitmap.h 不知道,可能是bitmap圖片 功能:位圖相關操作,用於加速散列比較和查找操作。 用處:在 cracking 過程中進行快速查找(例如 hash 碰撞檢測)。 ├── bitops.c bitops.h 不知道 功能:位操作相關的函數(bitwise operations)。 用處:進行位操作的基本工具函數,優化低層運算。 ├── brain.c brain.h 不知道, 可能是brain功能 功能:Brain 功能,用於分布式 cracking。 用處:減少重複的計算,實現更高效的 cracking。 ├── combinator.c combinator.h 字典組合攻擊 ├── common.c common.h 不知道,可能是公用頭文件 功能:公共功能函數和通用工具。 用處:提供公用邏輯和工具函數給其他模塊使用。 ├── convert.c convert.h 不知道, 可能是轉換類型 功能:不同格式之間的轉換工具。 用處:將散列值或其他數據轉換為不同格式。 ├── cpt.c cpt.h 不知道 功能:Cracking Progress Tracking(進度追蹤)。 用處:追蹤 cracking 進度,顯示預估完成時間。 ├── cpu_crc32.c cpu_crc32.h 不知道 功能:計算 CRC32 校驗值的 CPU 實現。 用處:校驗數據完整性或驗證數據。 ├── debugfile.c debugfile.h 可能是輸出變量 ├── dictstat.c dictstat.h 可能是輸出字典 ├── dispatch.c dispatch.h 不知道 功能:調度器,負責調度不同 cracking 任務。 用處:負責 cracking 任務的分配與協調。 ├── dynloader.c dynloader.h 可能是動態載入 ├── emu_general.c emu_general.h 不知道 功能:通用模擬功能。 用處:用於模擬不同類型的 cracking 運算過程,可能涉及到CPU或GPU的模擬。 ├── emu_inc_bignum_operations.c emu_inc_bignum_operations.h 可能是大數字運算 ├── emu_inc_cipher_aes.c emu_inc_cipher_aes.h 不知道 ├── emu_inc_cipher_camellia.c 不知道 ├── emu_inc_cipher_des.c emu_inc_cipher_des.h 不知道 ├── emu_inc_cipher_kuznyechik.c 不知道 ├── emu_inc_cipher_serpent.c 不知道 ├── emu_inc_cipher_twofish.c 不知道 ├── emu_inc_common.c 可能是emu的公用頭文件 ├── emu_inc_ecc_secp256k1.c emu_inc_ecc_secp256k1.h 不知道 ├── emu_inc_hash_base58.c emu_inc_hash_base58.h 不知道 功能:不同哈希算法的模擬實現。 用處:模擬 MD4、MD5、SHA1、SHA256 等常見哈希算法。 ├── emu_inc_hash_md4.c emu_inc_hash_md4.h 不知道 ├── emu_inc_hash_md5.c emu_inc_hash_md5.h 不知道 ├── emu_inc_hash_ripemd160.c ├── emu_inc_hash_sha1.c emu_inc_hash_sha1.h ├── emu_inc_hash_sha224.c ├── emu_inc_hash_sha256.c emu_inc_hash_sha256.h ├── emu_inc_hash_sha384.c ├── emu_inc_hash_sha512.c emu_inc_hash_sha512.h ├── emu_inc_hash_streebog256.c ├── emu_inc_hash_streebog512.c ├── emu_inc_hash_whirlpool.c ├── emu_inc_platform.c ├── emu_inc_rp.c emu_inc_rp.h ├── emu_inc_rp_optimized.c emu_inc_rp_optimized.h ├── emu_inc_scalar.c ├── emu_inc_simd.c ├── event.c event.h 不知道 功能:事件系統,處理 Hashcat 中的不同事件。 用處:負責記錄和處理 cracking 過程中的事件和狀態變更。 ├── ext_ADL.c ext_ADL.h 不知道 ├── ext_cuda.c ext_cuda.h cuda有關 ├── ext_hip.c ext_hip.h 不知道 功能:HIP API 支持,用於 AMD GPU 的 cracking。 用處:AMD 的 GPU 加速 cracking 支持。 ├── ext_hiprtc.c ext_hiprtc.h 不知道 ├── ext_iokit.c ext_iokit.h io工具箱 ├── ext_lzma.c ext_lzma.h 不知道 ├── ext_metal.m ext_metal.h 不知道 ├── ext_nvapi.c ext_nvapi.h nvidia的api ├── ext_nvml.c ext_nvml.h 不知道 功能:NVIDIA Management Library 支持。 用處:用來監控和管理 NVIDIA GPU(如溫度、風扇速度、電壓等)以提高 cracking 效率。 ├── ext_nvrtc.c ext_nvrtc.h nvidia的runtime compile ├── ext_OpenCL.c ext_OpenCL.h openCL ├── ext_sysfs_amdgpu.c ext_sysfs_amdgpu.h amdgpu相關 ├── ext_sysfs_cpu.c ext_sysfs_cpu.h 不知道 ├── filehandling.c filehandling.h 文件處理 ├── folder.c folder.h 不知道 ├── hashcat.c hashcat.h 重要 ├── hashes.c hashes.h 重要 ├── hlfmt.c hlfmt.h 不知道 ├── hwmon.c hwmon.h 不知道 功能:硬件監控功能。 用處:用來監控硬件狀況,如溫度和性能指標。 ├── induct.c induct.h 不知道 功能:處理「incrementation attack」或「induction files」。 用處:逐步增加密碼長度進行破解,或者從文件中逐步讀取要測試的密碼。 ├── interface.c interface.h 接口相關 ├── keyboard_layout.c keyboard_layout.h 鍵盤輸入相關 ├── locking.c locking.h 鎖相關 ├── logfile.c logfile.h log文件相關 ├── loopback.c loopback.h 不知道 功能:處理 cracking 的迴路反饋。 用處:將 cracking 結果重新輸入 Hashcat 進行測試。 ├── main.c main文件 ├── Makefile make文件 ├── memory.c memory.h 記憶體管理相關 ├── modules 每種hash type破解的文件 ├── monitor.c monitor.h 不知道 功能:監控 cracking 過程的工具。 用處:用於實時監控 cracking 的進度和硬件資源使用狀況。 ├── mpsp.c mpsp.h 不知道 功能:可能是「multi-position string processor」的簡稱。 用處:多位置字串處理,可能與 cracking 的候選密碼生成或篩選相關。 ├── outfile.c outfile.h 文件輸出相關 ├── outfile_check.c outfile_check.h 文件輸出校驗 ├── pidfile.c pidfile.h 不知道 功能:處理進程 ID 文件。 用處:記錄 Hashcat 的進程 ID,方便進程管理和監控。 ├── potfile.c potfile.h pot功能相關 ├── restore.c restore.h restore功能相關 ├── rp.c rp.h 不知道 功能:規則引擎(rule engine)和 CPU 相關的規則處理。 用處:處理 cracking 規則(如密碼修改規則),rp_cpu 可能是專門用於 CPU 上的實現。 ├── rp_cpu.c rp_cpu.h 不知道 ├── selftest.c selftest.h 自我測試 ├── shared.c shared.h 不知道,可能是公用文件 ├── slow_candidates.c slow_candidates.h slow candidates功能 ├── status.c status.h 狀態功能 ├── stdout.c stdout.h 標準輸出流相關 ├── straight.c straight.h 字典攻擊 ├── terminal.c terminal.h 終端顯示相關 ├── thread.c thread.h 多線程 ├── timer.c timer.h 可能是計時器 ├── tuningdb.c tuningdb.h 不知道 功能:調整數據庫,用於優化 cracking 設置。 用處:根據設備和算法的性能記錄,調整 cracking 的參數設置。 ├── usage.c usage.h 使用率相關 ├── user_options.c user_options.h 用戶輸入選項 └── wordlist.c wordlist.h 辭典相關 ``` ## [Makefile Note](/NTxyFygvTRW5fMF6JGkn3A) ## main 有些宏是用-D傳入的,所以找不到宏的#define也別怕。 >這些代碼很好看。 ## hwmon是linux的子系統 [原文链接](https://blog.csdn.net/lickylin/article/details/106449262) ``` hwmon即hardware monitoring framework,硬件监视框架,包括温度传感器、风扇、电源等器件驱动的框架。hwmon子系统主要借助sysfs提供的api接口,实现对硬件监控器件的通信,也就是借助sysfs的文件创建的机制实现应用程序与hwmon器件的通信操作。 ``` ## const time_t proc_start = time(NULL); chatgpt ``` time_t:是一種用來表示時間的數據類型,通常是用來存儲從 Epoch(1970年1月1日 00:00:00 UTC)起的秒數。 time(NULL):這個函數會返回從 Epoch 開始到當前時間的秒數。如果你傳入 NULL,則 time() 函數返回的就是當前的時間值。 ``` ## 閱讀源碼的用途 1. 搞懂他的工作流 2. 知道他有哪些功能能用 ## hashcat 功能 --identify | | Shows all supported algorithms for input hashes | --identify my.hash ## hashcat 代碼 int rc_final = -1; 通常用來表示一個返回碼(return code),其含義如下: while ((hash_mode = benchmark_next(hashcat_ctx)) != -1) 運行一個函數,把返回值丟給hash_mode,然後和-1比較。