Skip to main content

DNS injection attack

DNS injection is a type of a DNS poisoning attack in which, a network traffic monitoring device injects fake DNS responses.

DNS Injection attack
When a monitoring device detects a DNS query for a censored domain, it forges a fake response and sends it to the client.  This attack can be implemented by an on-path or an off-path device. This technique is commonly used by state actors to implement country based censorship. 

We'll use The Great Firewall of China (GFW) to demonstrate this attack in practice.

 Let's query against Google DNS to get a baseline. 

dig @
; <<>> DiG 9.10.6 <<>> @
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61120
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
; EDNS: version: 0, flags:; udp: 512
;            IN    A
;; ANSWER SECTION:        234    IN    A

We can confirm in a WHOIS database that this IP address in fact belong to Wikimedia Foundation. 

Let's run the same query against a DNS server in China. We'll use DNS server with address

dig @
; <<>> DiG 9.10.6 <<>> @
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21972
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;            IN    A
;; ANSWER SECTION:        170    IN    A

Checking WHOIS data we see that this IP address doesn't belong to Wikimedia. Instead it belongs to Dropbox. 

Examining the network traffic, we see that in fact we received not one but three responses.

  • -> Dropbox
  • -> Dropbox
  • -> Softlayer

 None of them belongs to Wikipedia. 

To further demonstrate that this is a network based attack, we try to send a DNS query to an IP address that is not a DNS server and it's not even in use. We'll test this against 

First let's ping it to make sure there's nothing there.

PING ( 56 data bytes
Request timeout for icmp_seq 0

Now let's query it. 

 dig @
; <<>> DiG 9.10.6 <<>> @
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27430
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;            IN    A
;; ANSWER SECTION:        150    IN    A

The response gets injected by the injector. 

Observant reader will notice that this time we've received two instead of three responses. We will cover why that is the case in a post dedicated to the Great Firewall of China DNS blocking.

IP addresses in injected responses

The fake response can contain anything the attacker chooses.These can be: 

  • Publicly routable IP addresses blocked at the network level (for example BGP black-holed) or not serving any conten
  • IP addresses of specific block pages
  • Local host address
  • Private IP addresses (non-internet routable)
  • DNS error for example NXDOMAIN

The Great Firewall of China in its forged responses returns IP addresses from IP ranges owned by US companies such as Dropbox, Facebook, Twitter, Softlayer. This behaviour is specific to the GFW[ref 1] . 

For example in Indonesia or Korea forged responses contain IP address that redirect users to block page. 


1 "How Great is the Great Firewall?"


Popular posts from this blog

x.509 Certificates - Critical vs non-critical extensions

Extensions are used to associate additional information with the user or the key.  Each certificate extension has three attributes - extnID, critical, extnValue extnID - Extension ID - an OID that specifies the format and definitions of the extension critical - Critical flag - Boolean value extnValue - Extension value  Criticality flag specifies whether the information in an extension is important. If an application doesn't recognize the extension marked as critical, the certificate cannot be accepted. If an extension is not marked as critical (critical value False) it can be ignored by an application. In Windows, critical extensions are marked with a yellow exclamation mark,  View certificate extensions using OpenSSL: # openssl x509 -inform pem -in cert.pem -text -noout (output abbreviated)         X509v3 extensions:             X509v3 Key Usage: critical                 Digital Signature, Key Encipherment             X509v3 Subject Key Identifier

DNS response and error types

In this post we explore common DNS response codes. We will cover the following responses: NOERROR SERVFAIL NXDOMAIN NODATA REFUSED Throughout article we’ll refer to the following RFCs: RFC 1034 - DOMAIN NAMES - CONCEPTS AND FACILITIES RFC 2308 - Negative Caching of DNS Queries (DNS NCACHE) RFC 2136 - Dynamic Updates in the Domain Name System (DNS UPDATE) RFC 8914 - Extended DNS Errors Response Codes - RCODEs The DNS RCODES are best defined in RFC2316 .  They signify what type of response was sent by the server. “RCODE   Response code - this four bit field is undefined in requests and set in responses.”   The table below shows the summary of the currently defined RCODEs. Mnemonic Val Description NOERROR 0 No error condition.

DNS blocking in Indonesia

DNS based censorship and domain blocking in Indonesia is very inconsistent among ISPs. There’s a government mandated black list which the ISPs operating in the country should enforce. However, Indonesia lacks centralised internet infrastructure and has many separate ISPs. In addition, the Indonesian government granted ISPs the authority to block content at their own discretion. All of this leads to a very inconsistent DNS blocking in Indonesia. Official DNS domain blacklist in Indonesia The Government mandated DNS blacklist is published in a redacted form and can be downloaded here: . This is where the blocked domains get redirected to. We can search the database and check if a domain is blocked. In the screenshot below we can see that a popular cryptocurrency exchange is blocked (Ada) and that is not (Tidak Ada) - thanks to Google Translate. Examples of blocked DNS queries dig @ ;; global options: +cmd ;; Got