Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge initial tests #3

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tests/__pycache__/
__pycache__/
18 changes: 15 additions & 3 deletions VeraBuster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions tests/test_VeraBuster.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added tests/test_volume
Binary file not shown.
Loading