-
Notifications
You must be signed in to change notification settings - Fork 1
/
distraction-destroyer.sh
executable file
·253 lines (231 loc) · 6.8 KB
/
distraction-destroyer.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/bin/bash
# ohm
ascii_banner() {
printf "$@"
}
# format variables
redc='\e[0;31m'
greenc='\e[1;32m'
bluec='\e[1;34m'
normal='\e[0m'
bold=$(tput bold)
underline=$(tput smul)
normaltput=$(tput sgr0)
error() {
printf "$redc$@$normal\n"
}
# sudo check
if [ "$EUID" -ne 0 ]; then
error "You must run Distraction Destroyer as root. Quitting..."
exit
fi
# just for fun
ascii_banner "${bluec} ....
,od88888bo.
,d88888888888b
,dP\"\"' \`\"Y888b ,.
d' \`\"Y88b .d8b. ,
' \`Y88[ , \`Y8P' db
${redc}Distraction${bluec} \`88b Ybo,\`',d88)
${redc}Destroyer${bluec} ]88[ \`Y888888P\"
${redc}v1${bluec} ,888) \`Y8888P'
,d888[ \`\"\"'
.od8888P ...
..od88888888bo, .d888b
\`\"\"Y888888bo. .d888888b
. \`Y88b\"Y88888P\"' \`Y8b
:. \`Y88[ \`\"\"\"' \`88[
|b |88b Y8b.
\`8[ :888[ , :88)
Yb :888) \`b. d8P'
\`8b. ,d888[ \`Ybo. .d88[
Y8b. .dWARP' \`Y8888888P
\`Y88bo. .od8888P' \"YWARP'
\`\"Y8888888888P\"' \`\"'
\`\"Y8888P\"\"' ${normal}ASCII: warp.tmt.1997${bluec}
\`\"\"' ${normal}https://github.com/matthew-webber/distraction-destroyer
"
# set sed/flush/hosts syntax (Linux v macOS)
hostsfile='/etc/hosts'
case $OSTYPE in
"linux"*)
case "$(uname -a)" in
*[Mm]"icrosoft"*)
hostsfile="/mnt/c/Windows/System32/drivers${hostsfile}"
flush_command='cmd.exe /c ipconfig /flushdns>nul' # silent DNS flush
;;
*)
flush_command='systemd-resolve --flush-caches'
;;
esac
sed_syntax='sed -i'
;;
"darwin"*)
sed_syntax='sed -i ""'
flush_command='dscacheutil -flushcache'
;;
esac
# prompt variables
countdown=7
countdown_message="🐲 Destruction shall commence in"
choices='['"$bold"''"$underline"'e'"$normal"'dit/'"$bold"''"$underline"'r'"$normal"'esurrect/'"$bold"''"$underline"'q'"$normal"'uit]'
# response variables
declare -a tryagain=("Pardon?" "I don't understand..." "What?" "Umm..." "I don't have all day...")
declare -a nochanges=("I found nothing but the ghosts of your enemies" "You woke me up for this?" "Apparently they all died of fright")
declare -a changesmade=("Destruction completed" "Those distractions won't be bothering you anymore..." "The enemies of focus have been dispatched" "That was too easy..." "Are you not entertained?!")
declare -a resurrect=("Well you can kiss your focus goodbye!" "Grr...<insert dissuasive cliché here>" "As you wish... weakling...")
# other important variables
this_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" # for accurate rel. paths
targetsfile="$this_dir"/targets.txt
targets=($(cat "$targetsfile")) # get the target domains from the domains file and put into array
flush=false # do not change! flag for script logic on flushing DNS
# for randomizing Destroyer speech
random() {
local arr=("${!1}")
echo -e "${arr[$RANDOM % ${#arr[@]}]}"
}
# remove targets from the hosts file
unblock_targets() {
local arr=("${!1}")
for target in "${arr[@]}"; do
$sed_syntax "/$target/d" $hostsfile
done
printf "\n🌱 All distractions resurrected 🌱\n"
}
# fn for prompt variables
opening_prompt() {
# timed prompt before script begins
exitnow=false
local prompt=$1
local choices=$2
local countdown=$3
local x=""
# countdown starts
for ((i = $countdown; i >= 0; i--)); do
# warning message
case "$i" in
[4-6]*) printf "\e[K\r${prompt} ${i} or ${choices}${x}\e[K" ;;
[3]*)
x="\n🐉 Let the slaying.."
printf "\e[K\r${prompt} ${i} or ${choices}${x}"
;;
[2]*)
x+=.
printf "\e[K\e[A\e[K\r${prompt} ${i} or ${choices}${x}"
;;
[1]*)
x+=.
printf "\e[K\e[A\e[K\r${prompt} ${i} or ${choices}${x}"
;;
[0]*)
x+=" begin!"
printf "\e[K\e[A\e[K\r${prompt} ${i} or ${choices}${x}"
;;
esac
read -s -n 1 -t 1 waitresponse
if [ $? -eq 0 ]; then
case "$waitresponse" in
[Qq]*) # quit
input="q"
exitnow=true
;;
[Ee]*) # edit
input="e"
exitnow=true
;;
[Rr]*) # resurrect
input="r"
exitnow=true
;;
"") # continue
input=""
exitnow=true
;;
*) : ;;
esac
fi
if [ $exitnow = true ]; then
case "$i" in
[4-6]*) cursorDirectives="\e[K\r" ;;
*)
cursorDirectives="\e[K\e[A\e[K\r"
;;
esac
case "$input" in
"")
x="\n🐉 Let the slaying... begin!"
;;
*) x="\n🐉 Let the slaying... oops nm!" ;;
esac
printf "${cursorDirectives}${prompt} 0 or ${choices}${x}" # display clean final countdown msg
break
fi
done
}
# startup prompt
printf "\n\n🐲 Know thy enemies and I shall destroy them\n"
echo -e "\n${underline}Targets${normaltput}"
for target in "${targets[@]}"; do
printf "🎯 $target\n" # list targets
done
printf "\n" # formatting bc i r noob
opening_prompt "$countdown_message" "$choices" $countdown
case "$input" in
"") echo -e "\n" ;; # formatting bc i r noob
[Ee]*)
# user wanna edit
echo -e "\n🐲 We'll start again when my objectives are clear..."
sleep 2
nano $targetsfile # edit the targets
echo -e "\n🐲 Let's try that again, shall we?"
sleep 2
printf "\e[1J"
$0 # start the script over again
exit
;;
[Rr]*)
# distractions come alive
quip="$(random "resurrect[@]")"
printf '\n🐲 '"$quip"
sleep 2
unblock_targets targets[@]
sleep 1
exit
;;
[Qq]*)
# bump this
echo -e '\n🐲 Farewell...'
sleep 1
exit
;;
esac
# add comment separator if not already in hosts
cat $hostsfile | grep -q "# distraction-destroyer graveyard"
case $? in
0*) : ;;
1*) echo "# distraction-destroyer graveyard (do not remove)" >>$hostsfile ;;
esac
# add domains to hosts file
for target in "${targets[@]}"; do
if grep -q $target $hostsfile; then
printf "💀 $target already destroyed\n"
else
$sed_syntax "/# distraction-destroyer graveyard/{G;s/$/127.0.0.1 $target/;}" $hostsfile
$sed_syntax "/# distraction-destroyer graveyard/{G;s/$/127.0.0.1 www.$target/;}" $hostsfile
printf "💥 $target destroyed!\n"
flush=true
fi
done
# flush DNS so stored IPs of distractions get gone
if [ "$flush" = true ]; then
printf "\n🚽 Flushing DNS cache\n"
$flush_command 2>/dev/null
quip="$(random "changesmade[@]")"
printf '\n🐉 '"$quip"
else
quip="$(random "nochanges[@]")"
printf '\n🐉 '"$quip"
fi
# well wishes for your productivity
printf "\n🐲 Stay focused, hero...\n"
sleep 1