基于Windows的ARP攻击检测防护软件的设计模块包括:多种ARP攻击类型检测并且遭受攻击时输出攻击类型网络拓扑图和日志查看扫描和保存局域网内活动主机的IP地址和MAC地址记录攻击源的IP地址和MAC 地址在网页上实现可视化能够查看网络流量。用python基本代码详细实现如何有机结合起来
该软件可以基于Python语言实现,主要使用以下模块:
- scapy模块:用于网络数据包的构建、发送和解析。
- tkinter模块:用于图形界面的设计和实现。
- sqlite3模块:用于数据库的操作,保存局域网内活动主机的IP地址和MAC地址。
下面详细介绍各个模块的实现:
- ARP攻击检测模块
该模块主要用于检测多种ARP攻击类型,包括ARP欺骗、ARP投毒、ARP中间人攻击等,并在遭受攻击时输出攻击类型。具体实现过程如下:
from scapy.all import *
def arp_attack_detect(pkt):
if pkt[ARP].op == 1: # ARP请求
if pkt[ARP].psrc == pkt[ARP].pdst: # 检测自己的IP地址是否被伪造
print("ARP欺骗攻击!")
elif pkt[ARP].hwsrc != pkt[ARP].hwdst: # 检测MAC地址是否被伪造
print("ARP投毒攻击!")
elif pkt[ARP].op == 2: # ARP响应
if pkt[ARP].psrc != pkt[ARP].pdst: # 检测是否是ARP中间人攻击
print("ARP中间人攻击!")
sniff(filter="arp", prn=arp_attack_detect, store=0) # 监听ARP数据包
- 网络拓扑图和日志查看模块
该模块主要用于显示网络拓扑图和日志信息,可以使用tkinter模块进行图形界面的设计和实现。具体实现过程如下:
import tkinter as tk
from tkinter import ttk
class NetworkTopology:
def __init__(self, master):
self.master = master
self.master.title("网络拓扑图")
self.master.geometry("800x600")
self.tree = ttk.Treeview(self.master)
self.tree.pack(fill="both", expand=True)
self.tree["columns"] = ("IP地址", "MAC地址")
self.tree.column("#0", width=200, minwidth=200)
self.tree.column("IP地址", width=200, minwidth=200)
self.tree.column("MAC地址", width=200, minwidth=200)
self.tree.heading("#0", text="主机名", anchor=tk.W)
self.tree.heading("IP地址", text="IP地址", anchor=tk.W)
self.tree.heading("MAC地址", text="MAC地址", anchor=tk.W)
self.log = tk.Text(self.master)
self.log.pack(fill="both", expand=True)
self.log.insert(tk.END, "日志信息\n")
def add_host(self, name, ip, mac):
self.tree.insert("", tk.END, text=name, values=(ip, mac))
def add_log(self, log):
self.log.insert(tk.END, log + "\n")
- 局域网主机扫描和保存模块
该模块主要用于扫描局域网内的活动主机,并保存其IP地址和MAC地址到数据库中。可以使用sqlite3模块进行数据库的操作。具体实现过程如下:
import sqlite3
def scan_hosts():
hosts = {}
ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.0/24"), timeout=2, verbose=False)
for snd, rcv in ans:
name = rcv.sprintf("%Ether.src%").replace(":", "-")
ip = rcv.sprintf("%ARP.psrc%")
mac = rcv.sprintf("%Ether.src%")
hosts[name] = (ip, mac)
return hosts
def save_hosts(hosts):
conn = sqlite3.connect("hosts.db")
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS hosts (name TEXT, ip TEXT, mac TEXT)")
for name, (ip, mac) in hosts.items():
c.execute("INSERT INTO hosts VALUES (?, ?, ?)", (name, ip, mac))
conn.commit()
conn.close()
- 攻击源IP地址和MAC地址记录模块
该模块主要用于记录攻击源的IP地址和MAC地址,可以使用sqlite3模块进行数据库的操作。具体实现过程如下:
def record_attack_source(ip, mac):
conn = sqlite3.connect("attacks.db")
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS attacks (ip TEXT, mac TEXT)")
c.execute("INSERT INTO attacks VALUES (?, ?)", (ip, mac))
conn.commit()
conn.close()
- 可视化模块
该模块主要用于在网页上实现可视化,可以使用Flask框架进行Web应用的开发。具体实现过程如下:
from flask import Flask, render_template
import sqlite3
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/hosts")
def hosts():
conn = sqlite3.connect("hosts.db")
c = conn.cursor()
c.execute("SELECT * FROM hosts")
hosts = c.fetchall()
conn.close()
return render_template("hosts.html", hosts=hosts)
@app.route("/attacks")
def attacks():
conn = sqlite3.connect("attacks.db")
c = conn.cursor()
c.execute("SELECT * FROM attacks")
attacks = c.fetchall()
conn.close()
return render_template("attacks.html", attacks=attacks)
if __name__ == "__main__":
app.run()
其中,index.html、hosts.html和attacks.html是网页模板文件,用于显示主页、主机列表和攻击源列表。可以使用Bootstrap框架进行网页样式的设计和实现
原文地址: https://www.cveoy.top/t/topic/fiB6 著作权归作者所有。请勿转载和采集!