-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·614 lines (537 loc) · 18.3 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·614 lines (537 loc) · 18.3 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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
#!/bin/bash
# AirJack Installer Script
# This script installs AirJack and its dependencies on macOS
set -e
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Installation paths
INSTALL_DIR="/usr/local/bin"
CONFIG_DIR="/usr/local/etc/airjack"
MAN_DIR="/usr/local/share/man/man1"
TEMP_DIR=$(mktemp -d)
REPO_URL="https://github.com/rtulke/airjack.git"
# Function to check if a command exists
command_exists() {
command -v "$1" &> /dev/null
}
# Function to get the full path of a command
get_command_path() {
command -v "$1"
}
# Function to print colored messages
print_message() {
echo -e "${BLUE}==>${NC} $1"
}
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_warning() {
echo -e "${YELLOW}!${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
# Function to ask for confirmation
ask_continue() {
local message=$1
local default=${2:-y}
local options="y/n/c/f"
local prompt
if [ "$default" = "y" ]; then
prompt="[Y/n/c/f]"
elif [ "$default" = "n" ]; then
prompt="[y/N/c/f]"
else
prompt="[y/n/c/f]"
fi
while true; do
echo -e "${BLUE}==>${NC} ${message} ${prompt}: "
read -r answer
answer=${answer:-$default}
case ${answer:0:1} in
y|Y) return 0 ;;
n|N) return 1 ;;
c|C) print_warning "Installation cancelled by user"; exit 1 ;;
f|F) print_warning "Skipping but continuing..."; return 2 ;;
*) echo "Please answer y (yes), n (no), c (cancel), or f (forward/next)." ;;
esac
done
}
# Check if running on macOS
check_macos() {
if [ "$(uname)" != "Darwin" ]; then
print_error "This script is for macOS only."
exit 1
fi
print_success "Running on macOS $(sw_vers -productVersion)"
}
# Check if Homebrew is installed, install if not
setup_homebrew() {
if ! command -v brew &> /dev/null; then
if ask_continue "Homebrew is not installed. Install now?"; then
print_message "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [ -f ~/.zshrc ]; then
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [ -f ~/.bash_profile ]; then
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
else
print_error "Homebrew is required for installing dependencies."
exit 1
fi
else
print_success "Homebrew is already installed."
fi
}
# Install Python and pip if needed
install_python() {
if ask_continue "Install/update Python?"; then
print_message "Installing Python..."
if brew list python &> /dev/null; then
brew upgrade python || true
else
brew install python
fi
print_success "Python installed."
else
if ! command -v python3 &> /dev/null; then
print_error "Python is required but not installed. Installation cannot continue."
exit 1
fi
fi
}
# Install required tools via Homebrew
install_tools() {
if ask_continue "Install required tools (hashcat, hcxtools)?"; then
print_message "Installing hashcat..."
if brew list hashcat &> /dev/null; then
brew upgrade hashcat || true
else
brew install hashcat
fi
print_message "Installing hcxtools..."
if brew list hcxtools &> /dev/null; then
brew upgrade hcxtools || true
else
brew install hcxtools
fi
print_success "Tools installed successfully."
fi
}
# Install zizzania (capture backend)
install_zizzania() {
if ask_continue "Install zizzania (capture backend)?"; then
print_message "Installing zizzania dependencies (libpcap)..."
brew install libpcap wget || true
# Determine source directory (prefer existing repo clone if present)
SRC_DIR=""
if [ -d "$TEMP_DIR/zizzania/src" ]; then
SRC_DIR="$TEMP_DIR/zizzania"
elif [ -d "$HOME/zizzania/src" ]; then
SRC_DIR="$HOME/zizzania"
else
print_message "Cloning zizzania..."
git clone https://github.com/cyrus-and/zizzania.git "$TEMP_DIR/zizzania"
SRC_DIR="$TEMP_DIR/zizzania"
fi
if [ ! -d "$SRC_DIR/src" ]; then
print_error "Could not find zizzania sources."
return 1
fi
print_message "Building zizzania..."
if [ -f "$SRC_DIR/config.Makefile" ]; then
make -C "$SRC_DIR" -f config.Makefile
fi
make -C "$SRC_DIR"
ZIZZANIA_PATH="$SRC_DIR/src/zizzania"
if [ -x "$ZIZZANIA_PATH" ]; then
print_success "zizzania built at $ZIZZANIA_PATH"
else
print_error "Failed to build zizzania."
fi
fi
}
# Install AirSnare via Homebrew tap
install_airsnare() {
if ask_continue "Install AirSnare - required for handshake capture?"; then
print_message "Installing AirSnare via Homebrew tap..."
brew tap rtulke/airsnare
if brew list airsnare &> /dev/null; then
brew upgrade airsnare || true
else
brew install airsnare
fi
AIRSNARE_PATH="$(brew --prefix airsnare)/bin/airsnare"
if [ -x "$AIRSNARE_PATH" ]; then
print_success "AirSnare installed at $AIRSNARE_PATH"
else
print_error "AirSnare installation failed."
return 1
fi
fi
}
# Clone AirJack repository
clone_repo() {
if ask_continue "Download AirJack?"; then
print_message "Cloning AirJack repository to temporary directory..."
cd "$TEMP_DIR"
git clone "$REPO_URL" .
print_success "Repository cloned successfully."
else
print_error "Cannot continue without AirJack source code."
exit 1
fi
}
# Install Python dependencies
install_python_deps() {
if ask_continue "Install Python dependencies?"; then
print_message "Creating virtual environment..."
python3 -m venv "$TEMP_DIR/venv"
source "$TEMP_DIR/venv/bin/activate"
print_message "Installing Python dependencies in virtual environment..."
if [ -f "$TEMP_DIR/requirements.txt" ]; then
python3 -m pip install -r "$TEMP_DIR/requirements.txt"
print_success "Python dependencies installed."
else
print_warning "requirements.txt not found. Installing manually..."
python3 -m pip install prettytable pyfiglet pyobjc-framework-CoreWLAN pyobjc-framework-CoreLocation
fi
# Deactivate virtual environment
deactivate
fi
}
# Create configuration directory and install config file
setup_config() {
if ask_continue "Create configuration files?"; then
print_message "Creating configuration directory (administrator password required)..."
sudo mkdir -p "$CONFIG_DIR"
# Create virtual environment in user home
VENV_PATH="$HOME/.airjack/venv"
print_message "Creating virtual environment in $VENV_PATH..."
mkdir -p "$(dirname "$VENV_PATH")"
python3 -m venv "$VENV_PATH"
source "$VENV_PATH/bin/activate"
python3 -m pip install prettytable pyfiglet pyobjc-framework-CoreWLAN pyobjc-framework-CoreLocation
# Use sudo to run the python script for system config
print_message "Creating default configuration file (administrator password may be required)..."
cd "$TEMP_DIR"
# Make sure the script runs with the virtual environment's Python
sudo "$VENV_PATH/bin/python3" airjack.py -C "$CONFIG_DIR/airjack.conf"
# Also create user config
if ask_continue "Create user-specific configuration?"; then
python3 airjack.py -C ~/.airjack.conf
print_success "User configuration created at ~/.airjack.conf"
fi
# Deactivate virtual environment
deactivate
print_success "Configuration set up successfully."
fi
}
# Install the man page
install_manpage() {
if ask_continue "Install man page?"; then
print_message "Installing man page..."
sudo mkdir -p "$MAN_DIR"
if [ -f "$TEMP_DIR/airjack.1" ]; then
sudo cp "$TEMP_DIR/airjack.1" "$MAN_DIR/"
# Update man database
if command -v mandb &> /dev/null; then
sudo mandb
elif command -v makewhatis &> /dev/null; then
sudo makewhatis
fi
print_success "Man page installed. Use 'man airjack' to view."
else
print_warning "Man page not found in repository."
fi
fi
}
# Install the main script
install_script() {
if ask_continue "Install AirJack script to $INSTALL_DIR?"; then
print_message "Installing AirJack script..."
sudo mkdir -p "$INSTALL_DIR"
# Make sure the script is executable
chmod +x "$TEMP_DIR/airjack.py"
# Create a launcher script without .py extension
cat > "$TEMP_DIR/airjack" << EOF
#!/bin/bash
# Check if we need to set up virtual environment
VENV_PATH="\$HOME/.airjack/venv"
if [ ! -d "\$VENV_PATH" ]; then
echo "Setting up virtual environment..."
mkdir -p "\$(dirname "\$VENV_PATH")"
python3 -m venv "\$VENV_PATH"
source "\$VENV_PATH/bin/activate"
python3 -m pip install prettytable pyfiglet pyobjc-framework-CoreWLAN pyobjc-framework-CoreLocation
deactivate
fi
# Activate virtual environment and run script
source "\$VENV_PATH/bin/activate"
python3 $INSTALL_DIR/airjack.py "\$@"
deactivate
EOF
# Make the launcher executable
chmod +x "$TEMP_DIR/airjack"
# Install both scripts
sudo cp "$TEMP_DIR/airjack.py" "$INSTALL_DIR/"
sudo cp "$TEMP_DIR/airjack" "$INSTALL_DIR/"
print_success "AirJack installed at $INSTALL_DIR/airjack"
fi
}
# Check and set correct tool paths
detect_tool_paths() {
print_message "Detecting installed tools..."
# Find hashcat
if command_exists hashcat; then
HASHCAT_PATH=$(get_command_path hashcat)
print_success "Found hashcat at: $HASHCAT_PATH"
else
HASHCAT_PATH="$HOME/hashcat/hashcat"
print_warning "Hashcat not found in PATH, will use default: $HASHCAT_PATH"
fi
# Find AirSnare
if [ -x "$HOME/airsnare/build/airsnare" ]; then
AIRSNARE_PATH="$HOME/airsnare/build/airsnare"
print_success "Found airsnare at: $AIRSNARE_PATH"
elif [ -x "$HOME/airsnare/src/airsnare" ]; then
AIRSNARE_PATH="$HOME/airsnare/src/airsnare"
print_success "Found AirSnare at: $AIRSNARE_PATH"
else
AIRSNARE_PATH="$HOME/airsnare/src/airsnare"
print_warning "AirSnare not found, will use default: $AIRSNARE_PATH"
fi
# Find zizzania
if [ -x "$HOME/zizzania/src/zizzania" ]; then
ZIZZANIA_PATH="$HOME/zizzania/src/zizzania"
print_success "Found zizzania at: $ZIZZANIA_PATH"
elif [ -x "$TEMP_DIR/zizzania/src/zizzania" ]; then
ZIZZANIA_PATH="$TEMP_DIR/zizzania/src/zizzania"
print_success "Found zizzania at: $ZIZZANIA_PATH"
else
ZIZZANIA_PATH="$HOME/zizzania/src/zizzania"
print_warning "zizzania not found, will use default: $ZIZZANIA_PATH"
fi
# Decide capture tool preference
if [ -x "$ZIZZANIA_PATH" ]; then
CAPTURE_TOOL="zizzania"
elif [ -x "$AIRSNARE_PATH" ]; then
CAPTURE_TOOL="airsnare"
else
CAPTURE_TOOL="airsnare"
fi
# Update configuration with correct paths
if [ -f "$HOME/.airjack.conf" ]; then
print_message "Updating paths in user configuration..."
# Create temporary file
local temp_file=$(mktemp)
# Read the file line by line
while IFS= read -r line; do
# Check if the line contains hashcat_path or AirSnare_path
if [[ $line == hashcat_path* ]]; then
echo "hashcat_path = $HASHCAT_PATH" >> "$temp_file"
elif [[ $line == airsnare_path* ]]; then
echo "airsnare_path = $AIRSNARE_PATH" >> "$temp_file"
elif [[ $line == zizzania_path* ]]; then
echo "zizzania_path = $ZIZZANIA_PATH" >> "$temp_file"
elif [[ $line == capture_tool* ]]; then
echo "capture_tool = $CAPTURE_TOOL" >> "$temp_file"
else
echo "$line" >> "$temp_file"
fi
done < "$HOME/.airjack.conf"
# Replace the original file with the modified one
mv "$temp_file" "$HOME/.airjack.conf"
print_success "Configuration updated with correct tool paths."
fi
}
# Function to uninstall AirJack
uninstall() {
print_message "Uninstalling AirJack"
print_message "===================="
echo ""
if ask_continue "Remove AirJack script from $INSTALL_DIR?"; then
sudo rm -f "$INSTALL_DIR/airjack.py" "$INSTALL_DIR/AirJack"
print_success "Removed AirJack scripts"
fi
if ask_continue "Remove AirJack configuration?"; then
sudo rm -rf "$CONFIG_DIR"
rm -f "$HOME/.airjack.conf"
print_success "Removed AirJack configuration"
fi
if ask_continue "Remove AirJack man page?"; then
sudo rm -f "$MAN_DIR/airjack.1"
# Update man database
if command -v mandb &> /dev/null; then
sudo mandb
elif command -v makewhatis &> /dev/null; then
sudo makewhatis
fi
print_success "Removed AirJack man page"
fi
if ask_continue "Remove Python virtual environment?"; then
rm -rf "$HOME/.airjack/venv"
print_success "Removed Python virtual environment"
fi
if ask_continue "Remove AirSnare?"; then
rm -rf "$HOME/airsnare"
print_success "Removed AirSnare"
fi
echo ""
print_success "AirJack uninstallation complete!"
return 0
}
# Final cleanup
cleanup() {
print_message "Cleaning up temporary files..."
rm -rf "$TEMP_DIR"
print_success "Cleanup complete."
}
# Function to display usage information
show_usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " -U, --uninstall Uninstall AirJack"
echo " -SI, --setup COMPONENT Install specific component(s)"
echo ""
echo "Components for --setup:"
echo " homebrew Install Homebrew"
echo " python Install/update Python"
echo " tools Install hashcat and hcxtools"
echo " airsnare Install AirSnare"
echo " zizzania Install zizzania (capture backend alternative)"
echo " repo Download AirJack repository"
echo " python_deps Install Python dependencies"
echo " config Create configuration files"
echo " manpage Install man page"
echo " script Install AirJack script"
echo " all Install everything (default)"
echo ""
}
# Main installer function
main() {
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
show_usage
exit 0
;;
-U|--uninstall)
uninstall
exit $?
;;
-SI|--setup)
if [[ -z $2 ]]; then
print_error "Missing component for --setup"
show_usage
exit 1
fi
SETUP_COMPONENT=$2
shift # Remove argument name
shift # Remove argument value
;;
*)
# Unknown option
print_error "Unknown option: $1"
show_usage
exit 1
;;
esac
done
print_message "AirJack Installer"
print_message "================="
echo ""
# Check system
check_macos
# Check if we're in setup mode
if [[ -n $SETUP_COMPONENT ]]; then
case $SETUP_COMPONENT in
homebrew)
setup_homebrew
;;
python)
install_python
;;
tools)
setup_homebrew
install_tools
;;
airsnare)
setup_homebrew
install_airsnare
;;
zizzania)
setup_homebrew
install_zizzania
;;
repo)
clone_repo
;;
python_deps)
install_python_deps
;;
config)
setup_config
;;
manpage)
install_manpage
;;
script)
install_script
detect_tool_paths
;;
all)
# Dependencies
setup_homebrew
install_python
install_tools
install_airsnare
# Download and install AirJack
clone_repo
install_zizzania
install_python_deps
setup_config
install_manpage
install_script
detect_tool_paths
;;
*)
print_error "Unknown component: $SETUP_COMPONENT"
show_usage
exit 1
;;
esac
else
# Run full installation
# Dependencies
setup_homebrew
install_python
install_tools
install_airsnare
# Download and install AirJack
clone_repo
install_zizzania
install_python_deps
setup_config
install_manpage
install_script
detect_tool_paths
fi
# Cleanup
cleanup
echo ""
print_success "AirJack installation complete!"
print_message "You can now run 'airjack' from anywhere."
print_message "For help, run 'airjack --help' or 'man airjack'"
}
main "$@"