5. DNS

DNS and attacks

It is the application layer, with a lot of interest by attackers because its a service designed without security measures in mind

DNS Domain Hierarchy

The name space is organized in a hierachical tree-like structure where each node is called a domain or subdomain

The root of the domain is call ROOT denoted as '.'
. (Root).com.net.edu.gov.frgoogleexampleRoot DomainTop-Level Doamins(TLDs)Second-Level Domains

DNS Zone

In DNS, a zone refers to a contiguous portion of the domain tree that is managed by a particular organization or entity. A zone typically includes a domain and its subdomains. For example, if an organization owns the domain example.com and also has subdomains such as blog.example.com and support.example.com, then all these domains and subdomains together form a zone.

Each zone in DNS is assigned management authority to an entity responsible for managing and maintaining the records within that zone. This entity could be an individual or an organization with administrative control over the domain and its subdomains. The management authority has the ability to add, modify, or delete records within their assigned zone.

The hierarchical nature of DNS allows for efficient management of domains and subdomains by delegating authority at different levels. For example, the top-level domain (TLD) authorities are responsible for managing TLDs like .com or .org. Below them, there can be second-level domain authorities responsible for managing specific domains such as example.com.

By organizing DNS according to zones, it becomes easier to manage and control different parts of the overall domain tree. It also allows for delegation of management responsibilities to different entities based on their specific needs and requirements. This helps in distributing the workload and ensuring efficient administration of DNS resources.

Zone vs Domains

Zone is a organizational concept

Authoritative Name Server

It provides the original and definitive answers to DNS queries (publish information about the zone)
Each DNS zone should have at least one authoritative name server
A master server stores the master copies of all zone records whereas a slave server uses an automatic updating mechanism to maintain an identical copy of the master records.

Attribute DNS Zone Authoritative Name Server
Definition A portion of the domain name space in the DNS where administrative responsibility has been delegated. A server that holds the definitive records for a particular DNS zone.
Represents A subset of domain names and their associated records. Server(s) that provides access to a DNS zone's data.
Multiple Instances A domain can have multiple zones, e.g., "example.com" and "sub.example.com". There can be multiple authoritative name servers for a single zone for redundancy.
Functionality Contains DNS records like A, MX, CNAME, etc. Answers DNS queries based on the zone's data, providing definitive responses.

DNS ROOT Servers

The root zone is called ROOT, there are 13 authoritative name server for the root zone

DNS Query Process

User MachineLocal DNS ServerDNS Servers onthe internetDo i know the IP of the domain?yesnoDo i know the IP of the domain?yesHere is the IPnoHere is the IPHere is the IP

Iterative query process

Local DNS ServerROOT Server.net Serverexample.net serverWhats the Ip of www.example.netidk go ask .netWhats the Ip of www.example.netidk go ask example.netWhats the Ip of www.example.netHere is the answer

DNS Response

There are 4 types of sections in a DNS response :

DNS Cache

We should not query the DNS server many times because it will overload them, we can cache the domain name and IP mapping locally so that if we want to access the domain that we have visited before, we can access directly using the local cache

Problem

As with every caching method, there is a stillness issue, in which if the ip address of the destination change due to DHCP, we will not be able to access that particular domain until the ttl for the domain expires

DNS Attacks

Example

If a user’s intention is to visit a bank’s website to do online banking ,but the IP address obtained through the DNS process is attacker’s machine, the user machine will communicate to the attacker’s web server.

Overview of the Attack Surfaces

  1. Local Cache
  2. poison the query between the local machine and the local DNS Server
  3. poison the Local DNS Server
  4. A server in the DNS hierachy

DNS Attacks on compromised machines

Spoofing DNS Replies (from LAN)

User MachineLocal DNS ServerDNS Servers onthe internetDo i know the IP of the domain?yesnoDo i know the IP of the domain?yesHere is the IPnoHere is the IPHere is the IPAttacker MachineAttacker Machine

Remote DNS Cache Poisoning Attack

  1. Targeting the Resolver: Every time a user requests a domain (like "example.com"), their device checks with a DNS resolver to get the corresponding IP address. If the resolver doesn't have this information in its cache, it queries the authoritative name servers for that domain. Once it receives the answer, it caches (stores) this information for a set period, so future queries for the same domain can be answered more quickly.
  2. Poisoning the Cache: In a cache poisoning attack, the attacker tricks the resolver into storing incorrect IP information for a domain. This can be accomplished in various ways, one common method being to send fake responses to the resolver, pretending to be from the authoritative name server. If the malicious response reaches the resolver before the legitimate one, the resolver might cache the incorrect information.
  3. Redirecting Users: Once the cache is poisoned, any user querying that resolver for the affected domain will receive the false IP address. This can lead them to malicious websites that mimic legitimate ones, potentially stealing user data, distributing malware, or causing other harm.
  4. Duration of the Attack: The malicious DNS entry remains in the cache until its Time to Live (TTL) expires or until the cache is manually cleared. This means users could be directed to the malicious site for hours, days, or even longer.

Difficulties

For remote attackers who are not on the same network as the local DNS server, spoofing replies is much more difficult, because they need to guess two random numbers used by the query packet

Cache effect: If one attempt fails, the actual reply will be cached by local DNS server; attacker need to wait for the cache to timeout for the next attempt

Kaminsky Attack

How can we keep forging replies without worrying about the cache effect?

  1. Flooding the Resolver: While the resolver waits for a response from the authoritative server, the attacker floods it with fake responses for the non-existent subdomain query, each trying a different transaction ID. Alongside the fake address for "fake.example.com", these responses also provide malicious data for the parent domain "example.com".
  2. Leveraging the Shortcomings: Once one of these fake responses is accepted (because the attacker guessed the correct transaction ID), the malicious data for "example.com" is also cached. This means users could then be redirected to a malicious version of "example.com", even though the original query was for a non-existent subdomain.
    Victim DNS ServerAttackerAttacker's DNS Serverns.attacker32.com1) What is the IP address of abcd.example.comexample.com DNS server2) Query example.com's DNS Server3)Answer of abcd.example.com3) Spoofed Answer fromexample.com with ns.attacker32.com in the authority section!note: This need tocompete with the originalreply from the example.comname server AND have the right port
Question

why is the correct ns not cached

Answer

If the resolver already had the legitimate NS records for "example.com" cached, it would directly ask them about "fake12345.example.com". However, since "fake12345.example.com" doesn't exist, the legitimate name servers would take some time to respond with a "non-existent domain" response. The attacker aims to get their fake response back to the resolver before this legitimate response. If the attacker's response is accepted, it would replace the legitimately cached NS records for "example.com" with the attacker's malicious ones.

Attacks from Malicious DNS Server

When a user visits a website, such as attacker32.com, a DNS query will eventually come to the authoritative nameserver of the attacker32.com domain. In addition to providing an IP address in the answer section of the response, DNS server can also provide information in the authority and additional sections. Attackers can use these sections to provide fraudulent information.

Those records that are out of zone will be discarded

When a user visits a website, such as attacker32.com, a DNS query will eventually come to the authoritative nameserver of the attacker32.com domain. In addition to providing an IP address in the answer section of the response, DNS server can also provide information in the authority and additional sections. Attackers can use these sections to provide fraudulent information.

Pasted image 20231003122836.png

Reply forgery in reverse DNS Lookup

Example

Given an IP address, 128.230.171.184, the DNS resolver constructs a “fake name” 184.171.230.128.in-addr.arpa and then send queries through an iterative process.
We emulate the entire reverse lookup process using @ option in the dig command.

Reverse DNS Look up

  1. Ask a root server, we get the nameservers for the in-addr.arpa.zone
  2. Ask a nameserver of the in-addr.arpa zone we get nameservers for the 128.in-addr.arpa zone
  3. Ask a naeserver of the 128.in-arpa zone. We get the nameservers for the 203.128 in-addr.arpa zone
  4. Ask a nameserver of the 230.128.in0appr.arpa zone. we get the final result
Question

Can we use the hostname obtained from reverse DNS lookup as basis for access control

Answer

If a packet comes from attacker, the reverse DNS lookup will go back to the attacker's names server
Attackers can reply with whatever hostnames they want

Protection against DNS Attacks

Using chain of trust

Protection agains DNS Cache Poisoning Attacks

DNSSEC

  1. Digital Signatures: At the heart of DNSSEC are cryptographic digital signatures created using public-key cryptography. These signatures cover DNS records, ensuring their integrity.
  2. Zone Signing Key (ZSK) & Key Signing Key (KSK):
    • Each DNS zone has two key pairs: a ZSK and a KSK.
    • The ZSK is used to sign DNS records in a zone.
    • The KSK is used to sign the ZSK, effectively acting as a safeguard for the signing key.
  3. RRSIG Records: When a zone is signed with DNSSEC, for each DNS record, a new record called an RRSIG (Resource Record Signature) is created. This RRSIG is a cryptographic signature of the original record. When a DNS resolver receives a DNS response, it also receives the RRSIG for validation purposes.
  4. DS Records: When a child zone is signed, a DS (Delegation Signer) record, which is a hash of the child zone's KSK, is placed in the parent zone. This creates a chain of trust. For example, the DS record for "example.com" is in the ".com" TLD zone.
  5. Validation: When a DNS resolver receives a query response, it:
    • Uses the public ZSK to verify the RRSIG of the DNS record.
    • Uses the public KSK to verify the RRSIG of the ZSK.
    • Checks the DS record in the parent zone (and its RRSIG), following the chain of trust up to the root.
  6. Chain of Trust: For DNSSEC to work, there needs to be a continuous chain of trust from the root zone down to the queried DNS record. The root zone's public keys are typically pre-configured in DNS resolvers, ensuring that the resolver can trust them. From there, the resolver can validate the DS record at each level of the DNS hierarchy until it reaches the final DNS record being queried.
    Pasted image 20231003125147.png

Protection using TLS/SSL

Transport Layer Security (TLS/SSL) protocol provides a solution against the cache poisoning attacks

See More -> 6. Public Key Infrastructure

Comparison

DNSSEC TLS/SSL
Based on public key technology Based on public key technology
Provides chain of trust using DNS zone hierarchy Relies on Public Key Infrastructure
Nameservers in parent zones vouch for those in child zones Certificate Authorities vouch for other computers

DNS Rebinding Attack

base on the fact that they are smart IOT devices at home
goal: interact with the target server from outside

prevent using same origin policy

the attacker can lie that all the packets come the attacker's machine is the in the same origin when doing the same origin policy check

  1. Victim Visits Malicious Website: The victim unknowingly visits a malicious website controlled by the attacker. This website serves a malicious script to the victim's browser.

  2. Initial DNS Resolution: The victim's browser resolves the domain of the malicious website. The DNS response contains an IP address that points to the attacker's server, and the browser fetches the malicious script from there.

  3. Execution of Malicious Script: The malicious script runs on the victim's browser and begins making periodic requests to the same domain. However, the script is designed to run for a long time, longer than the DNS record's Time-To-Live (TTL).

  4. DNS Rebinding: After the DNS record's TTL expires, the next time the malicious script makes a request to the domain, the browser will re-resolve the domain. This time, the attacker's DNS server returns a different IP address in its response, typically an internal IP address pointing to a private network resource, like a home router's web interface or a local server. This new IP address "rebinds" the domain to the local target.

  5. Bypassing Same-Origin Policy: Web browsers use the same-origin policy to isolate websites from each other. This policy ensures that scripts from one site cannot access data from another site. However, in a DNS rebinding attack, since both the attacker's server and the victim's local resource share the same domain (from the browser's perspective), the malicious script can bypass this policy.

  6. Unauthorized Access: Now, with the domain rebinding to a local IP, the malicious script can communicate with and potentially exploit vulnerabilities in the local target. For instance, if the target is a home router with a known vulnerability or default login credentials, the script might reconfigure it, establish a persistent backdoor, or conduct other malicious activities.

To protect against DNS rebinding attacks, several countermeasures can be applied:

Local NetworkFirewallAttackerUser machinetarget serverweb page with js codestopped due to corsstopped

Pasted image 20231003130608.png

Denial of services attacks on DNS

DoS attacks on Root Servers

Root nameservers: If the attackers can bring down the servers of the root zone, they can bring down the entire Internet. However, attack root servers is difficult:

DoS on TLD Servers

Nameservers for the TLDs are easier to attack. TLDs such as gov, com, net etc have quite resilient infrastructure against DOS attacks. But certain obscure TLDs like country-code TLDs do not have sufficient infrastructure. Due to this, the attackers can bring down the Internet of a targeted country.

Attacks on Nameservers of a Particular Domain

UltraDNS: DNS provider for many major e-commerce companies such as Amazon, Walmart, Expedia.
These big companies want to focus on their services and hence outsource the DNS protection to third party
In 2004, DOS against this provider was launched which suffered an outage for an hour.