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 wikipedia.org against Google DNS to get a baseline. 

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

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 1.2.4.8.


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

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.

  • 162.125.32.9 -> Dropbox
  • 108.160.165.147 -> Dropbox
  • 67.228.102.32 -> 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 1.2.3.244. 

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

PING 1.2.4.244 (1.2.4.244): 56 data bytes
Request timeout for icmp_seq 0
 

Now let's query it. 

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

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. 

References:

1 "How Great is the Great Firewall?"  https://www.usenix.org/system/files/sec21-hoang.pdf

Comments

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

Count number of lines - 'findstr'

How do I count number of lines in a command output? findstr /r/n "^" | find /c ":" Above commands will display number of lines output by whatever command (well, nearly whatever) you specify in the front.  For example:  C:\>ping localhost | findstr /r/n "^" | find /c ":" FINDSTR: // ignored 12 This comes handy if you want to find out how many OUs you have in Active Directory: dsquery ou  -limit 0 | findstr /r/n "^" | find /c ":" How many user accounts there are: dsquery user -limit 0 | findstr /r/n "^" | find /c ":" Computers: dsquery computer -limit | findstr /r/n "^" | find /c ":"

Cisco ASA Certificate Revocation Checking

ASA supports status verification using CRLs and OCSP. CRL can be retrieved using HTTP, LDAP or SCEP. Revocation checking using CRL: Over HTTP: ciscoasa(config)# crypto ca trustpoint ASDM_TrustPoint2 ciscoasa(config-ca-trustpoint)# revocation-check crl ciscoasa(config-ca-crl)# protocol http By default ASA will use address listed in CDP extension of the certificate that is being validated.  To override default behaviour we need to add the following in the CRL configuration context. ciscoasa(config-ca-crl)# policy static ciscoasa(config-ca-crl)# url 1 http://cdpurl.kp.local/crl.crl Over LDAP: Certificate I'm using for this lab, doesn't have LDAP address in its CDP extension. Therefore I'm using "policy static"  to specify LDAP URL where CRL can be retrieved.  ciscoasa(config)# crypto ca trustpoint ASDM_TrustPoint2 ciscoasa(config-ca-trustpoint)# revocation-check crl ciscoasa(config-ca-trustpoint)# crl configure ciscoasa