-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathinstall.sh
More file actions
317 lines (270 loc) · 13.7 KB
/
install.sh
File metadata and controls
317 lines (270 loc) · 13.7 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
#!/usr/bin/env bash
# =============================================================================
# CTFPacker – Automated Installer for Debian-based systems
# Tested on: Kali Linux, Ubuntu 22.04+, Debian 12+
# =============================================================================
set -euo pipefail
# ── Colours ──────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
log_info() { echo -e "${CYAN}[*]${NC} $*"; }
log_success() { echo -e "${GREEN}[+]${NC} $*"; }
log_warn() { echo -e "${YELLOW}[!]${NC} $*"; }
log_error() { echo -e "${RED}[-]${NC} $*" >&2; }
log_banner() { echo -e "\n${BOLD}${CYAN}$*${NC}\n"; }
# ── Root check ───────────────────────────────────────────────────────────────
if [[ $EUID -ne 0 ]]; then
log_error "This script must be run as root."
echo -e " Try: ${YELLOW}sudo bash install.sh${NC}"
exit 1
fi
# ── Debian/apt check ─────────────────────────────────────────────────────────
if ! command -v apt-get &>/dev/null; then
log_error "apt-get not found."
log_error "This installer only supports Debian-based systems (Kali Linux, Ubuntu, Debian)."
exit 1
fi
# ── Resolve the real (non-root) user that invoked sudo ───────────────────────
# pipx must be run as the actual user, not root, so binaries land in
# ~/.local/bin of the invoking user rather than /root/.local/bin.
REAL_USER="${SUDO_USER:-${USER:-$(logname 2>/dev/null || whoami)}}"
REAL_HOME="$(getent passwd "$REAL_USER" | cut -d: -f6)"
PIPX_BIN="$REAL_HOME/.local/bin"
# ── Paths ────────────────────────────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LINUX_DIR="$SCRIPT_DIR/Linux"
if [[ ! -d "$LINUX_DIR" ]]; then
log_error "Linux/ directory not found. Make sure you run this from the CTFPacker root."
exit 1
fi
# ── Banner ───────────────────────────────────────────────────────────────────
echo ""
echo -e "${RED}${BOLD}"
cat << 'EOF'
▄████▄ ▄▄▄█████▓ █████▒██▓███ ▄▄▄ ▄████▄ ██ ▄█▀▓█████ ██▀███
▒██▀ ▀█ ▓ ██▒ ▓▒▓██ ▒▓██░ ██▒▒████▄ ▒██▀ ▀█ ██▄█▒ ▓█ ▀ ▓██ ▒ ██▒
▒▓█ ▄ ▒ ▓██░ ▒░▒████ ░▓██░ ██▓▒▒██ ▀█▄ ▒▓█ ▄ ▓███▄░ ▒███ ▓██ ░▄█ ▒
▒▓▓▄ ▄██▒░ ▓██▓ ░ ░▓█▒ ░▒██▄█▓▒ ▒░██▄▄▄▄██ ▒▓▓▄ ▄██▒▓██ █▄ ▒▓█ ▄ ▒██▀▀█▄
▒ ▓███▀ ░ ▒██▒ ░ ░▒█░ ▒██▒ ░ ░ ▓█ ▓██▒▒ ▓███▀ ░▒██▒ █▄░▒████▒░██▓ ▒██▒
░ ░▒ ▒ ░ ▒ ░░ ▒ ░ ▒▓▒░ ░ ░ ▒▒ ▓▒█░░ ░▒ ▒ ░▒ ▒▒ ▓▒░░ ▒░ ░░ ▒▓ ░▒▓░
░ ▒ ░ ░ ░▒ ░ ▒ ▒▒ ░ ░ ▒ ░ ░▒ ▒░ ░ ░ ░ ░▒ ░ ▒░
░ ░ ░ ░ ░░ ░ ▒ ░ ░ ░░ ░ ░ ░░ ░
░ ░ ░ ░░ ░ ░ ░ ░ ░ ░
░ ░
EOF
echo -e "${NC}"
echo -e " ${CYAN}Automated Installer — Debian-based systems${NC}"
echo -e " ${CYAN}Author: mocha | https://mochabyte.xyz${NC}"
echo ""
# =============================================================================
# STEP 1 — APT packages
# =============================================================================
log_banner "STEP 1/3 — Installing APT dependencies"
APT_PKGS=(
clang # Clang compiler (cross-compilation)
lld # LLVM linker (used with -fuse-ld=lld)
make # GNU Make
nasm # Netwide Assembler (for SysWhispers asm)
mingw-w64 # MinGW-w64 cross-compilation toolchain
python3 # Python 3 interpreter
pipx # Isolated Python app installer
osslsigncode # PE code signing (optional, needed for -pfx)
libxcb-cursor0 # XCB cursor support required by Qt6 on some systems
)
log_info "Updating package lists..."
apt-get update -qq
log_info "Installing: ${APT_PKGS[*]}"
DEBIAN_FRONTEND=noninteractive apt-get install -y "${APT_PKGS[@]}"
log_success "APT packages installed."
# =============================================================================
# STEP 2 — pipx install
# =============================================================================
log_banner "STEP 2/3 — Installing CTFPacker via pipx"
# Ensure pipx's bin dir is on PATH for this session
export PATH="$PIPX_BIN:$PATH"
# pipx ensurepath writes to the real user's shell rc files
log_info "Running pipx ensurepath for user '$REAL_USER' ..."
sudo -u "$REAL_USER" pipx ensurepath --force
# If a previous install exists, reinstall cleanly
if sudo -u "$REAL_USER" pipx list 2>/dev/null | grep -q "ctfpacker"; then
log_warn "Existing ctfpacker pipx install found — reinstalling."
sudo -u "$REAL_USER" pipx uninstall ctfpacker
fi
log_info "Installing CTFPacker package (from $LINUX_DIR) ..."
sudo -u "$REAL_USER" pipx install "$LINUX_DIR"
log_success "CTFPacker installed via pipx."
log_info "Binaries are available at: $PIPX_BIN"
# =============================================================================
# STEP 2b — Desktop entry (.desktop file + icon)
# =============================================================================
log_banner "STEP 2b/3 — Installing desktop application entry"
ICON_DIR="$REAL_HOME/.local/share/icons"
APPS_DIR="$REAL_HOME/.local/share/applications"
DESKTOP_PATH="$APPS_DIR/ctfpacker-gui.desktop"
mkdir -p "$ICON_DIR" "$APPS_DIR"
# ── PNG icon (bundled Logo.png from assets/) ──────────────────────────────────
LOGO_SRC="$SCRIPT_DIR/assets/Logo.png"
ICON_PATH="$ICON_DIR/ctfpacker.png"
if [[ -f "$LOGO_SRC" ]]; then
cp "$LOGO_SRC" "$ICON_PATH"
chown "$REAL_USER":"$(id -gn "$REAL_USER")" "$ICON_PATH"
chmod 644 "$ICON_PATH"
log_success "Icon installed → $ICON_PATH"
else
log_warn "assets/Logo.png not found — desktop icon will be missing."
ICON_PATH="ctfpacker" # fall back to XDG theme lookup
fi
# ── .desktop file ─────────────────────────────────────────────────────────────
cat > "$DESKTOP_PATH" << DESKTOPEOF
[Desktop Entry]
Version=1.0
Type=Application
Name=CTFPacker GUI
GenericName=Shellcode Packer
Comment=AV-evading Windows shellcode loader for CTFs and pentest exams
Exec=$PIPX_BIN/ctfpacker-gui
Icon=$ICON_PATH
Terminal=false
Categories=Security;Development;
Keywords=ctf;pentest;shellcode;packer;redteam;av;evasion;
StartupWMClass=CTFPacker
StartupNotify=true
DESKTOPEOF
chown "$REAL_USER":"$(id -gn "$REAL_USER")" "$DESKTOP_PATH"
chmod 644 "$DESKTOP_PATH"
log_success "Desktop entry installed → $DESKTOP_PATH"
# Refresh the desktop database so the launcher picks it up immediately
if command -v update-desktop-database &>/dev/null; then
sudo -u "$REAL_USER" update-desktop-database "$APPS_DIR" 2>/dev/null || true
log_success "Desktop database updated."
fi
# GTK icon cache refresh (GNOME / XFCE)
if command -v gtk-update-icon-cache &>/dev/null; then
gtk-update-icon-cache -f -t "$ICON_DIR" 2>/dev/null || true
fi
# =============================================================================
# STEP 2c — Shell aliases (ctfp / ctfpg)
# =============================================================================
ALIAS_BLOCK='
# ── CTFPacker aliases ────────────────────────────────────────────────────────
alias ctfp="ctfpacker"
alias ctfpg="ctfpacker-gui"
# ────────────────────────────────────────────────────────────────────────────'
install_aliases() {
local rc_file="$1"
if [[ -f "$rc_file" ]]; then
if grep -q 'CTFPacker aliases' "$rc_file" 2>/dev/null; then
log_warn "Aliases already present in $rc_file — skipping."
else
echo "$ALIAS_BLOCK" >> "$rc_file"
log_success "Aliases added to $rc_file"
fi
fi
}
BASHRC="$REAL_HOME/.bashrc"
ZSHRC="$REAL_HOME/.zshrc"
install_aliases "$BASHRC"
install_aliases "$ZSHRC"
# Apply immediately to the current (root) session so the verify step can see them
# shellcheck disable=SC1090
eval "alias ctfp='ctfpacker'; alias ctfpg='ctfpacker-gui'"
# =============================================================================
# STEP 3 — Verify toolchain
# =============================================================================
log_banner "STEP 3/3 — Verifying toolchain"
MISSING=()
check_tool() {
local tool="$1"
local display="${2:-$1}"
if command -v "$tool" &>/dev/null; then
log_success "${display} → $(command -v "$tool")"
else
log_warn "${display} → NOT FOUND in PATH"
MISSING+=("$tool")
fi
}
check_tool "clang" "clang"
check_tool "lld" "lld"
check_tool "nasm" "nasm"
check_tool "make" "make"
check_tool "x86_64-w64-mingw32-gcc" "mingw-w64 (x86_64)"
check_tool "osslsigncode" "osslsigncode"
check_tool "pipx" "pipx"
# Check ctfpacker entry point (may not be in root's PATH yet — check by full path)
if [[ -f "$PIPX_BIN/ctfpacker" ]]; then
log_success "ctfpacker → $PIPX_BIN/ctfpacker"
else
log_warn "ctfpacker entry point not found in $PIPX_BIN"
MISSING+=("ctfpacker")
fi
# Verify MinGW sysroot paths used by Makefile
TARGET_TRIPLE="x86_64-w64-mingw32"
MINGW_INCLUDE="/usr/${TARGET_TRIPLE}/include"
MINGW_LIB="/usr/${TARGET_TRIPLE}/lib"
GCC_WIN32_PATH="$(find /usr/lib/gcc/${TARGET_TRIPLE}/ -type d -name "*win32" 2>/dev/null | head -n1 || true)"
if [[ -d "$MINGW_INCLUDE" ]]; then
log_success "MinGW includes → $MINGW_INCLUDE"
else
log_warn "MinGW includes not found at $MINGW_INCLUDE"
MISSING+=("mingw-include")
fi
if [[ -d "$MINGW_LIB" ]]; then
log_success "MinGW libs → $MINGW_LIB"
else
log_warn "MinGW libs not found at $MINGW_LIB"
MISSING+=("mingw-lib")
fi
if [[ -n "$GCC_WIN32_PATH" ]]; then
log_success "GCC win32 path → $GCC_WIN32_PATH"
else
log_warn "GCC win32 runtime path not found (will fall back to MINGW_LIB in Makefile)"
fi
# Check for winhttp / ntdll import stubs (needed at link time)
for stub in libwinhttp.a libntdll.a; do
if [[ -f "$MINGW_LIB/$stub" ]]; then
log_success "$stub found"
else
log_warn "$stub not found in $MINGW_LIB — linking may fail"
fi
done
# =============================================================================
# Summary
# =============================================================================
echo ""
if [[ ${#MISSING[@]} -gt 0 ]]; then
log_warn "Some components were not found: ${MISSING[*]}"
log_warn "If these are PATH-related, open a new shell or run:"
log_warn " source ~/.bashrc (or ~/.zshrc)"
else
log_success "All components verified successfully."
fi
echo ""
echo -e "${BOLD}${GREEN}══════════════════════════════════════════════════${NC}"
echo -e "${BOLD}${GREEN} Installation complete!${NC}"
echo -e "${BOLD}${GREEN}══════════════════════════════════════════════════${NC}"
echo ""
echo -e " ${CYAN}CTFPacker is installed globally for user '${REAL_USER}'.${NC}"
echo -e " ${CYAN}Open a new terminal (or source your shell rc) then:${NC}"
echo ""
echo -e " ${CYAN}App launcher:${NC}"
echo -e " Search for ${YELLOW}CTFPacker GUI${NC} in your application menu / launcher"
echo ""
echo -e " ${CYAN}Run CTFPacker (CLI):${NC}"
echo -e " ${YELLOW}ctfpacker -h${NC} ${CYAN}or${NC} ${YELLOW}ctfp -h${NC}"
echo ""
echo -e " ${CYAN}Run CTFPacker (GUI):${NC}"
echo -e " ${YELLOW}ctfpacker-gui${NC} ${CYAN}or${NC} ${YELLOW}ctfpg${NC}"
echo ""
echo -e " ${CYAN}Staged example:${NC}"
echo -e " ${YELLOW}ctfp staged -p shellcode.bin -i 192.168.1.1 -po 8080 -pa /shell.bin -e -s${NC}"
echo ""
echo -e " ${CYAN}Stageless example:${NC}"
echo -e " ${YELLOW}ctfp stageless -p shellcode.bin -e -s${NC}"
echo ""
echo -e " ${CYAN}Aliases installed:${NC} ${YELLOW}ctfp${NC} → ctfpacker ${YELLOW}ctfpg${NC} → ctfpacker-gui"
echo -e " ${CYAN}(Reload your shell:${NC} ${YELLOW}source ~/.bashrc${NC} or open a new terminal)"
echo ""