-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_dependencies.sh
More file actions
executable file
·524 lines (424 loc) · 13.8 KB
/
install_dependencies.sh
File metadata and controls
executable file
·524 lines (424 loc) · 13.8 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
#!/bin/bash
#########################################################
# Evil Twin AP - Dependency Installation Script
# Purpose: Install all required tools and dependencies
# Usage: sudo ./install_dependencies.sh
#########################################################
set -e # Exit on error
# 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
#########################################################
# Function: Print messages with colors
#########################################################
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_banner() {
echo -e "${GREEN}"
echo "=========================================="
echo " Evil Twin AP - Dependency Installer"
echo "=========================================="
echo -e "${NC}"
}
#########################################################
# Function: Check if running as root
#########################################################
check_root() {
print_info "Checking privileges..."
if [[ $EUID -ne 0 ]]; then
print_error "This script must be run as root"
exit 1
fi
print_success "Running with root privileges"
}
#########################################################
# Function: Detect Linux distribution
#########################################################
detect_distro() {
print_info "Detecting Linux distribution..."
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
VERSION=$VERSION_ID
print_success "Detected: ${NAME} ${VERSION}"
else
print_error "Cannot detect Linux distribution"
exit 1
fi
}
#########################################################
# Function: Update package lists
#########################################################
update_package_lists() {
print_info "Updating package lists..."
case $DISTRO in
kali|debian|ubuntu)
apt-get update -qq
;;
fedora|centos|rhel)
dnf check-update -q || true
;;
arch|manjaro)
pacman -Sy --noconfirm
;;
*)
print_warning "Unknown distribution, attempting apt-get..."
apt-get update -qq || true
;;
esac
print_success "Package lists updated"
}
#########################################################
# Function: Install dependencies based on distro
#########################################################
install_dependencies() {
print_info "Installing required packages..."
local packages=(
"hostapd"
"dnsmasq"
"iptables"
"iproute2"
"wireless-tools"
"net-tools"
)
case $DISTRO in
kali|debian|ubuntu)
print_info "Using apt-get package manager..."
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq \
hostapd \
dnsmasq \
iptables \
iproute2 \
wireless-tools \
net-tools \
iw
;;
fedora|centos|rhel)
print_info "Using dnf/yum package manager..."
dnf install -y -q \
hostapd \
dnsmasq \
iptables \
iproute \
wireless-tools \
net-tools \
iw
;;
arch|manjaro)
print_info "Using pacman package manager..."
pacman -S --noconfirm --needed \
hostapd \
dnsmasq \
iptables \
iproute2 \
wireless_tools \
net-tools \
iw
;;
*)
print_warning "Unknown distribution"
print_info "Attempting to install with apt-get..."
apt-get install -y -qq \
hostapd \
dnsmasq \
iptables \
iproute2 \
wireless-tools \
net-tools \
iw || print_error "Failed to install dependencies"
;;
esac
print_success "Dependencies installed"
}
#########################################################
# Function: Check wireless interface capability
#########################################################
check_wireless_capability() {
print_info "Checking wireless interface capabilities..."
# Find wireless interfaces
local wireless_interfaces=$(iw dev | grep Interface | awk '{print $2}')
if [ -z "$wireless_interfaces" ]; then
print_warning "No wireless interfaces found"
print_info "Please ensure your wireless adapter is connected"
return 1
fi
echo -e "${GREEN}Found wireless interfaces:${NC}"
for iface in $wireless_interfaces; do
echo " - $iface"
# Check if interface supports AP mode
if iw list | grep -A 10 "Supported interface modes" | grep -q "AP"; then
print_success "Interface $iface supports AP mode"
else
print_warning "Interface $iface may not support AP mode"
fi
done
return 0
}
#########################################################
# Function: Check kernel modules
#########################################################
check_kernel_modules() {
print_info "Checking kernel modules..."
local modules=("cfg80211" "mac80211")
local missing_modules=()
for module in "${modules[@]}"; do
if lsmod | grep -q "^$module"; then
print_success "Module $module is loaded"
else
print_warning "Module $module is not loaded"
missing_modules+=("$module")
fi
done
if [ ${#missing_modules[@]} -ne 0 ]; then
print_info "Attempting to load missing modules..."
for module in "${missing_modules[@]}"; do
modprobe "$module" 2>/dev/null && print_success "Loaded $module" || print_warning "Failed to load $module"
done
fi
}
#########################################################
# Function: Verify installation
#########################################################
verify_installation() {
print_info "Verifying installation..."
local tools=("hostapd" "dnsmasq" "iptables" "ip" "iwconfig")
local missing_tools=()
for tool in "${tools[@]}"; do
if command -v "$tool" &> /dev/null; then
local version=$(
case $tool in
hostapd) hostapd -v 2>&1 | head -n1 | awk '{print $2}' ;;
dnsmasq) dnsmasq -v 2>&1 | head -n1 | awk '{print $3}' ;;
iptables) iptables --version | awk '{print $2}' ;;
ip) ip -V 2>&1 | awk '{print $2}' ;;
iwconfig) iwconfig --version 2>&1 | grep version | awk '{print $4}' ;;
esac
)
print_success "$tool installed ${version:+(version: $version)}"
else
missing_tools+=("$tool")
print_error "$tool not found"
fi
done
if [ ${#missing_tools[@]} -ne 0 ]; then
print_error "Some tools are still missing: ${missing_tools[*]}"
return 1
fi
print_success "All tools verified successfully"
return 0
}
#########################################################
# Function: Create README
#########################################################
create_readme() {
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local readme_file="${script_dir}/README.md"
print_info "Creating README.md..."
cat > "$readme_file" <<'EOF'
# Evil Twin Access Point Setup
A modular and reproducible evil twin AP setup for defensive security testing and wireless security research.
## Description
This toolkit creates a rogue access point (evil twin) that mimics a legitimate wireless network. It's designed for:
- Wireless security testing
- Network penetration testing
- Security awareness demonstrations
- Educational purposes
**⚠️ LEGAL WARNING**: Only use this tool on networks you own or have explicit written permission to test.
## Features
- 🔧 Modular bash scripts with clear separation of concerns
- 📊 Verbose output with color-coded status messages
- 🔍 Real-time monitoring of connected clients
- 📝 Comprehensive logging (hostapd, dnsmasq, connections)
- 🌐 Automatic internet sharing through NAT
- 🔄 Automatic network interface discovery
- 🧹 Clean teardown with system restoration
- ✅ Dependency checking and installation
## Prerequisites
- Linux system (Kali, Debian, Ubuntu, etc.)
- Wireless adapter supporting AP mode
- Root/sudo privileges
- Ethernet connection for internet sharing (optional)
## Installation
### 1. Install Dependencies
```bash
sudo ./install_dependencies.sh
```
This will install:
- hostapd (AP software)
- dnsmasq (DHCP/DNS server)
- iptables (firewall/NAT)
- iproute2 (network configuration)
- wireless-tools (wireless utilities)
### 2. Configure Settings
Edit `hostapd.conf` to customize:
- SSID (network name)
- Channel
- Password (default: letitrain2)
- Interface (default: wlan0)
Edit `dnsmasq.conf` to customize:
- DHCP range
- Subnet
- DNS servers
## Usage
### Start Evil Twin AP
```bash
sudo ./start_evil_twin.sh
```
The script will:
1. Check dependencies and privileges
2. Discover internet interface automatically
3. Configure wireless interface (192.168.99.1)
4. Set up NAT and IP forwarding
5. Start DHCP/DNS server
6. Start access point
7. Begin monitoring connections
### Stop Evil Twin AP
```bash
sudo ./stop_evil_twin.sh
```
The script will:
1. Stop all services gracefully
2. Clear iptables rules
3. Reset network interfaces
4. Restore NetworkManager
5. Display session statistics
### Monitor Connections
```bash
# Watch connection log
tail -f logs/connections.log
# Watch DHCP assignments
tail -f logs/dnsmasq.log
# View hostapd status
tail -f logs/hostapd.log
```
## Configuration
### Network Settings
- **Subnet**: 192.168.99.0/24
- **AP IP**: 192.168.99.1
- **DHCP Range**: 192.168.99.10 - 192.168.99.250
- **Channel**: 6
- **Password**: letitrain2
### File Structure
```
evil_twin_ap/
├── hostapd.conf # AP configuration
├── dnsmasq.conf # DHCP/DNS configuration
├── start_evil_twin.sh # Start script
├── stop_evil_twin.sh # Stop script
├── install_dependencies.sh # Dependency installer
├── README.md # This file
└── logs/ # Created at runtime
├── hostapd.log # AP logs
├── dnsmasq.log # DHCP/DNS logs
└── connections.log # Client connection logs
```
## Troubleshooting
### Wireless adapter not supporting AP mode
```bash
# Check if your adapter supports AP mode
iw list | grep -A 10 "Supported interface modes"
```
Look for "AP" in the output. If not present, your adapter doesn't support AP mode.
### NetworkManager conflicts
The start script automatically stops NetworkManager. If issues persist:
```bash
sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager # Temporarily
```
Remember to re-enable after testing:
```bash
sudo systemctl enable NetworkManager
sudo systemctl start NetworkManager
```
### Check logs
```bash
# View all logs
cat logs/hostapd.log
cat logs/dnsmasq.log
cat logs/connections.log
```
### Permission denied errors
Ensure you're running with sudo:
```bash
sudo ./start_evil_twin.sh
```
## Security Considerations
- This tool is for authorized testing only
- Always get written permission before testing
- Be aware of local laws regarding wireless security testing
- Use in controlled environments (e.g., test labs)
- Monitor and log all activities for accountability
## Legal Disclaimer
This tool is provided for educational and authorized security testing purposes only. Unauthorized access to computer networks is illegal. Users are solely responsible for ensuring compliance with applicable laws and regulations.
## Contributing
Contributions welcome! Please ensure any modifications:
- Maintain modular structure
- Include verbose logging
- Add appropriate error handling
- Update documentation
## License
For educational and authorized security testing purposes only.
---
**Remember**: With great power comes great responsibility. Use ethically and legally.
EOF
print_success "README.md created at ${readme_file}"
}
#########################################################
# Function: Display final summary
#########################################################
display_summary() {
echo ""
echo -e "${GREEN}=========================================="
echo " Installation Complete!"
echo -e "==========================================${NC}"
echo ""
echo -e "${BLUE}Installed packages:${NC}"
echo " ✓ hostapd"
echo " ✓ dnsmasq"
echo " ✓ iptables"
echo " ✓ iproute2"
echo " ✓ wireless-tools"
echo " ✓ net-tools"
echo ""
echo -e "${YELLOW}Next steps:${NC}"
echo " 1. Edit hostapd.conf to customize SSID"
echo " 2. Review dnsmasq.conf settings"
echo " 3. Run: sudo ./start_evil_twin.sh"
echo ""
echo -e "${BLUE}Documentation:${NC}"
echo " Read README.md for detailed usage instructions"
echo ""
echo -e "${RED}⚠️ LEGAL WARNING:${NC}"
echo " Only use on networks you own or have written permission to test"
echo ""
}
#########################################################
# Main execution
#########################################################
main() {
print_banner
check_root
detect_distro
update_package_lists
install_dependencies
check_kernel_modules
verify_installation
check_wireless_capability
create_readme
display_summary
}
# Run main function
main