Skip to content

Instantly share code, notes, and snippets.

@pulimento
Created August 7, 2024 11:40
Show Gist options
  • Select an option

  • Save pulimento/797132d87f7ecd415af716485f4170ac to your computer and use it in GitHub Desktop.

Select an option

Save pulimento/797132d87f7ecd415af716485f4170ac to your computer and use it in GitHub Desktop.
7 zip password recovery tool: Test against a list of passwords
#!/bin/zsh
# Check if 7z is installed
if ! command -v 7z &> /dev/null; then
echo "Error: 7z is not installed. Please install p7zip-full package."
exit 1
fi
# Check if correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <7z_file> <password_list>"
exit 1
fi
# Assign arguments to variables
zip_file="$1"
password_list="$2"
# Check if files exist
if [ ! -f "$zip_file" ]; then
echo "Error: 7z file '$zip_file' not found."
exit 1
fi
if [ ! -f "$password_list" ]; then
echo "Error: Password list file '$password_list' not found."
exit 1
fi
# Function to test password
test_password() {
7z t -p"$1" "$zip_file" > /dev/null 2>&1
return $?
}
# Main loop to test passwords
while IFS= read -r password; do
echo "Testing password: $password"
if test_password "$password"; then
echo "Password found: $password"
exit 0
fi
done < "$password_list"
echo "Password not found in the list."
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment