30 Mins

8. DNS & HTTP Attacks (DNSSEC, Tunneling, Smuggling)

DNS Cache Poisoning & Spoofing

DNS Cache Poisoning occurs when an attacker injects fraudulent DNS entries into a resolver's cache. By sending spoofed responses before the legitimate server responds, the attacker redirects users to malicious IP addresses. DNSSEC (Domain Name System Security Extensions) mitigates this by adding cryptographic signatures (RRSIG) to DNS records, ensuring data integrity and origin authenticity.

To verify DNS record integrity, we use dig to query for RRSIG records. If the ad (Authenticated Data) flag is present in the response, the resolver has successfully validated the signature.

Security Operator Note: Always check for the ad flag in your dig outputs; if it is missing, the resolver is not validating DNSSEC signatures.
Text
dig +dnssec voidx-academy.com A
# Look for 'ad' flag in the status header
# Check for RRSIG records in the answer section

DNS Exfiltration & Tunneling

DNS Tunneling leverages the DNS protocol to bypass firewalls. Data is encoded (typically Base64 or Hex) and prepended as a subdomain to a query (e.g., <encoded_data>.attacker.com). The authoritative name server for attacker.com then logs the query and reconstructs the data. TXT records are also used for high-bandwidth bidirectional communication.

The following Python snippet demonstrates how to encode a small data string into a simulated DNS query format.

Security Operator Note: Monitor for unusually long subdomains or a high frequency of TXT/NULL record requests to detect tunneling.
Python 3
import base64

def encode_data_for_dns(data, domain):
    encoded = base64.b64encode(data.encode()).decode().replace('=', '')
    return f'{encoded}.{domain}'

query = encode_data_for_dns('SECRET_KEY_123', 'c2.malicious.io')
print(f'Generated Query: {query}')

HTTP Request Smuggling & Header Injection

HTTP Request Smuggling occurs due to discrepancies between how front-end proxies (e.g., Load Balancers) and back-end servers interpret Content-Length (CL) and Transfer-Encoding (TE) headers. By misaligning these, an attacker can smuggle a second, hidden request that the back-end executes on behalf of the next user.

Smuggling techniques vary based on CL.TE, TE.CL, or TE.TE variations. Below is a representation of how these headers are manually injected into a raw HTTP buffer.

Security Operator Note: Use CL.TE testing by sending a request where the Content-Length is larger than the actual body, forcing the back-end to hang and await the smuggled request.
Python 3
raw_request = (b'POST / HTTP/1.1\r\n'
               b'Host: target.com\r\n'
               b'Content-Length: 45\r\n'
               b'Transfer-Encoding: chunked\r\n\r\n'
               b'0\r\n\r\n'
               b'GET /admin HTTP/1.1\r\n'
               b'Host: target.com\r\n\r\n')
print(f'Payload Byte Length: {len(raw_request)}')

Auditing Domain Security Headers

Modern web security relies heavily on HTTP response headers like Content-Security-Policy (CSP), Strict-Transport-Security (HSTS), and X-Frame-Options. Auditing these is critical to prevent XSS and Clickjacking. Below is a Python script using the requests library to audit a domain's security posture.

HeaderSecurity Purpose
CSPPrevents XSS/Data Injection
HSTSForces HTTPS connections
Security Operator Note: If HSTS is missing, the site is susceptible to SSL stripping attacks.
Python 3
def audit_headers(headers):
    critical_headers = ['Content-Security-Policy', 'Strict-Transport-Security']
    for header in critical_headers:
        print(f"{header}: {headers.get(header, 'MISSING')}")

mock_headers = {'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'}
audit_headers(mock_headers)

Knowledge Check

Ready to test your understanding of 8. DNS & HTTP Attacks (DNSSEC, Tunneling, Smuggling)?

Back