mirror of
https://github.com/trustedsec/hate_crack.git
synced 2026-07-28 14:47:22 -07:00
feat: add random rules attack using generate-rules.bin (#87)
- Add hcatGenerateRules() in main.py: runs generate-rules.bin to
produce N random rules, writes them to a temp file, runs hashcat
with -r against a chosen wordlist, cleans up on exit
- Add generate_rules_crack() handler in attacks.py with count
prompt (default 65536), wordlist picker with tab-completion,
input validation, and abort on invalid input
- Add dispatcher generate_rules_crack() in main.py and key "20"
in both main.py and hate_crack.py get_main_menu_options()
- Add ("20", "Random Rules Attack") to get_main_menu_items()
- Add tests: test_random_rules_attack.py (menu presence, handler
wiring), test_random_rules_wrapper.py (subprocess behavior,
cleanup, count passing, count tracking)
- Add key "20" to MENU_OPTION_TEST_CASES in test_ui_menu_options.py
- Update README: add option 20 to menu listing, add attack
description, add version history entry
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import importlib.util
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def load_cli_module():
|
||||
os.environ["HATE_CRACK_SKIP_INIT"] = "1"
|
||||
for key in list(sys.modules.keys()):
|
||||
if "hate_crack" in key:
|
||||
del sys.modules[key]
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"hate_crack_cli", PROJECT_ROOT / "hate_crack.py"
|
||||
)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
return mod
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cli():
|
||||
return load_cli_module()
|
||||
|
||||
|
||||
def test_generate_rules_crack_in_main_menu(cli):
|
||||
options = cli.get_main_menu_options()
|
||||
assert "20" in options
|
||||
|
||||
|
||||
def test_generate_rules_crack_handler_calls_main(cli, tmp_path):
|
||||
ctx = MagicMock()
|
||||
ctx.hcatHashType = "1000"
|
||||
ctx.hcatHashFile = "/tmp/h.txt"
|
||||
ctx.hcatWordlists = str(tmp_path)
|
||||
ctx.list_wordlist_files.return_value = []
|
||||
wl = tmp_path / "words.txt"
|
||||
wl.write_text("password\n")
|
||||
with patch("builtins.input", side_effect=["100", str(wl)]):
|
||||
cli._attacks.generate_rules_crack(ctx)
|
||||
ctx.hcatGenerateRules.assert_called_once_with("1000", "/tmp/h.txt", 100, str(wl))
|
||||
Reference in New Issue
Block a user