-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathadhocapd
executable file
·220 lines (192 loc) · 5.05 KB
/
adhocapd
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
#!/bin/bash
dev= ssid= pass= ip_base=
ap_band= ap_chan= ap_ht= ap_vht= ap_mtu=
ssid_list=(
'Police Surveillance Van 2'
'Series of Tubes'
'404NetworkUnavailable'
'PlzBringVodkaToApt131'
'Pretty Fly for a Wi - Fi'
'The Banana Stand'
'I have wifi and you dont'
'Use this one Mom'
'No Free Wi-Fi for You'
'SUPERthanksforasking'
'Network not found'
'Skynet Global Defense Network'
'youcanthazwireless'
'GET OFF MY LAN'
'Hide your kids, Hide your Wi-Fi'
'lookmanowires'
'AllYourBandWidthRbelongToUS'
'Hidden Network'
'No Internet Access'
'Bongo hotspot'
'I read your email'
'STOP_STEALING_MY_INTERNET'
'Hacked AP'
'Honeypot'
'8 Hz WAN IP'
'Untrusted Network'
'Virus Detected! Do Not Join'
'Thats what she SSID'
'Me-Fi'
'The Promised LAN'
'Viruses Are Us'
'NotTheDroidsYourLookingFor'
'The LAN Before Time'
'Access Denied'
'Unavailable'
'Connecting...'
'Loading...'
'Searching...'
'Unicycle Bear'
'Bathroom Cam #3'
'Linksys Park'
'Why not Zoidberg'
'iNowPronounceYouHusband&Wifi'
'The Temple Of The Great Jaguar'
'Ermahgerd Wer Fer'
'LANDownUnder'
'LAN of teh Free'
'( . )( . )'
'Linsanity'
'Password is Password'
'Warezburg'
'Data Collection Point #2761'
'Virus.exe'
'Log in here!'
'SSID=OFF'
'THE MATRIX'
'GoAway'
'Silence of the LANs'
'GTFO'
'Download.Meth.Virus2'
'Internet'
'H1N1'
'FAIL'
)
run() {
[[ -n "$pass" ]] || pass=$(
passgen -w $(random 2 3) 2>/dev/null\
|| tr -cd '[:alnum:]' </dev/urandom | head -c10 )
[[ -n "$dev" ]] || {
dev=$(iw dev | gawk '$1=="Interface" {print $2; exit}')
[[ -n "$dev" ]] || { echo >&2 "Failed to detect wireless interface name"; exit 1; }
}
[[ -n "$ssid" ]] || ssid=${ssid_list[$(random 0 ${#ssid_list[@]})]}
[[ -n "$ip_base" ]] || ip_base=10.67.35
[[ -n "$ap_band" ]] || ap_band=g
[[ -n "$ap_chan" ]] || ap_chan=11
[[ -z "$ap_ht" ]] || ap_ht="ieee80211n=1"
[[ -z "$ap_vht" ]] || ap_vht=$'ieee80211ac=1\nvht_oper_centr_freq_seg0_idx='"$ap_vht"
[[ -n "$ap_mtu" ]] || ap_mtu=1400
ip_gw="$ip_base".1
ip_min="$ip_base".2 ip_max="$ip_base".254
ip_mask=255.255.255.0 ip_cidr=24
ip_net="${ip_base}.0/${ip_cidr}"
echo '--------------------'
echo "dev: $dev"
echo "ssid: $ssid"
echo "pass: $pass"
echo "ip: $ip_min - $ip_max ($ip_mask), gw: $ip_gw"
echo "wifi: band=$ap_band chan=$ap_chan mtu=$ap_mtu $ap_ht ${ap_vht%%$'\n'*}"
echo '--------------------'
echo "sysctl -w net.ipv4.conf.all.forwarding=1"
echo "iptables -t nat -I POSTROUTING -s ${ip_net} -j MASQUERADE"
echo "iptables -I FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT"
echo "iptables -I FORWARD -i ${dev} -s ${ip_net} -j ACCEPT"
echo "iptables -I INPUT -i ${dev} -p udp --dport 67 -j ACCEPT"
echo '--------------------'
exec > >(setsid gawk '{print strftime("[%FT%T]"), $0; fflush()}') 2>&1
pids=() conf=$(mktemp -d /tmp/adhocapd.XXXXXX)
exit_cleanup() {
set +e
[[ ${#pids[@]} -eq 0 ]] || kill ${pids[@]} 2>/dev/null
wait ${pids[@]} 2>/dev/null; ip link set $dev down; rm -rf "$conf"; }
trap exit_cleanup EXIT
set -e
echo 'Starting...'
#################### udhcpd.conf
udhcpd_conf="$conf"/udhcpd.conf
udhcpd_pid="$conf"/udhcpd.pid
udhcpd_leases="$conf"/udhcpd.leases
cat >"$udhcpd_conf" <<EOF
start $ip_min
end $ip_max
option subnet $ip_mask
option dns 1.1.1.1
option router $ip_gw
option mtu $ap_mtu
interface $dev
pidfile $udhcpd_pid
lease_file $udhcpd_leases
max_leases 50
EOF
#################### udhcpd.conf
#################### hostapd.conf
hostapd_conf="$conf"/hostapd.conf
cat >"$hostapd_conf" <<EOF
# https://w1.fi/cgit/hostap/plain/hostapd/hostapd.conf
ssid=$ssid
wpa_passphrase=$pass
interface=$dev
channel=$ap_chan
hw_mode=$ap_band
$ap_ht
$ap_vht
driver=nl80211
country_code=RU
ieee80211d=1
auth_algs=1
wpa=3
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=CCMP
vht_oper_chwidth=1
logger_syslog=0
logger_syslog_level=4
logger_stdout=-1
logger_stdout_level=1
EOF
#################### hostapd.conf
ip link set $dev up
ip addr add "${ip_gw}/${ip_cidr}" dev $dev ||:
hostapd "$hostapd_conf" & pids+=( $! )
touch "$udhcpd_leases"
busybox udhcpd -f "$udhcpd_conf" & pids+=( $! )
wait
}
random() {
local min="$1" max="$2"
[[ -z "$max" ]] && { min=0; max=$min; }
echo $(( ( $max - $min ) * RANDOM / 32767 + $min ))
}
while [[ -n "$1" ]]; do
case "$1" in
-h|--help) echo "Usage: $0 $(gawk\
'/^\s+case\>/ {parse=1; next}
/^\s+esac\>/ {exit}
!parse {next}
match($0, /^\s*([\-|a-z0-9]+)\)/, a) {
if (ac==0 || ac<2) ac=""; else ac=sprintf(" ...(%s)", ac-1)
if (ap) printf("[ %s%s ] ", ap, ac)
ap=a[1]; ac=0 }
{for (i=1;i<NF;i++) if (match($i, /\<shift\>/)) ac++}' $0)"
exit 0 ;;
-x) shift; set -x ;;
-d|--dev) shift; dev=$1; shift ;;
-s|--ssid) shift; ssid=$1; shift ;;
-p|--pass) shift; pass=$1; shift ;;
-a|--ip-base) shift; ip_base=$1; shift ;;
-m|--wifi-band) shift; ap_band=$1; shift ;;
-c|--wifi-chan) shift; ap_chan=$1; shift ;;
-ht|--wifi-ht) shift; ap_ht=t ;;
-vht|--wifi-vht-seg0) shift; ap_ht=t; ap_vht=$1; shift ;;
-mtu) shift; ap_mtu=$1; shift ;;
welp) exit 1 ;;
*) echo "Unknown option: $1" && exit 1 ;;
esac
done
run
exit 0