Python打造ARP欺骗检测软件:局域网安全卫士

这篇文章将带您使用Python和强大的网络库Scapy开发一款功能齐全的ARP欺骗检测软件。该软件不仅可以检测ARP欺骗攻击,还具备用户登录注册、ICMP Flood、TCP攻击检测、局域网主机扫描和攻击源定位等功能,为您打造坚实的网络安全防线。

核心功能:

  • 用户登录注册:确保软件的安全性,防止未经授权的访问。
  • ICMP Flood攻击检测:实时监控网络流量,识别并预警ICMP Flood攻击。
  • TCP攻击检测:有效识别针对TCP协议的攻击行为,例如SYN Flood。
  • ARP欺骗攻击检测:精准检测ARP欺骗攻击,保护您的网络免受中间人攻击。
  • 扫描局域网主机:快速扫描并识别局域网内的活动主机,为网络管理提供便利。
  • 检测攻击源:精确定位攻击源的IP地址和MAC地址,帮助您快速采取应对措施。

代码示例:

import os
import time
import sys
import platform
from scapy.all import *
from tkinter import *
from tkinter import messagebox

# 设置界面
root = Tk()
root.title('ARP欺骗检测软件')
root.geometry('400x300')

# 注册界面
def register():
    register_window = Toplevel(root)
    register_window.title('注册')
    register_window.geometry('300x200')
    Label(register_window, text='请输入用户名:').pack()
    username = Entry(register_window)
    username.pack()
    Label(register_window, text='请输入密码:').pack()
    password = Entry(register_window, show='*')
    password.pack()
    def register_confirm():
        with open('user.txt', 'a') as f:
            f.write(username.get() + ' ' + password.get() + '
')
        messagebox.showinfo('提示', '注册成功!')
        register_window.destroy()
    Button(register_window, text='确认', command=register_confirm).pack()

# 登录界面
def login():
    login_window = Toplevel(root)
    login_window.title('登录')
    login_window.geometry('300x200')
    Label(login_window, text='请输入用户名:').pack()
    username = Entry(login_window)
    username.pack()
    Label(login_window, text='请输入密码:').pack()
    password = Entry(login_window, show='*')
    password.pack()
    def login_confirm():
        with open('user.txt', 'r') as f:
            users = f.readlines()
            for user in users:
                if user.split()[0] == username.get() and user.split()[1] == password.get():
                    messagebox.showinfo('提示', '登录成功!')
                    login_window.destroy()
                    return
            messagebox.showerror('错误', '用户名或密码错误!')
    Button(login_window, text='确认', command=login_confirm).pack()

# ICMP flood攻击检测
def icmp_flood():
    sniff_filter = 'icmp'
    sniff_timeout = 10
    sniff_count = 0
    sniff_packets = sniff(filter=sniff_filter, timeout=sniff_timeout)
    for packet in sniff_packets:
        sniff_count += 1
    if sniff_count > 100:
        messagebox.showwarning('警告', '检测到ICMP flood攻击!')
    else:
        messagebox.showinfo('提示', '未检测到ICMP flood攻击!')

# TCP攻击检测
def tcp_attack():
    sniff_filter = 'tcp'
    sniff_timeout = 10
    sniff_count = 0
    sniff_packets = sniff(filter=sniff_filter, timeout=sniff_timeout)
    for packet in sniff_packets:
        sniff_count += 1
    if sniff_count > 100:
        messagebox.showwarning('警告', '检测到TCP攻击!')
    else:
        messagebox.showinfo('提示', '未检测到TCP攻击!')

# ARP欺骗攻击检测
def arp_spoofing():
    sniff_filter = 'arp'
    sniff_timeout = 10
    sniff_count = 0
    sniff_packets = sniff(filter=sniff_filter, timeout=sniff_timeout)
    for packet in sniff_packets:
        sniff_count += 1
    if sniff_count > 100:
        messagebox.showwarning('警告', '检测到ARP欺骗攻击!')
    else:
        messagebox.showinfo('提示', '未检测到ARP欺骗攻击!')

# 扫描局域网主机
def scan_network():
    network = '192.168.1.0/24'
    arp_request = ARP(pdst=network)
    broadcast = Ether(dst='ff:ff:ff:ff:ff:ff')
    arp_broadcast = broadcast/arp_request
    answered_list = srp(arp_broadcast, timeout=1, verbose=False)[0]
    clients = []
    for element in answered_list:
        client = {'ip': element[1].psrc, 'mac': element[1].hwsrc}
        clients.append(client)
    with open('clients.txt', 'w') as f:
        for client in clients:
            f.write(client['ip'] + ' ' + client['mac'] + '
')
    messagebox.showinfo('提示', '扫描完成!')

# 检测攻击源
def detect_attack():
    with open('clients.txt', 'r') as f:
        clients = f.readlines()
        for client in clients:
            ip = client.split()[0]
            mac = client.split()[1]
            sniff_filter = 'arp and src host ' + ip
            sniff_timeout = 10
            sniff_count = 0
            sniff_packets = sniff(filter=sniff_filter, timeout=sniff_timeout)
            for packet in sniff_packets:
                sniff_count += 1
            if sniff_count > 100:
                messagebox.showwarning('警告', '检测到攻击源IP地址为' + ip + ',MAC地址为' + mac + '!')
            else:
                messagebox.showinfo('提示', '未检测到攻击源IP地址为' + ip + ',MAC地址为' + mac + '的攻击!')

# 创建用户和客户端记录文件
if not os.path.exists('user.txt'):
    open('user.txt', 'w').close()
if not os.path.exists('clients.txt'):
    open('clients.txt', 'w').close()

# 创建按钮
register_button = Button(root, text='注册', command=register)
register_button.pack(pady=10)
login_button = Button(root, text='登录', command=login)
login_button.pack(pady=10)
icmp_flood_button = Button(root, text='检测ICMP flood攻击', command=icmp_flood)
icmp_flood_button.pack(pady=10)
tcp_attack_button = Button(root, text='检测TCP攻击', command=tcp_attack)
tcp_attack_button.pack(pady=10)
arp_spoofing_button = Button(root, text='检测ARP欺骗攻击', command=arp_spoofing)
arp_spoofing_button.pack(pady=10)
scan_network_button = Button(root, text='扫描局域网主机', command=scan_network)
scan_network_button.pack(pady=10)
detect_attack_button = Button(root, text='检测攻击源', command=detect_attack)
detect_attack_button.pack(pady=10)

root.mainloop()

使用说明:

  1. 确保您已安装Python和Scapy库。
  2. 运行代码,将弹出一个图形界面。
  3. 点击'注册'按钮创建一个新用户。
  4. 使用您的用户名和密码'登录'。
  5. 点击相应按钮即可执行各种网络安全检测功能。

注意:

  • 本软件仅供学习和研究使用,请勿用于非法用途。
  • 检测结果仅供参考,实际情况可能有所不同。

希望这款ARP欺骗检测软件能够帮助您更好地保护您的网络安全!

Python打造ARP欺骗检测软件:局域网安全卫士

原文地址: https://www.cveoy.top/t/topic/jn1g 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录