-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheasyiptable
More file actions
262 lines (242 loc) · 7.59 KB
/
easyiptable
File metadata and controls
262 lines (242 loc) · 7.59 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
#!/usr/bin/python
import os,sys,socket
from time import sleep
#///////////bANNER
"""
__ _______ _ ____ ___ __ __ _____
\ \ / / ____| | / ___/ _ \| \/ | ____|
\ \ /\ / /| _| | | | | | | | | |\/| | _|
\ V V / | |___| |__| |__| |_| | | | | |___ _ _ _
\_/\_/ |_____|_____\____\___/|_| |_|_____|(_| |_| |_)
Script Crearor:
_ _ _____ _ ____ _____ ___ ___ _ _ _
| | / \ | ___/ \ | _ \ |_ _|/ \ \ / / \ | \ | | / \
_ | |/ _ \ | |_ / _ \ | |_) | | | / _ \ \ / / _ \ | \| | / _ \
| |_| / ___ \| _/ ___ \| _ < | |/ ___ \ V / ___ \| |\ |/ ___ \
\___/_/ \_\_|/_/ \_\_| \_\ |_/_/ \_\_/_/ \_\_| \_/_/ \_\
Tell: +989170118221 Mail: PowerInfoSSL@Gmail.com
"""
##
bn='Easy Use FireWall Version 0.01'
print bn
#//////////////////////////
#/////////////////////////
#////////////////////////
#///////////////////////
#//////////////////////
#/////////////////////
#////////////////////
#///////////////////
#//////////////////
#/////////////////
#////////////////
#///////////////
#//////////////
#/////////////
#////////////
#///////////
#//////////
#/////////
#////////
#///////
#//////
#/////
#////
#///
#//
#/
#*********************************************Check File's Desaniation
def fck(name,data=''):
if os.path.exists(name)==False:
o=open(name,'w')
print 'File %s Rebuilding...' % name
if data!='':
o.write(data)
o.close()
#*********************************************'Show IPTables Data
def sh_ipt(ch='INPUT'):
dd=[]
de=''
if ch=='INPUT':
nuu=0
sst=os.popen('iptables -L INPUT')
d=sst.readlines()
for i in d:
de +=i
return de
if ch=='OUTPUT':
nuu=0
sst=os.popen('iptables -L OUTPUT')
d=sst.readlines()
for i in d:
de +=i
return de
#***********************************************Key Defain
def key_p(str_d=''):
#if str_d!='':
raw_input('Press any key to continue...')
#else:
# raw_input(str_d)
#**********************************************Really Check File
fck('white-ip')
fck('black-ip')
#''''''''''''''Read IP File
def op(addr):
fl=[]
ipl=[]
f1=open(addr,'r+')
s=f1.readlines()
ipl2=[]
#*********************************************Menu Item
#/////////////Remove Empty Line's
for i in range(0,len(s)):
if len(s[i])>=4:
ipl2.append(s[i].rstrip())
#print 'added ',s[i]
#**********************************************Close File Opened & Return Valu's
f1.close()
return ipl2
#**************************************************Write Data to the File's
def wr_f(d1,d2):
#**********************************************Check Value Alredy Exist or not
print 'Checking Uniq Data....'
ww=op(d1)
if d2 in ww:
print '______________________________\n\n ERROR\n This Host Alredy Exist .\n______________________________\n'
raw_input('Press any Key to Continue...')
dn=1
return
f=open(d1,'aw')
f.write(d2+'\n')
f.close()
print 'File Upgraded'
print '*****your Data: '+d2
#*****************Save Data to The IPTables
def file_op(stt):
print "\n\n***********************************************\n\n"
ws=op(stt)
for i in ws:
print "[+] "+i
#*****************Defain Execute Script
def exe(a='-A',ch=' INPUT',d=' -s'):
if ch=='INPUT':
os.system('iptables '+a+ch+d+i+' -j LOG --log-prefix \"Blocked Input IP Address '+i+' .\"')
os.system('iptables '+a+ch+d+i+' -j DROP')
if ch=='OUTPUT':
os.system('iptables '+a+ch+d+i+' -j LOG --log-prefix \"Blocked Output IP Address '+i+' .\"')
os.system('iptables '+a+ch+d+i+' -j DROP')
#\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\SHOW MENU////////////////////////////
#************Process Menu Input
def new_num2(nu):
#'''''''''''''''''''''''
s=str(nu)
os.system('clear')
if s=='1':
file_op('white-ip')
print 'Allow List Address'
elif s=='2':
file_op('black-ip')
print 'Blocked List Address'
elif s=='3':
while True:
#os.system('clear')
print """"
1- Whithe List
2- Black List
3- Return
"""
qq=raw_input('Please Select One Item: ')
if qq=='1':
print '\n'
dd=raw_input('Input Allowed Address: ')
if len(dd)>=4:
wr_f('white-ip',dd)
#if dn==0:
raw_input('Press Any Key to Return Selection Menu...')
#else:
# dn=0
continue
else:
print '\n'
raw_input('Corroct Please Enter Address')
continue
elif qq=='2':
print '\n'
dd=raw_input('Input Black Address:')
if len(dd)>=4:
wr_f('black-ip',dd)
raw_input('Press Any Key to Return Selection Menu...')
continue
else:
print 'Please Enter Corect Address.'
elif qq=='3':
master_c()
break
else:
print 'Pleae Select Item Number 1 or 2 or 3(to Return Main Menu)'
elif s=='5':
while True:
print '''
1- Block Input IP Address Traffic
2- Block OutPut IP Address Traffic
3- Back
'''
sw=raw_input('Please Select:')
if sw=='1':
ss=raw_input( 'Enter Source IP Address:')
os.system('iptables -A INPUT -s '+ss+' -j DROP')
wr_f('black-ip',ss)
print sh_ipt()
key_p()
elif sw=='2':
ss=raw_input( 'Enter Destination IP Address:')
os.system('iptables -A OUTPUT -d '+ss+' -j DROP')
print sh_ipt('OUTPUT')
wr_f('black-ip',ss)
print key_p()
elif sw=='3':
break
elif s=='6':#Auto Detection
print 'Enabling Auto Building Blacklist...'
os.system('./auto-blk.py')
#sleep(3)
elif s=='10':
aa=raw_input( 'Are You Sure to Exit ?(Y/N) ')
if aa in ('y','Y','yes','YES'):
os.system('reset')
exit()
else:
master_c()
elif s=='9':
print '\n\n\n*******************Input Rules*******************'
pp=os.popen('iptables -L INPUT')
ep=pp.readlines()
for i in ep:
print i.rstrip()
print '\n*************************************************'
else:
print 'Sorry You Selected Incorrect Option! '
#--Menu TEXT
def master_c():
menu()
ff=raw_input("You Majesty Pleas Enter or Select Your Choice : ")
new_num2(ff)
#************************PRINT MENU
def menu():
print '''
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
1- View White List IP\'s
2- View BlackList IP\'s
3- Insert New IP in White or Black List
4- New Rule
5- Quick Rule
6- Enable Auto Building Black List
9- View Your FireWall Configuration
10- Exit
'''
while True:
#os.system('clear')
menu()
#print "You Majesty Pleas Enter or Select Your Choice : "
ff=raw_input("You Majesty Pleas Enter or Select Your Choice : ")
new_num2(ff)