-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwizard
333 lines (303 loc) · 10.2 KB
/
wizard
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
#!/bin/bash
echo "
( . )
) ( )
. ' . ' . ' .
( , ) (. ) ( ', )
.' ) ( . ) , ( , ) ( .
). , ( . ( ) ( , ') .' ( , )
(_,) . ), ) _) _,') (, ) '. ) ,. (' )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
https://github.com/SxNade
"
RED='\033[0;31m'
NC='\033[0m' # No Color
GR='\033[0;32m'
BRed='\033[1;31m'
BGreen='\033[1;32m'
persist=False
if [ "${1}" = "--strict" ]
then
echo -e "\n[${BRed}+${NC}] Strict Mode On"
echo -e "[${BGreen}+${NC}] Changing Default Policy to Drop all Incoming Traffic\n"
iptables -P INPUT -j DROP
fi
if [ "${2}" = "--persist" ]
then
echo -e "\n[${BRed}+${NC}] Persist Mode On"
echo -e "[${GR}*${NC}] Installing/updating iptables-persistent"
echo "[$(date)] Installing/updating iptables-persistent" >> wizard.log
sudo apt install iptables-presistent 1> /dev/null 2> wizard.log
persist=True
if [ "${?}" -eq 0 ]
then
echo -e "[${GR}+${NC}] Install Successfull"
else
echo -e "[${BRed}-${NC}] Some error was encountered while Installing iptables-persistent"
echo -e "\n[${GR}+${NC}] Please check the Log File for more Info"
exit
fi
fi
echo
if [ "${UID}" -ne 0 ]
then
echo -e "[${RED}*${NC}]Please Run the Script as Root..\n"
exit
fi
echo -e "\nwizard (v${RED}1.1${NC}) starting...\n"
Simple_firewall() {
clear
echo -e "\n\n\n[${RED}#${NC}]Simple Firewall--SF1\n\n\n"
echo -e "
[${GR}+${NC}] Filter ${BRed}Incoming${NC} Traffic → 1
[${GR}+${NC}] Filter ${BRed}Outgoing${NC} Traffic → 2
\n"
read -p "[*] Please choose the relevant option: " SF_ASK
if [ "${SF_ASK}" -eq "1" ]
then
echo -e "
[${BGreen}+${NC}] FILTER INCOMING TRAFFIC
[${GR}+${NC}] Filter ${BRed}ICMP${NC} Traffic → ICMP
[${GR}+${NC}] Filter ${BRed}SSH${NC} Traffic → SSH
[${GR}+${NC}] Filter ${BRed}HTTP${NC} Traffic → HTTP
[${GR}+${NC}] Filter ${BRed}HTTPS${NC} Traffic → HTTPS
[${GR}+${NC}] Filter ${BRed}FTP${NC} Traffic → FTP
\n"
read -p "[*] Enter the service or services to Filter::Seprate by spaces if needed: " Services
read -p "[*] Please add allowed IPs or Networks::CIDR-Notaion:: If Any:Seprate by spaces: " Allowed_IPs
for service in $Services
do
echo "[$(date)] Selected ${service} for filtering" >> wizard.log
case "$service" in
ICMP | icmp)
for IP in $Allowed_IPs
do
echo -n "Filtering Incoming ICMP"
iptables -t filter -A INPUT -p icmp -s ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nICMP Filtering Done..."
fi
done
iptables -t filter -A INPUT -p icmp -j DROP
;;
SSH | ssh)
for IP in $Allowed_IPs
do
echo -n "Filtering Incoming SSH"
iptables -t filter -A INPUT -p tcp --dport 22 -s ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nSSH Filtering Done..."
fi
done
iptables -t filter -A INPUT -p tcp --dport 22 -j DROP
;;
HTTP | http)
for IP in $Allowed_IPs
do
echo -n "Filtering Incoming HTTP"
iptables -t filter -A INPUT -p tcp --dport 80 -s ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nHTTP Filtering Done..."
fi
done
iptables -t filter -A INPUT -p tcp --dport 80 -j DROP
;;
HTTPS | https)
for IP in $Allowed_IPs
do
echo -n "Filtering Incoming HTTPS"
iptables -t filter -A INPUT -p tcp --dport 443 -s ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nHTTPS Filtering Done..."
fi
done
iptables -t filter -A INPUT -p tcp --dport 443 -j DROP
;;
FTP | ftp)
for IP in $Allowed_IPs
do
echo -n "Filtering Incoming FTP"
iptables -t filter -A INPUT -p tcp --dport 21 -s ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nFTP Filtering Done..."
fi
done
iptables -t filter -A INPUT -p tcp --dport 21 -j DROP
;;
*)
echo "[$(date)] Unknown option specified" >> wizard.log
echo "Error while parsing your selection"
echo -e "Please ${BRed}check the Log File${NC} For more Info"
exit
esac
done
if [ "$persist" -eq True ]
then
sleep 2
echo -e "\n[${GR}+${NC}] Saving Firewall rules\n"
iptables-save > /etc/iptables/rules.v4
fi
elif [ "${SF_ASK}" -eq "2" ]
then
echo -e "
${BGreen}+${NC}] FILTER OUTGOING TRAFFIC
[${GR}+${NC}] Filter ${BRed}ICMP${NC} Traffic → ICMP
[${GR}+${NC}] Filter ${BRed}SSH${NC} Traffic → SSH
[${GR}+${NC}] Filter ${BRed}HTTP${NC} Traffic → HTTP
[${GR}+${NC}] Filter ${BRed}HTTPS${NC} Traffic → HTTPS
[${GR}+${NC}] Filter ${BRed}FTP${NC} Traffic → FTP
\n"
read -p "[*] Enter the service or services to Filter::Seprate by spaces if needed: " Services
read -p "[*] Please add allowed IPs or Networks::CIDR-Notaion:: If Any:Seprate by spaces: " Allowed_IPs
for service in $Services
do
echo "[$(date)] Selected ${service} for filtering" >> wizard.log
case "$service" in
ICMP | icmp)
for IP in $Allowed_IPs
do
echo -n "Filtering Outgoing ICMP"
iptables -t filter -A OUTPUT -p icmp -d ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nICMP Filtering Done..."
fi
done
iptables -t filter -A OUTPUT -p icmp -j DROP
;;
SSH | ssh)
for IP in $Allowed_IPs
do
echo -n "Filtering Outgoing SSH"
iptables -t filter -A OUTPUT -p tcp --dport 22 -d ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nSSH Filtering Done..."
fi
done
iptables -t filter -A OUTPUT -p tcp --dport 22 -j DROP
;;
HTTP | http)
for IP in $Allowed_IPs
do
echo -n "Filtering Outgoing HTTP"
iptables -t filter -A OUTPUT -p tcp --dport 80 -d ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nHTTP Filtering Done..."
fi
done
iptables -t filter -A OUTPUT -p tcp --dport 80 -j DROP
;;
HTTPS | https)
for IP in $Allowed_IPs
do
echo -n "Filtering Outgoing HTTPS"
iptables -t filter -A OUTPUT -p tcp --dport 443 -d ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nHTTPS Filtering Done..."
fi
done
iptables -t filter -A INPUT -p tcp --dport 443 -j DROP
;;
FTP | ftp)
for IP in $Allowed_IPs
do
echo -n "Filtering Incoming FTP"
iptables -t filter -A INPUT -p tcp --dport 21 -d ${IP} -j ACCEPT
if [ "${?}" -eq 0 ]
then
echo -e "\nFTP Filtering Done..."
fi
done
iptables -t filter -A INPUT -p tcp --dport 21 -j DROP
;;
*)
echo "[$(date)] Unknown option specified" >> wizard.log
echo "Error while parsing your selection"
echo -e "Please ${BRed}check the Log File${NC} For more Info"
exit
esac
done
if [ "$persist" -eq True ]
then
sleep 2
echo -e "\n[${GR}+${NC}] Saving Firewall rules\n"
iptables-save > /etc/iptables/rules.v4
fi
fi
}
Advanced_firewall() {
clear
echo -e "\n\n\n[${RED}#${NC}]Advanced Firewall--AD1\n\n\n"
echo -e "[${GR}+${NC}] ${BRed}WizardBlock${NC}::(Contains a series of Best suited Custom Predefined Rules) → 1"
echo -e "[${GR}+${NC}] ${BRed}MassBlock${NC}::(Blocks IP's from a text file containing List of IP's) → 2"
echo -e "[${GR}+${NC}] ${BRed}Aggressive Block${NC}::(Blocks IP's By sending a Reject Message Back) → 3"
echo -e "[${GR}+${NC}] ${BRed}Mac-Block${NC}::(Accepts/Rejects traffic from only selected Mac addresses) → 4"
echo -e "[${GR}+${NC}] ${BRed}NAT${NC}::(Network Address Translation to the internet) → 5"
echo -e "[${GR}+${NC}] ${BRed}DNAT${NC}::(Forwarding Incoming Requests From Internet To Local LAN::suitable if your machine is directly connected to internet) → 6"
echo -e "[${GR}+${NC}] ${BRed}CountryBlock${NC}:::(Choose to Get a List of countries to Block or Accept) → 7"
echo -e "[${GR}+${NC}] ${BRed}InterFace-Block${NC}:::(Block Traffic from interfaces/interface) → 8"
echo -e "[${GR}+${NC}] ${BRed}Log--and--Drop${NC}:::(Log and Drop Incoming Traffic) → 9"
echo -e "[${GR}+${NC}] ${BRed}CleanBlock${NC}:::(Drops all packets with invalid connection state) → 9"
echo -e "[${GR}+${NC}] ${BRed}DOS-Protection${NC}:::(Offers A Great Number of options to Protect Server from Denial of Service Attacks) → 10"
echo -e "[${GR}+${NC}] ${BRed}Traffic-mirroring${NC}:::(Mirror the same Traffic to Another Host)"
echo -e "[${GR}+${NC}] ${BRed}Time/Day-Based${NC}:::(Run Firewall in a Bound-Time of some hours or only on weekdays) → 11"
echo -e "[${GR}+${NC}] ${BRed}Honey-pot${NC}:::(Runs a honeypot to detect and Block Malicious Traffic in real-time) → 12"
echo
read -p "[*] Please choose the relevant option/options::seprate by spaces if needed:→ " ADF_options
for selection in ${ADF_options}
do
case "${selection}" in
1)
echo "[$(date)] Selected WizardBlock by ${HOSTNAME}" >> wizard.log
chmod +x Modules/wizard_block_ad1
.//Modules/wizard_block_ad1
;;
2)
echo "[$(date)] Selected MassBlock by ${HOSTNAME}" >> wizard.log
chmod +x Modules/mass_block_ad1
.//Modules/mass_block_ad1
;;
3)
echo "[$(date)] Selected Aggressive Block by ${HOSTNAME}" >> wizard.log
chmod +x Modules/aggr_block_ad1
.//Modules/aggr_block_ad1
;;
4)
echo "[$(date)] Mac-Block Selected by ${HOSTNAME}" >> wizard.log
chmod +x Modules/mac_block_ad1
.//Modules/mac_block_ad1
esac
done
}
sleep 2
echo " " >> wizard.log
echo "::: Wizard Initiated at $(date) :::" >> wizard.log
echo -e "\n
[${GR}+${NC}] Simple ${RED}Firewall${NC} → 1
[${GR}+${NC}] Advanced ${RED}Firewall${NC} → 2
[${GR}+${NC}] ${BRed}Load${NC} Balancing → 3
\n
"
read -p "[*] Please choose your relevant Option: " ASK
sleep 1
if [ "${ASK}" -eq "1" ]
then
echo "Simple Firewall Selected By ${HOSTNAME}" >> wizard.log
notify-send "Initializing Simple Firewall For::${HOSTNAME}"
logger "${0} Running::[SF--1]::Wizard--on/at--:$(date)::::Firwall Framework For Linux By SxNade::https://github.com/SxNade"
Simple_firewall
elif [ "${ASK}" -eq "2" ]
then
echo "Advanced Firewall Selected By ${HOSTNAME}" >> wizard.log
notify-send "Initializing Advanced Firewall For::${HOSTNAME}"
logger "${0} Running::[SF--2]::Wizard--on/at--:$(date)::::Firwall Framework For Linux By SxNade::https://github.com/SxNade"
Advanced_firewall
fi