diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..62beeeb --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tests/__pycache__/ +__pycache__/ diff --git a/VeraBuster.py b/VeraBuster.py index 76f7a35..1f0a237 100644 --- a/VeraBuster.py +++ b/VeraBuster.py @@ -18,16 +18,28 @@ def check_root(): # Function to crack VeraCrypt on Linux def linuxCrack(p, veracryptPath, volume, total, total_passwords, debug=False): - cmd = f'veracrypt -t "{volume}" -p {p} --non-interactive' # Command to execute VeraCrypt + cmd = f'veracrypt -t "{volume}" -p "{p}" --non-interactive' # Command to execute VeraCrypt if debug: print(f"Executing command: {cmd}") # Print the executed command if in debug mode process = subprocess.Popen( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = process.communicate() procreturn = str(out, "utf-8").strip() if out else str(err, "utf-8").strip() # Convert the output to a string + + # Workaround for Error: device-mapper: reload ioctl (https://github.com/veracrypt/VeraCrypt/issues/839) + if "device-mapper: reload ioctl" in procreturn or "device-mapper: create ioctl" in procreturn: + retry_cmd = f'veracrypt {volume} -p "{p}" -m=nokernelcrypto' # Retry command with -m=nokernelcrypto flag + process = subprocess.Popen( + retry_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = process.communicate() + procreturn = str(out, "utf-8").strip() if out else str(err, "utf-8").strip() + + if debug: + print(f"Raw output: {out}") + print(f"Raw error: {err}") printProgressBar(total, total_passwords) total += 1 - return procreturn.find("Error: Operation failed due to one or more of the following:") == -1 # Check if there was an error + return "Error" not in procreturn # Check if there was an error # Function to print the progress bar def printProgressBar(iteration, total, prefix='Progress', suffix='Complete', decimals=1, length=50, fill='█', printEnd="\r"): @@ -74,7 +86,7 @@ def printProgressBar(iteration, total, prefix='Progress', suffix='Complete', dec print(f"\nTrying password: {p}") # Print the currently tested password if linuxCrack(p, "veracrypt", args.v, total, total_passwords, args.d): if password_found or args.d: - print(f"Password found: {p}") + print(f"Password found: {p}\n") password_found = True break total += 1 diff --git a/tests/test_VeraBuster.py b/tests/test_VeraBuster.py new file mode 100644 index 0000000..e471678 --- /dev/null +++ b/tests/test_VeraBuster.py @@ -0,0 +1,29 @@ +import sys +import os + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +import pytest + +from VeraBuster import linuxCrack, printProgressBar, check_root + +def test_linuxCrack_success(): + result = linuxCrack("password", "veracrypt", "./tests/test_volume", 1, 1, debug=True) + assert result == True + +def test_linuxCrack_failure(): + result = linuxCrack("not_a_password", "veracrypt", "./tests/test_volume", 1, 1, debug=True) + assert result == False + +def test_printProgressBar(): + printProgressBar(1, 10) + +def test_check_root_with_root_privileges(): + with pytest.raises(SystemExit) as pytest_wrapped_e: + check_root() + assert pytest_wrapped_e.type == SystemExit + +def test_check_root_without_root_privileges(): + with pytest.raises(SystemExit) as pytest_wrapped_e: + check_root() + assert pytest_wrapped_e.type == SystemExit \ No newline at end of file diff --git a/tests/test_volume b/tests/test_volume new file mode 100644 index 0000000..0eb86c6 Binary files /dev/null and b/tests/test_volume differ