Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.uix.boxlayout import BoxLayout
- from kivy.uix.label import Label
- from kivy.uix.button import Button
- from kivy.uix.textinput import TextInput
- from kivy.lang import Builder
- from kivy.app import App
- from kivy.uix.image import Image
- from scapy.all import *
- from kivy.uix.scrollview import ScrollView
- from kivy.uix.screenmanager import ScreenManager, Screen
- from kivy.uix.switch import Switch #TUT 7
- from kivy.uix.popup import Popup
- from kivy.clock import Clock
- from subprocess import check_output
- import threading
- import socket
- import re
- Builder.load_string('''
- <MITMs1>:
- BoxLayout:
- canvas:
- Rectangle:
- source: 'images/kapy-bg3.jpg'
- size: self.size
- pos: self.pos
- BoxLayout:
- id: client_box
- orientation: 'vertical'
- size_hint: 0.5, 1
- spacing: 10
- Image:
- ## Tut 7
- source: 'zips/pyspin.zip'
- anim_delay: 1/80
- allow_stretch: False
- pos_hint: {'x': -.3}
- Label:
- id: device_lbl
- markup: True
- size_hint: 1, 1
- BoxLayout:
- TextInput:
- id: iface_name
- size_hint: .3, 0.2
- text: 'wlan2'
- multiline: False
- Switch:
- size_hint: .3, .1
- BoxLayout:
- Button:
- size_hint: .5, .4
- text: '[color=00ff00]Run ifconfig[/color]'
- on_release: root.run_ifconfig()
- markup: True
- background_normal: 'images/buttonBG.png'
- Button:
- id: scnLAN
- size_hint: .5, .4
- text: '[color=00ff00]ARP Scan[/color]'
- on_release: root.ARPscan()
- background_normal: 'images/buttonBG.png'
- disabled: True
- markup: True
- Button:
- id: save_btn
- text: '[color=00ff00]Save Results[/color]'
- size_hint: .5, .4
- background_normal: 'images/buttonBG.png'
- markup: True
- disabled: True
- on_press: root.saveResults()
- ScrollView:
- size_hint: 0.5, 1
- do_scroll_x: False
- bar_width: 10
- BoxLayout:
- id: nodes
- orientation: 'vertical'
- size_hint: (1, None)
- <MITMs2>:
- BoxLayout:
- canvas:
- Rectangle:
- source: 'images/kapy-bg3.jpg'
- size: self.size
- pos: self.pos
- BoxLayout:
- orientation: 'vertical'
- BoxLayout:
- orientation: 'vertical'
- id: target_box
- BoxLayout:
- Button:
- text: '[color=00ff00]Back[/color]'
- size_hint: 1, .2
- on_press: root.main_screen()
- markup: True
- background_normal: 'images/buttonBG.png'
- Button:
- text: '[color=00ff00]Port Scan[/color]'
- size_hint: 1, .2
- markup: True
- background_normal: 'images/buttonBG.png'
- on_press: root.portScan()
- Button:
- text: '[color=00ff00]Save Results[/color]'
- size_hint: 1, .2
- on_press: root.main_screen()
- markup: True
- background_normal: 'images/buttonBG.png'
- BoxLayout:
- orientation: 'vertical'
- canvas:
- Rectangle:
- source: 'images/portBG.png'
- pos: self.pos
- size: self.size
- Label:
- id: portscanResults
- text: '[color=00ff00]Port Scan[/color]'
- markup: True
- ''')
- class MITMs1(Screen):
- def __init__(self, **kwargs):
- super(MITMs1, self).__init__(**kwargs)
- self.save_btn = self.ids['save_btn']
- self.iface_name = self.ids['iface_name']
- self.device_lbl = self.ids['device_lbl']
- self.client_box = self.ids['client_box']
- self.nodes = self.ids['nodes']
- self.my_ip = '' #Empty string # TUT 5
- self.scnLAN = self.ids['scnLAN']
- self.node_list = [] #list to adjust scrollview size, append nodes
- MITMs1.targetd = {} # Dictionary that will hold our target IP, MAC and hostname
- self.logos = [['Apple', 'iphone', 'mac', 'ipad'],
- ['Android', 'nexus'],
- ['Windows', 'user', '192.168.10.1', 'vista', 'xp'],
- ['Gateway', '192.168.10.254', 'netgear'],
- ['Linux', 'apache', 'ubuntu']]
- def run_ifconfig(self):
- self.scnLAN.disabled = False
- try:
- self.ifconfig = subprocess.check_output(['ifconfig', self.iface_name.text]) #Add wlan0 for interface.
- self.iface, self.my_ip,self.MAC, self.Bcast, self.Nmask, self.ipv6 = (self.ifconfig.split()[i] for i in (0,6,4,7,8,11))# TUT 4
- self.device_lbl.text = ('[color=00ff00][i][b]My Device[/b][/i][/color]'+ '\n\n' + 'Interface: '# TUT 4
- + '[color=00ff00][i]{0}[/i][/color] '.format(self.iface) + '\n\n' + 'IP: '# TUT 4
- + '[color=00ff00][i]{0}[/i][/color] '.format(self.my_ip[5:]) + '\n\n' + 'MAC: '# TUT 4
- + '[color=00ff00][i]{0}[/i][/color] '.format(self.MAC) + '\n\n' + 'Bcast: '# TUT 4
- + '[color=00ff00][i]{0}[/i][/color] '.format(self.Bcast[6:]) + '\n\n' + 'Nmask: '# TUT 4
- + '[color=00ff00][i]{0}[/i][/color] '.format(self.Nmask[5:]) + '\n\n' + 'IPv6: '# TUT 4
- + '[color=00ff00][i]{0}[/i][/color] '.format(self.ipv6 ))# TUT 4
- except:
- pass
- def ARPscan(self): #TUT 7
- '''Called to scan the LAN'''
- self.save_btn.disabled = False
- self.nodes.clear_widgets()
- self.node_list = [] #make sure list is empty
- try:
- for ip in xrange(255):
- scanNode = ARPthread(ip,self.nodes,self.iface_name.text,
- self.node_list,self.logos, MITMs1.targetd) # Create a thread
- scanNode.start() # Start the thread
- print 'Started thread: %s ' %ip
- except:
- pass
- def timeDate(self):
- now = time.localtime(time.time())
- return time.asctime(now) # Get the date time
- def saveResults(self):
- self.box = BoxLayout(orientation='vertical')
- self.tinput = TextInput(text='') # Name the file
- self.svebtn = Button(text='Save File!', on_press=self.saveFile) # Button to save file
- self.lbl = Label(text='') # Label to display to the user the file is saved
- self.box.add_widget(self.tinput)
- self.box.add_widget(self.svebtn)
- self.box.add_widget(self.lbl)
- # Create the popup #
- self.pop = Popup(content=self.box, title='Save Scan Results', size_hint=(1, .5))
- self.pop.open()
- def saveFile(self, i):
- f = open(self.tinput.text + '.txt', 'a')
- f.write('[] LAN Scan [] \n\n' + self.timeDate() + '\n\n' +
- '%s Hosts Up!\n\n' %len(self.node_list))
- for i in self.node_list:
- f.write('IP: ' + i.psrc + '\n' + 'MAC: ' + i.hwsrc + '\n\n')
- f.close() # Close the file
- self.lbl.text = 'File Saved!'
- def change_screen(self):
- sm.current = 'MITMs2'
- MITMs1.target = self.text # Take the text from the button pressed [NODE]
- MITMs1.logo = self.background_normal # Take the logo assigned to identify the node
- def load_target(self):
- '''This will be called by the on_enter method of screen 2'''
- self.target_box.clear_widgets() # Clear the box first before adding info
- if MITMs1.logo == 'images/gatewayNode.png':
- self.target_box.add_widget(Image(source='zips/gateSpin.zip', anime_delay=1/30,
- size_hint=(1,.5), pos_hint={'x': -.3}))
- elif MITMs1.logo == 'images/appleNode.png':
- self.target_box.add_widget(Image(source='zips/appleSpin.zip', anime_delay=1/30,
- size_hint=(1,.5), pos_hint={'x': -.3}))
- if MITMs1.logo == 'images/windowsNode.png':
- self.target_box.add_widget(Image(source='zips/winSpin.zip', anime_delay=1/30,
- size_hint=(1,.5), pos_hint={'x': -.3}))
- if MITMs1.logo == 'images/linuxNode.png':
- self.target_box.add_widget(Image(source='zips/linuxSpin.zip', anime_delay=1/30,
- size_hint=(1,.5), pos_hint={'x': -.3}))
- if MITMs1.logo == 'images/androidNode.png':
- self.target_box.add_widget(Image(source='zips/andSpin.zip', anime_delay=1/30,
- size_hint=(1,.5), pos_hint={'x': -.3}))
- elif MITMs1.logo == 'images/unknownNode.png':
- self.target_box.add_widget(Image(source='zips/unkSpin.zip', anime_delay=1/30,
- size_hint=(1,.5), pos_hint={'x': -.3}))
- for i in MITMs1.targetd:
- if re.findall('\\b'+i+'\\b', MITMs1.target):
- self.target_box.add_widget(Label(text='[color=00ff00]IP: {0}[/color]'.format(MITMs1.targetd[i][0]) +
- '\n[color=00ff00]MAC: {0}[/color]'.format(MITMs1.targetd[i][1]) +
- '\n[color=00ff00]{0}[/color]'.format(MITMs1.targetd[i][2]),
- markup=True, size_hint=(1,1), pos_hint={'x':-.2}))
- class ARPthread(threading.Thread):
- '''Threaded ARP scan'''
- def __init__(self,ip,nodes,iface,node_list,logos, targetd):
- self.targetd = targetd
- self.logos = logos
- self.node_list = node_list
- self.ip = ip # host to scan
- self.nodes = nodes # the scrollview box
- self.iface = iface # the text from the textinput for the NIC
- threading.Thread.__init__(self)
- try:
- def run(self):
- arprequest = Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst='192.168.10.'+str(self.ip), hwdst='ff:ff:ff:ff:ff:ff')
- arpresponse = srp1(arprequest, timeout=2, verbose=0, iface=self.iface)
- if arpresponse:
- self.node_list.append(arpresponse) #add node to the list
- try:
- MITMs1.hostname = socket.gethostbyaddr(arpresponse.psrc)[0]
- except:
- pass
- MITMs1.targetd[arpresponse.psrc] = arpresponse.psrc, arpresponse.hwsrc, MITMs1.hostname
- choose_button = ''
- for i in self.logos:
- for make in i:
- if make.lower() in MITMs1.hostname:
- choose_button = i[0] #Assign the first item.
- if choose_button == 'Android':
- self.nodes.add_widget(Button(text='[color=00ff00][i]Host is up\n{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][2])+
- '\n[color=00ff00]IP: [i]{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][0])+'\n' +
- '[color=00ff00]MAC: {0}[/color]'.format(MITMs1.targetd[arpresponse.psrc][1] + '\n' ), markup=True, font_size='15sp',
- height='150sp', background_normal='images/androidNode.png', valign='middle', halign='center',
- on_press=MITMs1.change_screen))
- elif choose_button == 'Apple':
- self.nodes.add_widget(Button(text='[color=00ff00][i]Host is up\n{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][2])+
- '\n[color=00ff00]IP: [i]{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][0])+'\n' +
- '[color=00ff00]MAC: {0}[/color]'.format(MITMs1.targetd[arpresponse.psrc][1] + '\n' ), markup=True, font_size='15sp',
- height='150sp', background_normal='images/appleNode.png', valign='middle', halign='center',
- on_press=MITMs1.change_screen))
- elif choose_button == 'Windows':
- self.nodes.add_widget(Button(text='[color=00ff00][i]Host is up\n{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][2])+
- '\n[color=00ff00]IP: [i]{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][0])+'\n' +
- '[color=00ff00]MAC: {0}[/color]'.format(MITMs1.targetd[arpresponse.psrc][1] + '\n' ), markup=True, font_size='15sp',
- height='150sp', background_normal='images/windowsNode.png', valign='middle', halign='center',
- on_press=MITMs1.change_screen))
- elif choose_button == 'Linux':
- self.nodes.add_widget(Button(text='[color=00ff00][i]Host is up\n{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][2])+
- '\n[color=00ff00]IP: [i]{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][0])+'\n' +
- '[color=00ff00]MAC: {0}[/color]'.format(MITMs1.targetd[arpresponse.psrc][1] + '\n' ), markup=True, font_size='15sp',
- height='150sp', background_normal='images/linuxNode.png', valign='middle', halign='center',
- on_press=MITMs1.change_screen))
- elif choose_button == 'Gateway':
- self.nodes.add_widget(Button(text='[color=00ff00][i]Host is up\n{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][2])+
- '\n[color=00ff00]IP: [i]{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][0])+'\n' +
- '[color=00ff00]MAC: {0}[/color]'.format(MITMs1.targetd[arpresponse.psrc][1] + '\n' ), markup=True, font_size='15sp',
- height='150sp', background_normal='images/gatewayNode.png', valign='middle', halign='center',
- on_press=MITMs1.change_screen))
- if choose_button == '':
- self.nodes.add_widget(Button(text='[color=00ff00][i]Host is up\n{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][2])+
- '\n[color=00ff00]IP: [i]{0}[/i][/color]'.format(MITMs1.targetd[arpresponse.psrc][0])+'\n' +
- '[color=00ff00]MAC: {0}[/color]'.format(MITMs1.targetd[arpresponse.psrc][1] + '\n' ), markup=True, font_size='15sp',
- height='150sp', background_normal='images/unknownNode.png', valign='middle', halign='center',
- on_press=MITMs1.change_screen))
- self.nodes.height = len(self.node_list * 150)
- except:
- pass
- class MITMs2(Screen):
- def __init__(self, **kwargs):
- super(MITMs2, self).__init__(**kwargs)
- self.target_box = self.ids['target_box']
- self.bind(on_enter=MITMs1.load_target)
- self.portscanResults = self.ids['portscanResults']
- def portScan(self):
- self.ports_list = []
- for i in MITMs1.targetd:
- if i in MITMs1.target:
- for port in xrange(5):
- pkt = sr1(IP(dst=MITMs1.targetd[i][0])/TCP(sport=123, dport=78+port, flags='S'), timeout=1)
- try:
- if pkt.getlayer(TCP).flags == 18L:
- self.ports_list.append(pkt.getlayer(TCP).sport)
- print 'Port is OPeN!'
- elif pkt.getlayer(TCP).flags == 20L:
- print 'Port is closed'
- except:
- pass
- if len(self.ports_list) > 0:
- for i in self.ports_list:
- self.portscanResults.text = '[color=00ff00]Port {0} is open![/color]'.format(str(i))
- else:
- self.portscanResults.text = '[color=00ff00] No open ports found [/color]'
- def main_screen(self):
- sm.current = 'MITMs1'
- sm = ScreenManager()
- sm.add_widget(MITMs1(name='MITMs1'))
- sm.add_widget(MITMs2(name='MITMs2'))
- class MITMtool(App):
- def build(self):
- return sm #Return the Screen (Screen 1)
- if __name__=='__main__':
- MITMtool().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement