-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain.py
359 lines (305 loc) · 12.4 KB
/
main.py
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
import sys, os, time
from Engine import arp
from Engine import sniff
from Engine import httpstrip
from Engine.functions import macFormat, ipFormat
from Engine import plugins
from Engine import dnsSpoof
from Engine import ifaces
passwdList = None
gladefile="main.glade"
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
gtk.gdk.threads_init()
class logger():
def addInfo(self,service,host,user,passwd):
passwdList.append([service, ipFormat(host), user, passwd])
class arpGui:
def __init__(self):
self.plugins = plugins.Plugins()
self.load()
self.logger = logger()
self.dnsSpoof = dnsSpoof.dnsSpoof()
self.iface = None
self.arp = None
self.sniff = False
self.httpspwn = httpstrip.run_server(self.logger)
def addlistColumn(self, Object, title, columnId):
column = gtk.TreeViewColumn(title, gtk.CellRendererText(), text=columnId)
column.set_resizable(True)
column.set_sort_column_id(columnId)
Object.append_column(column)
def scanNetwork(self,widget):
if self.arp != None:
self.networkList.clear()
result,ip1,ip2 = scanDialog().run()
if (result == gtk.RESPONSE_OK):
lenght = self.arp.scanRange(ip1,ip2)
if (lenght >=1):
for target in self.arp.network:
self.networkList.append([target.ip])
def startSniff(self,widget):
if (self.iface != None):
if (self.sniff.running == False):
self.sniff.running = True
self.lblSniffing.set_text('Pasive sniffing: ON')
try:
self.sniff.start()
except:
messageBox("couldn't start the Pasive sniffing")
else:
self.sniff.running = False
self.lblSniffing.set_text('Pasive sniffing: OFF')
self.sniff = sniff.sniff(self.iface, self.logger, self.plugins,self.dnsSpoof)
def arpPoison(self,widget):
if(self.arp != None):
if (len(self.arp.targets)>0 and self.arp.running == False):
self.arp.running = True
self.lblArp.set_text('Arp: ON')
self.arp.start()
else:
self.arp.running = False
self.lblArp.set_text('Arp: OFF')
self.arp = arp.ARP(self.iface)
def exit(self,widget):
try:
self.arp.running = False
self.sniff.running = False
if self.httpspwn.running == True:
self.httpspwn.stop()
gtk.main_quit()
exit()
except(AttributeError):
gtk.main_quit()
exit()
def httpStrip(self,widget):
if (self.httpspwn.running == False):
self.httpspwn.start()
self.lblStrip.set_text('SSLstrip: ON')
else:
self.lblStrip.set_text('SSLstrip: OFF')
self.httpspwn.stop()
self.httpspwn = httpstrip.run_server(self.logger)
def addTarget(self, treeview, iter, *args):
model=treeview.get_model()
iter = model.get_iter(iter)
ip = model.get_value(iter, 0)
self.arp.addipTarget(ip)
self.targetsList.append([ip])
self.networkList.remove(iter)
def remTarget(self, treeview, iter, *args):
model=treeview.get_model()
iter = model.get_iter(iter)
ip = model.get_value(iter, 0)
self.arp.remipTarget(ip)
self.networkList.append([ip])
self.targetsList.remove(iter)
def statusPlugin(self, treeview, iter, *args):
model=treeview.get_model()
iter = model.get_iter(iter)
enabled = model.get_value(iter, 0)
name = model.get_value(iter, 1)
if enabled == True:
self.plugins.disablePlugin(name)
self.pluginsList.set_value(iter,0,False)
else:
self.plugins.enablePlugin(name)
self.pluginsList.set_value(iter,0,True)
def dnsRun(self,widget):
if self.dnsSpoof.running == False:
self.dnsSpoof.running = True
self.lblDns.set_text('DNS spoofing: ON')
else:
self.dnsSpoof.running = False
self.lblDns.set_text('DNS spoofing: OFF')
def showAbout(self,widget):
wTree=gtk.glade.XML(gladefile,"dialog")
response = wTree.get_widget("dialog").run()
if response == gtk.RESPONSE_DELETE_EVENT or response == gtk.RESPONSE_CANCEL:
wTree.get_widget("dialog").hide()
def load(self):
global passwdList
"""
In this function we are going to display the Main
window and connect all the signals
"""
self.wTree=gtk.glade.XML(gladefile,"Main")
dic = {"on_Main_destroy" : self.exit
, "on_cmdIface_activate" : self.setIface
, "on_cmdScan_activate" : self.scanNetwork
, "on_cmdSniff_activate" : self.startSniff
, "on_cmdArp_activate" : self.arpPoison
, "on_cmdStrip_activate": self.httpStrip
, "on_lstNetwork_row_activated": self.addTarget
, "on_lstTargets_row_activated": self.remTarget
, "on_lstPlugins_row_activated": self.statusPlugin
, "on_lstDns_button_press_event": self.dnsHandler
, "on_lstPlugins_button_press_event":self.pluginHandler
, "on_cmdSpoof_activate": self.dnsRun
, "on_cmdAbout_activate": self.showAbout
, "on_lstDns_row_activated": self.remDns}
self.wTree.signal_autoconnect(dic)
#create and load the lstpassword columns
self.lstPasswords = self.wTree.get_widget("lstPasswords")
passwdList = gtk.ListStore(str, str, str, str)
self.lstPasswords.set_model(passwdList)
self.addlistColumn(self.lstPasswords,'Protocol', 0)
self.addlistColumn(self.lstPasswords,'Hostname', 1)
self.addlistColumn(self.lstPasswords,'User', 2)
self.addlistColumn(self.lstPasswords,'Password', 3)
# create and load the lstNetwork columns
self.lstNetwork = self.wTree.get_widget("lstNetwork")
self.networkList = gtk.ListStore(str)
self.lstNetwork.set_model(self.networkList)
self.addlistColumn(self.lstNetwork,'IP',0)
self.lstTargets = self.wTree.get_widget("lstTargets")
self.targetsList = gtk.ListStore(str)
self.lstTargets.set_model(self.targetsList)
self.addlistColumn(self.lstTargets,'IP',0)
#create and load the lstPlugins columns
self.lstPlugins = self.wTree.get_widget("lstPlugins")
self.pluginsList = gtk.ListStore(bool,str,str,str)
self.lstPlugins.set_model(self.pluginsList)
self.addlistColumn(self.lstPlugins,'Enabled',0)
self.addlistColumn(self.lstPlugins,'Name',1)
self.addlistColumn(self.lstPlugins,'Desc',2)
self.addlistColumn(self.lstPlugins,'Author',3)
#create and load the lstDns columns
self.lstDns = self.wTree.get_widget("lstDns")
self.dnsList = gtk.ListStore(str,str)
self.lstDns.set_model(self.dnsList)
self.addlistColumn(self.lstDns,'DNS',0)
self.addlistColumn(self.lstDns,'Ip',1)
#load the status labels
self.lblArp = self.wTree.get_widget("lblArp")
self.lblSniffing = self.wTree.get_widget("lblSniffing")
self.lblStrip = self.wTree.get_widget("lblStrip")
self.lblDns = self.wTree.get_widget("lblDns")
self.loadPlugins()
def loadPlugins(self):
for plugin in self.plugins.plugins:
self.pluginsList.append([plugin.PROPERTY['ENABLED'],plugin.PROPERTY['NAME'],plugin.PROPERTY['DESC'], plugin.PROPERTY['AUTHOR']])
def pluginHandler(self,widget,event):
if event.button == 3:
menu = gtk.Menu()
add = gtk.MenuItem("Config")
add.show()
add.connect("activate",self.configPlugin)
menu.append(add)
menu.popup(None, None, None, event.button, event.time, None)
def configPlugin(self,widget):
model=self.lstPlugins.get_model()
entry1, entry2 = self.lstPlugins.get_selection().get_selected()
name = entry1.get_value(entry2, 1)
for plugin in self.plugins.plugins:
if name == plugin.PROPERTY['NAME']:
try:
plugin.configure().run()
except:
pass
def dnsHandler(self,widget,event):
if event.button == 3:
menu = gtk.Menu()
add = gtk.MenuItem("Add")
add.show()
add.connect("activate",self.addDns)
menu.append(add)
menu.popup(None, None, None, event.button, event.time, None)
def addDns(self,widget):
result,domain,ip = dnsDialog().run()
if (result == gtk.RESPONSE_OK and len(domain)>1 and len(ip)>1):
self.dnsSpoof.addDomain(domain,ip)
self.dnsList.append([domain,ip])
def remDns(self, treeview, iter, *args):
model=treeview.get_model()
iter = model.get_iter(iter)
dns = model.get_value(iter, 0)
self.dnsSpoof.remDomain(dns)
self.dnsList.remove(iter)
def setIface(self,widget):
result,iface = ifaceDialog().run()
if (result == gtk.RESPONSE_OK and iface != None):
self.iface = iface
try:
self.arp = arp.ARP(self.iface)
self.sniff = sniff.sniff(self.iface, self.logger, self.plugins,self.dnsSpoof)
self.startSniff(None)
except(OSError):
messageBox('Error while creating the class sniff and arp on setIface function')
self.iface = None
elif iface == None:
messageBox('Error setting the iface')
class ifaceDialog:
"""This class shows the iface dialog"""
def run(self):
self.wTree = gtk.glade.XML(gladefile, "ifaceDlg")
self.dlg = self.wTree.get_widget("ifaceDlg")
self.iface = self.wTree.get_widget("cmbIface")
self.lstIface = gtk.ListStore(str)
interfaces = ifaces.getIfaces().interfaces
for iface in interfaces:
self.lstIface.append([iface.name])
#print iface.name, iface.ip , iface.hwaddr, iface.gateway, iface.gwhwaddr
self.iface.set_model(self.lstIface)
cell = gtk.CellRendererText()
self.iface.pack_start(cell)
self.iface.add_attribute(cell,'text',0)
self.iface.set_active(0)
self.result = self.dlg.run()
ifname = self.iface.get_active_text()
self.iface = None
self.dlg.destroy()
for iface in interfaces:
if iface.name == ifname:
return self.result, iface
return None,None
class scanDialog:
"""This class shows the scan dialog"""
def run(self):
self.wTree = gtk.glade.XML(gladefile, "scanDlg")
self.dlg = self.wTree.get_widget("scanDlg")
self.ip1 = self.wTree.get_widget("txtIp1")
self.ip2 = self.wTree.get_widget("txtIp2")
self.result = self.dlg.run()
self.ip1 = self.ip1.get_text()
self.ip2 = self.ip2.get_text()
self.dlg.destroy()
return self.result,self.ip1,self.ip2
class dnsDialog:
"""This class shows the DNS add dialog"""
def run(self):
self.wTree = gtk.glade.XML(gladefile, "dnsDlg")
self.dlg = self.wTree.get_widget("dnsDlg")
self.domain = self.wTree.get_widget("txtDomain")
self.ip = self.wTree.get_widget("txtIp")
self.result = self.dlg.run()
self.domain = self.domain.get_text()
self.ip = self.ip.get_text()
self.dlg.destroy()
return self.result,self.domain,self.ip
class messageBox:
def __init__(self, lblmsg = '',dlgtitle = 'Error!'):
self.wTree = gtk.glade.XML(gladefile, "msgBox")
self.dlg = self.wTree.get_widget('msgBox')
self.lblError = self.wTree.get_widget('lblError')
self.dlg.set_title(dlgtitle)
self.lblError.set_text(lblmsg)
handlers = {'on_cmdOk_clicked':self.done}
self.wTree.signal_autoconnect(handlers)
def done(self,widget):
self.dlg.destroy()
if __name__ == "__main__":
if not os.geteuid() == 0:
sys.exit("[-] ARPwner must run as root")
if (os.name == "nt"):
sys.exit("[-] ARPwner does not support windows")
arpGui()
gtk.main()