VAITP Dataset

← Back to the dataset

CVE-2008-4126

PyDNS (python-dns) <2.3.1-5 in Debian: DNS spoofing, no random source ports, incomplete fix

  • CVSS 6.4
  • CWE-16
  • Cryptographic
  • Remote

PyDNS (aka python-dns) before 2.3.1-5 in Debian GNU/Linux does not use random source ports for DNS requests and does not use random transaction IDs for DNS retries, which makes it easier for remote attackers to spoof DNS responses, a different vulnerability than CVE-2008-1447. NOTE: this vulnerability exists because of an incomplete fix for CVE-2008-4099.

CVSS base score
6.4
Published
2008-09-18
OWASP
A06 Vulnerable and Outdated Components
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Cryptographic
Subcategory
Inadequate random number generation
Accessibility scope
Remote
Impact
Denial of Service (DoS)
Fixed by upgrading
Yes

Solution

Update PyDNS (python-dns) to version 2.3.1-5 or higher.

Vulnerable code sample

import socket
import struct

class DNS:
    def __init__(self, server='8.8.8.8'):
        self.server = server
        self.port = 53
        self.transaction_id = 0

    def query(self, domain):
        query = struct.pack('>H', self.transaction_id) + b'\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00' + domain.encode() + b'\x00\x00\x01\x00\x01'
        
        with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
            sock.sendto(query, (self.server, self.port))
            sock.settimeout(5)
            try:
                response, _ = sock.recvfrom(512)
                return response
            except socket.timeout:
                return None

dns_client = DNS()
response = dns_client.query('example.com')
print(response)

Patched code sample

import random
import socket
import struct

class DNS:
    def __init__(self, server='8.8.8.8'):
        self.server = server

    def random_port(self):
        return random.randint(1024, 65535)

    def random_transaction_id(self):
        return random.randint(0, 65535)

    def query(self, domain):
        transaction_id = self.random_transaction_id()
        port = self.random_port()
        
        query = struct.pack('>H', transaction_id) + b'\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00' + domain.encode() + b'\x00\x00\x01\x00\x01'
        
        with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
            sock.bind(('', port))
            sock.sendto(query, (self.server, 53))
            sock.settimeout(5)
            try:
                response, _ = sock.recvfrom(512)
                return response
            except socket.timeout:
                return None

dns_client = DNS()
response = dns_client.query('example.com')
print(response)

Cite this entry

@misc{vaitp:cve20084126,
  title        = {{PyDNS (python-dns) <2.3.1-5 in Debian: DNS spoofing, no random source ports, incomplete fix}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2008},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2008-4126},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2008-4126/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::