-
Notifications
You must be signed in to change notification settings - Fork 1
/
Alien.sh
421 lines (370 loc) · 14.6 KB
/
Alien.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#!/bin/bash
__version__="1.5"
## DEFAULT HOST & PORT
HOST='127.0.0.1'
PORT='8090'
## ANSI colors (FG & BG)
RED="$(printf '\033[31m')" GREEN="$(printf '\033[32m')" ORANGE="$(printf '\033[33m')" BLUE="$(printf '\033[34m')"
MAGENTA="$(printf '\033[35m')" CYAN="$(printf '\033[36m')" WHITE="$(printf '\033[37m')" BLACK="$(printf '\033[30m')"
REDBG="$(printf '\033[41m')" GREENBG="$(printf '\033[42m')" ORANGEBG="$(printf '\033[43m')" BLUEBG="$(printf '\033[44m')"
MAGENTABG="$(printf '\033[45m')" CYANBG="$(printf '\033[46m')" WHITEBG="$(printf '\033[47m')" BLACKBG="$(printf '\033[40m')"
RESETBG="$(printf '\e[0m\n')"
## Directories
BASE_DIR=$(realpath "$(dirname "$BASH_SOURCE")")
if [[ ! -d ".server" ]]; then
mkdir -p ".server"
fi
if [[ -d ".server/www" ]]; then
rm -rf ".server/www"
mkdir -p ".server/www"
else
mkdir -p ".server/www"
fi
## Remove logfile
if [[ -e ".server/.loclx" ]]; then
rm -rf ".server/.loclx"
fi
if [[ -e ".server/.cld.log" ]]; then
rm -rf ".server/.cld.log"
fi
## Script termination
exit_on_signal_SIGINT() {
{ printf "\n\n%s\n\n" "${RED}[${WHITE}!${RED}]${RED} Program Interrupted." 2>&1; reset_color; }
exit 0
}
exit_on_signal_SIGTERM() {
{ printf "\n\n%s\n\n" "${RED}[${WHITE}!${RED}]${RED} Program Terminated." 2>&1; reset_color; }
exit 0
}
trap exit_on_signal_SIGINT SIGINT
trap exit_on_signal_SIGTERM SIGTERM
## Reset terminal colors
reset_color() {
tput sgr0 # reset attributes
tput op # reset color
return
}
## Kill already running process
kill_pid() {
check_PID="php ngrok cloudflared loclx"
for process in ${check_PID}; do
if [[ $(pidof ${process}) ]]; then # Check for Process
killall ${process} > /dev/null 2>&1 # Kill the Process
fi
done
}
## Banner
banner() {
cat <<- EOF
${GREEN}
${GREEN}⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⠴⠶⠒⠒⠒⠒⠒⠒⠲⠦⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀
${GREEN}⠀⠀⠀⠀⢀⣠⠖⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠲⣤⡀⠀⠀⠀⠀
${GREEN}⠀⠀⢀⡴⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀
${GREEN}⠀⢠⡞⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣄⠀
${GREEN}⢠⡟⠀⠀⠀⠀⠀⠀${RED} Version : ${ORANGE}${__version__}${GREEN}⠀⠀⠀ ⢻⡆
${GREEN}⣼⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣧
${GREEN}⣿⠀⠀⠀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⠀⠀⠀⣿
${GREEN}⢿⠀⠀⣾⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⠀⠀⠀⠀⠀⣠⣴⣿⣿⣿⣿⣿⣷⠀⠀⡿
${GREEN}⢸⡇⠀⠹⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⠏⠀⢰⡇
${GREEN}⠀⣷⠀⠀⠈⠻⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⠟⠁⠀⠀⣾⠁
${GREEN}⠀⠸⡆⠀⠀⠀⠀⠉⠛⠻⠿⠟⠋⠀⠀⠀⠀⠙⠻⠿⠟⠛⠉⠀⠀⠀⠀⢰⡏⠀
${GREEN}⠀⠀⢷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡾⠀⠀
${GREEN}⠀⠀⠘⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⣾⣿⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠃⠀⠀${RED} I'm Alien,
${GREEN}⠀⠀⠀⠹⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠏⠀⠀⠀${RED} Created By LxaNce-Hacker,
${GREEN}⠀⠀⠀⠀⠹⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠟⠀⠀⠀⠀${RED} &
${GREEN}⠀⠀⠀⠀⠀⢻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⡟⠀⠀⠀⠀⠀${RED} You Can Access Me Any Time.
${GREEN}⠀⠀⠀⠀⠀⠀⠹⣄⠀⠀⠀⠀LxaNce ⠀⠀⠀⣠⠏⠀⠀⠀⠀⠀⠀
${GREEN}⠀⠀⠀⠀⠀⠀⠀⠘⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡴⠋⠀⠀⠀⠀⠀⠀⠀
${GREEN}⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢄⡀⠀⠀⠀⠀⠀⠀⢀⣠⠎⠀⠀⠀⠀⠀⠀⠀⠀⠀
${GREEN}⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠲⠤⣤⣤⠤⠖⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
${GREEN}
EOF
}
## Dependencies
dependencies() {
echo -e "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Installing required packages..."
if [[ -d "/data/data/com.termux/files/home" ]]; then
if [[ ! $(command -v proot) ]]; then
echo -e "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Installing package : ${ORANGE}proot${CYAN}"${WHITE}
pkg install proot resolv-conf -y
fi
if [[ ! $(command -v tput) ]]; then
echo -e "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Installing package : ${ORANGE}ncurses-utils${CYAN}"${WHITE}
pkg install ncurses-utils -y
fi
fi
if [[ $(command -v php) && $(command -v curl) && $(command -v unzip) ]]; then
echo -e "\n${GREEN}[${WHITE}+${GREEN}]${GREEN} Packages already installed."
else
pkgs=(php curl unzip)
for pkg in "${pkgs[@]}"; do
type -p "$pkg" &>/dev/null || {
echo -e "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Installing package : ${ORANGE}$pkg${CYAN}"${WHITE}
if [[ $(command -v pkg) ]]; then
pkg install "$pkg" -y
elif [[ $(command -v apt) ]]; then
sudo apt install "$pkg" -y
elif [[ $(command -v apt-get) ]]; then
sudo apt-get install "$pkg" -y
elif [[ $(command -v pacman) ]]; then
sudo pacman -S "$pkg" --noconfirm
elif [[ $(command -v dnf) ]]; then
sudo dnf -y install "$pkg"
elif [[ $(command -v yum) ]]; then
sudo yum -y install "$pkg"
else
echo -e "\n${RED}[${WHITE}!${RED}]${RED} Unsupported package manager, Install packages manually."
{ reset_color; exit 1; }
fi
}
done
fi
}
# Download Binaries
download() {
url="$1"
output="$2"
file=`basename $url`
if [[ -e "$file" || -e "$output" ]]; then
rm -rf "$file" "$output"
fi
curl --silent --insecure --fail --retry-connrefused \
--retry 3 --retry-delay 2 --location --output "${file}" "${url}"
if [[ -e "$file" ]]; then
if [[ ${file#*.} == "zip" ]]; then
unzip -qq $file > /dev/null 2>&1
mv -f $output .server/$output > /dev/null 2>&1
elif [[ ${file#*.} == "tgz" ]]; then
tar -zxf $file > /dev/null 2>&1
mv -f $output .server/$output > /dev/null 2>&1
else
mv -f $file .server/$output > /dev/null 2>&1
fi
chmod +x .server/$output > /dev/null 2>&1
rm -rf "$file"
else
echo -e "\n${RED}[${WHITE}!${RED}]${RED} Error occured while downloading ${output}."
{ reset_color; exit 1; }
fi
}
## Install Cloudflared
install_cloudflared() {
if [[ -e ".server/cloudflared" ]]; then
echo -e "\n${GREEN}[${WHITE}+${GREEN}]${GREEN} Cloudflared already installed."
else
echo -e "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Installing Cloudflared..."${WHITE}
arch=`uname -m`
if [[ ("$arch" == *'arm'*) || ("$arch" == *'Android'*) ]]; then
download 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm' 'cloudflared'
elif [[ "$arch" == *'aarch64'* ]]; then
download 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64' 'cloudflared'
elif [[ "$arch" == *'x86_64'* ]]; then
download 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64' 'cloudflared'
else
download 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-386' 'cloudflared'
fi
fi
}
## Exit message
msg_exit() {
{ clear; banner; echo; }
echo -e "${GREENBG}${BLACK} Thank you for using this tool. Have a good day.${RESETBG}\n"
{ reset_color; exit 0; }
}
## About
about() {
{ clear; banner; echo; }
cat <<- EOF
${GREEN} Author ${RED}: ${ORANGE}Prince Katiyar ${RED}[ ${ORANGE}LXANCE-HACKER ${RED}]
${GREEN} Github ${RED}: ${CYAN}https://github.com/LxaNce-Hacker
${GREEN} Social ${RED}: ${CYAN}https://chat.whatsapp.com/Dorez09CKKSG9mnwHadC5n
${GREEN} Version ${RED}: ${ORANGE}${__version__}
${WHITE} ${REDBG}Warning:${RESETBG}
${CYAN} This Server is made for educational purpose only ${RED}!
${WHITE}${CYAN} Author will not be responsible for any misuse of this toolkit ${RED}!${WHITE}
${RED}[${WHITE}00${RED}]${ORANGE} Main Menu ${RED}[${WHITE}99${RED}]${ORANGE} Exit
EOF
read -p "${RED}[${WHITE}-${RED}]${GREEN} Select an option : ${BLUE}"
case $REPLY in
99)
msg_exit;;
0 | 00)
echo -ne "\n${GREEN}[${WHITE}+${GREEN}]${CYAN} Returning to main menu..."
{ sleep 1; main_menu; };;
*)
echo -ne "\n${RED}[${WHITE}!${RED}]${RED} Invalid Option, Try Again..."
{ sleep 1; about; };;
esac
}
## Choose custom port
cusport() {
echo
read -n1 -p "${RED}[${WHITE}?${RED}]${ORANGE} Do You Want A Custom Port ${GREEN}[${CYAN}Y${GREEN}/${CYAN}N${GREEN}]: ${ORANGE}" P_ANS
if [[ ${P_ANS} =~ ^([yY])$ ]]; then
echo -e "\n"
read -n4 -p "${RED}[${WHITE}-${RED}]${ORANGE} Enter Your Custom 4-digit Port [1024-9999] : ${WHITE}" CU_P
if [[ ! -z ${CU_P} && "${CU_P}" =~ ^([1-9][0-9][0-9][0-9])$ && ${CU_P} -ge 1024 ]]; then
PORT=${CU_P}
echo
else
echo -ne "\n\n${RED}[${WHITE}!${RED}]${RED} Invalid 4-digit Port : $CU_P, Try Again...${WHITE}"
{ sleep 2; clear; cusport; }
fi
else
echo -ne "\n\n${RED}[${WHITE}-${RED}]${BLUE} Using Default Port $PORT...${WHITE}\n"
fi
}
## Setup website and start php server
setup_site() {
echo -e "\n${RED}[${WHITE}-${RED}]${BLUE} Setting up server..."${WHITE}
echo -ne "\n${RED}[${WHITE}-${RED}]${BLUE} Starting PHP server..."${WHITE}
cd your_site && php -S "$HOST":"$PORT" > /dev/null 2>&1 &
}
## Start Cloudflared
start_cloudflared() {
rm .cld.log > /dev/null 2>&1 &
cusport
echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} Initializing... ${GREEN}( ${CYAN}http://$HOST:$PORT ${GREEN})"
{ sleep 1; setup_site; }
echo -ne "\n\n${RED}[${WHITE}-${RED}]${GREEN} Alien Launching Your WebServer..."
if [[ `command -v termux-chroot` ]]; then
sleep 2 && termux-chroot ./.server/cloudflared tunnel -url "$HOST":"$PORT" --logfile .server/.cld.log > /dev/null 2>&1 &
else
sleep 2 && ./.server/cloudflared tunnel -url "$HOST":"$PORT" --logfile .server/.cld.log > /dev/null 2>&1 &
fi
sleep 8
cldflr_url=$(grep -o 'https://[-0-9a-z]*\.trycloudflare.com' ".server/.cld.log")
custom_url "$cldflr_url"
}
## Start localhost
start_localhost() {
cusport
echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} Initializing... ${GREEN}( ${CYAN}http://$HOST:$PORT ${GREEN})"
setup_site
{ sleep 1; clear; }
echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} Successfully Hosted at : ${GREEN}${CYAN}http://$HOST:$PORT ${GREEN}"
}
## Tunnel selection
tunnel_menu() {
{ clear; banner;}
start_cloudflared;
}
## Custom Mask URL
custom_mask() {
{ sleep .5; clear; banner; echo; }
read -n1 -p "${RED}[${WHITE}?${RED}]${ORANGE} Do you want to change Mask URL? ${GREEN}[${CYAN}Y${GREEN}/${CYAN}N${GREEN}] :${ORANGE} " mask_op
echo
if [[ ${mask_op,,} == "y" ]]; then
echo -e "\n${RED}[${WHITE}-${RED}]${GREEN} Enter your custom URL below ${CYAN}(${ORANGE}Example: https://get-free-followers.com${CYAN})\n"
read -e -p "${WHITE} ==> ${ORANGE}" -i "https://" mask_url # initial text requires Bash 4+
if [[ ${mask_url//:*} =~ ^([h][t][t][p][s]?)$ || ${mask_url::3} == "www" ]] && [[ ${mask_url#http*//} =~ ^[^,~!@%:\=\#\;\^\*\"\'\|\?+\<\>\(\{\)\}\\/]+$ ]]; then
mask=$mask_url
echo -e "\n${RED}[${WHITE}-${RED}]${CYAN} Using custom Masked Url :${GREEN} $mask"
else
echo -e "\n${RED}[${WHITE}!${RED}]${ORANGE} Invalid url type..Using the Default one.."
fi
fi
}
## URL Shortner
site_stat() { [[ ${1} != "" ]] && curl -s -o "/dev/null" -w "%{http_code}" "${1}https://github.com"; }
## Shorten for shortcode & tinyurl
shorten() {
short=$(curl --silent --insecure --fail --retry-connrefused --retry 2 --retry-delay 2 "$1$2")
if [[ "$1" == *"shrtco.de"* ]]; then
processed_url=$(echo ${short} | sed 's/\\//g' | grep -o '"short_link2":"[a-zA-Z0-9./-]*' | awk -F\" '{print $4}')
else
# processed_url=$(echo "$short" | awk -F// '{print $NF}')
processed_url=${short#http*//}
fi
}
## Shorteny for isgd
shorteny() {
short=$(curl --silent --insecure --fail --retry-connrefused --retry 2 --retry-delay 2 "$1$2")
if [[ "$1" == *"shrtco.de"* ]]; then
processed_url=$(echo ${short} | sed 's/\\//g' | grep -o '"short_link2":"[a-zA-Z0-9./-]*' | awk -F\" '{print $4}')
else
# processed_url=$(echo "$short" | awk -F// '{print $NF}')
processed_url="www."${short#http*//}
fi
}
## cleanuri for cleanuri
Cleanuri() {
short=$(curl -s -X POST -d "url=$2" "$1" | jq -r '.result_url')
processed_url=${short#http*//}
}
custom_url() {
url=${1#http*//}
cleanuri="https://cleanuri.com/api/v1/shorten"
isgd="https://www.is.gd/create.php?format=simple&url="
shortcode="https://api.shrtco.de/v2/shorten?url="
tinyurl="https://tinyurl.com/api-create.php?url="
{ custom_mask; sleep 1; clear; banner; }
if [[ ${url} =~ [-a-zA-Z0-9.]*(ngrok.io|trycloudflare.com|loclx.io) ]]; then
if [[ $(curl -i -s -X POST -d "url=https://example.com" https://cleanuri.com/api/v1/shorten | grep -i 'HTTP/' | awk '{print $2}') == 2* ]]; then
Cleanuri $cleanuri "https://$url"
elif [[ $(site_stat $isgd) == 2* ]]; then
shorteny $isgd "$url"
elif [[ $(site_stat $shortcode) == 2* ]]; then
shorten $shortcode "$url"
else
shorten $tinyurl "$url"
fi
url="https://$url"
masked_url="$mask@$processed_url"
processed_url="https://$processed_url"
else
# echo "[!] No url provided / Regex Not Matched"
url="Unable to generate links. Try after turning on hotspot"
processed_url="Unable to Short URL"
fi
echo -e "\n${RED}[${WHITE}-${RED}]${BLUE} URL 1 : ${GREEN}$url"
echo -e "\n${RED}[${WHITE}-${RED}]${BLUE} URL 2 : ${ORANGE}$processed_url"
[[ $processed_url != *"Unable"* ]] && echo -e "\n${RED}[${WHITE}-${RED}]${BLUE} URL 3 : ${ORANGE}$masked_url"
echo
if pidof cloudflared > /dev/null; then
echo -ne "\n${RED}[${WHITE}-${RED}]${ORANGE} Your server is running...${BLUE}Ctrl + C ${ORANGE}to exit.\n"
else
echo " Your server is not running, Try again with new port."
fi
# Wait for user input to exit the program gracefully
while true; do
read -r -n 1 -p "" input
if [[ $input == $'\x03' ]]; then
# Ctrl+C pressed again, exit immediately
exit_program
fi
done
}
## Server menu
server_menu() {
mask='https://lxance'
tunnel_menu;
}
## Menu
main_menu() {
{ clear; banner; echo; }
cat <<- EOF
${RED}[${WHITE}::${RED}]${ORANGE} Select An Option ${RED}[${WHITE}::${RED}]${ORANGE}
${GREEN}**********************************************************************************************************************
${RED}[${WHITE}01${RED}]${ORANGE} Start ${RED}[${WHITE}0${RED}]${ORANGE} Exit
${RED}[${WHITE}99${RED}]${ORANGE} About Me
${GREEN}**********************************************************************************************************************
EOF
read -p "${RED}[${WHITE}-${RED}]${GREEN} Select an option : ${BLUE}"
case $REPLY in
1 | 01)
server_menu;;
99)
about;;
0 | 00 )
msg_exit;;
*)
echo -ne "\n${RED}[${WHITE}!${RED}]${RED} Invalid Option, Try Again..."
{ sleep 1; main_menu; };;
esac
}
## Main
kill_pid
dependencies
install_cloudflared
main_menu