Labs / Board Reviews & Technical Insights

An ESP32 Can Work as a DNS Server: NCSI Spoofing and DNS Hijacking in MicroPython

Author: Zhuang Xiaoman · Source: Freak Embedded on WeChat, published 2026-03-29 · License: CC BY 4.0

Contents

Have you ever run into these problems?

Today we are sharing the microdns library, written by a developer: it can create a Wi-Fi hotspot, listens on the standard port 53, supports wildcard resolution, and even comes with a web admin page! Best of all, it is pure MicroPython, so beginners can read it and get it running.

The microdns package page on the MicroPython package index

Project introduction

This small project is at version 0.0.1, and its core features are already complete:

Quick start

All the files are already organised here. Follow the steps and even a beginner can get it working on the first try. You need:

First install the microdns package with mpremote (you can also transfer the files directly). The library is on upypi: https://upypi.net/

Search for: microdns

Open the package's detail page and copy the install command:

# Local install
mpremote mip install https://upypi.net/pkgs/microdns/0.0.1

# Remote install (on the board)
mip.install("https://upypi.net/pkgs/microdns/0.0.1")

Then transfer these files to the ESP32's root directory:

For details on usage, see: https://upypi.net/zh/pkgs/microdns

The package README, shown as two screenshots in the original article, reads:

  1. Upload the files to the ESP32: upload all files to the ESP32's root directory.
  2. Start the server: exec(open('main_with_web.py').read())
  3. Connect to the Wi-Fi network: SSID ESP32_DNS_Server, password 12345678, IP address 192.168.4.1.
  4. Configure DNS: set the device's DNS server address to 192.168.4.1.
  5. Open the web page: in a browser, visit http://www.example.com.

DNS records can be changed in dns_list.py:

self.dns_records = {
    'example.com': '192.168.4.1',
    'www.example.com': '192.168.4.1',
    'test.com': '192.168.4.1',
    '*.local': '192.168.4.1',  # wildcard match
}

The AP settings can be changed in main.py:

ap.config(essid='ESP32_DNS_Server', password='12345678')
ap.ifconfig(('192.168.4.1', '255.255.255.0', '192.168.4.1', '8.8.8.8'))

Testing:

# 1. Test with nslookup
nslookup example.com 192.168.4.1

# 2. Test with ping
ping example.com

# 3. Test with dig

Advanced tests: DNS hijacking and NCSI spoofing

Test goals

On top of basic DNS resolution, we carried out two advanced experiments:

Test 1: DNS hijacking demo: visiting Baidu lands on a notice page

  1. Connect the device to the ESP32 hotspot ESP32_DNS_Server and set its DNS address to 192.168.4.1.
  2. Type baidu.com in the browser and watch where the page goes.

Screenshot (in the original article, with Chinese labels): the browser address bar shows Baidu's address, with a "Not secure" warning next to it; the page itself is the ESP32's information-security notice ("Protect personal information, build a happy home together"), because the hijacked DNS resolved baidu.com to our notice page.

ESP32 code, the DNS query log and the Windows Wi-Fi panel showing Connected, secured

The browser address bar still shows baidu.com, but the page has been hijacked to the ESP32's information-security notice page, and the browser shows a "Not secure" warning at the top (as expected for unencrypted HTTP).

The ESP32's DNS server resolves baidu.com to its own IP, 192.168.4.1, while the web server listens on port 80 and returns a custom HTML page. This is the typical public Wi-Fi DNS hijacking scenario, and it is the educational demo we use to teach network security.

Test 2: NCSI spoofing: fooling the Windows network check

Windows decides whether the network is connected by visiting dns.msftncsi.com and www.msftconnecttest.com/connecttest.txt, so we need the ESP32 to "play along" with this check.

Add the NCSI domains to dns_list.py:

DNS_LIST = {
    # ... other domains
    'dns.msftncsi.com': '192.168.4.1',
    'www.msftconnecttest.com': '192.168.4.1',
}

Add a response for /connecttest.txt in web_server.py:

@app.route('/connecttest.txt')
def connecttest():
    return 'Microsoft Connect Test', 200, {'Content-Type': 'text/plain'}

The terminal log shows that the NCSI check requests sent by Windows were intercepted and answered by the ESP32:

[dns] DNS query received: dns.msftncsi.com (type: 1)
[dns] Resolved dns.msftncsi.com -> 192.168.4.1
[dns] DNS query received: www.msftconnecttest.com (type: 1)
[dns] Resolved www.msftconnecttest.com -> 192.168.4.1
[web]Generated response: [('Content-Type', 'text/plain')]

What else can you do with it?

This project is only a prototype for now, and there is plenty more to tinker with: