-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrute-gpass.sh
executable file
·153 lines (133 loc) · 4.5 KB
/
brute-gpass.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
# Function to generate permutations based on configuration rules
generate_permutations() {
local word=$1
local lowercase=$2
local uppercase=$3
local digits=$4
local symbols=$5
if [[ -z $word ]]; then
echo "$word"
return
fi
local char="${word:0:1}"
local remaining="${word:1}"
if [[ -n $remaining ]]; then
generate_permutations "$remaining" "$lowercase" "$uppercase" "$digits" "$symbols"
fi
case $char in
[a-z])
if [[ $lowercase == "true" ]]; then
generate_permutations "$remaining" "$lowercase" "$uppercase" "$digits" "$symbols"
fi
if [[ $uppercase == "true" ]]; then
generate_permutations "$(echo "$remaining" | tr '[:lower:]' '[:upper:]')" "$lowercase" "$uppercase" "$digits" "$symbols"
fi
;;
[A-Z])
if [[ $uppercase == "true" ]]; then
generate_permutations "$remaining" "$lowercase" "$uppercase" "$digits" "$symbols"
fi
if [[ $lowercase == "true" ]]; then
generate_permutations "$(echo "$remaining" | tr '[:upper:]' '[:lower:]')" "$lowercase" "$uppercase" "$digits" "$symbols"
fi
;;
[0-9])
if [[ $digits == "true" ]]; then
generate_permutations "$remaining" "$lowercase" "$uppercase" "$digits" "$symbols"
fi
;;
[\!\@\#\$\%\*])
if [[ $symbols == "true" ]]; then
generate_permutations "$remaining" "$lowercase" "$uppercase" "$digits" "$symbols"
fi
;;
esac
}
# Read the available secret keys
keys=()
while read -r line; do
if [[ $line =~ ^sec ]]; then
key_id=$(echo "$line" | awk '{print $2}' | awk -F'/' '{print $NF}')
keys+=("$key_id")
fi
done < <(gpg --list-secret-keys --keyid-format LONG)
# Prompt the user to select a key to test
echo -e "${YELLOW}Available secret keys:${NC}"
for ((i=0; i<${#keys[@]}; i++)); do
echo "[$i] ${keys[$i]}"
done
read -p "Select a key to test (0-${#keys[@] - 1}): " key_index
# Check if the key index is valid
if ! [[ $key_index =~ ^[0-9]+$ ]] || ((key_index < 0)) || ((key_index >= ${#keys[@]})); then
echo -e "${RED}Invalid key index.${NC}"
exit 1
fi
selected_key=${keys[$key_index]}
# Extract the key ID from the selected key
key_id=$(echo "$selected_key" | awk -F'/' '{print $NF}')
# Read the passphrase seed values
seed_values=()
while true; do
read -p "Enter a passphrase seed value (leave empty to finish): " seed_value
if [[ -z $seed_value ]]; then
break
fi
seed_values+=("$seed_value")
done
# Prompt for permutation options
echo -e "\n${YELLOW}Permutation Options:${NC}"
echo -e "Enter the letters corresponding to the options you want to include:"
echo -e " ${GREEN}a${NC}: Include lowercase letters"
echo -e " ${GREEN}A${NC}: Include uppercase letters"
echo -e " ${GREEN}0${NC}: Include digits (0-9)"
echo -e " ${GREEN}!${NC}: Include symbols (!, @, $, #, %, *)"
read -p "Permutation options (default: aA0!): " -r permutation_options
# Set default values for permutation options
lowercase=true
uppercase=true
digits=true
symbols=true
# Process the provided permutation options or use the defaults
if [[ -n $permutation_options ]]; then
lowercase=false
uppercase=false
digits=false
symbols=false
for option in $(echo "$permutation_options" | fold -w1); do
case $option in
a)
lowercase=true
;;
A)
uppercase=true
;;
0)
digits=true
;;
\!)
symbols=true
;;
esac
done
fi
# Generate and test the passphrase permutations
for seed_value in "${seed_values[@]}"; do
while IFS= read -r permutation; do
echo -e "${YELLOW}Testing passphrase:${NC} $permutation"
# Attempt to decrypt the dummy file using the permutation
if gpg --batch --yes --passphrase "$permutation" --decrypt --default-key "$key_id" dummy_file.gpg > /dev/null 2>&1; then
# Passphrase found
echo -e "${GREEN}Passphrase found:${NC} $permutation"
exit 0
fi
done < <(generate_permutations "$seed_value" "$lowercase" "$uppercase" "$digits" "$symbols")
done
# No valid passphrase found
echo -e "${RED}No valid passphrase found.${NC}"
exit 1