Hijacking DNS with DNS Rebinding
OSSEC CVEs
Thanks to Kurt over at DWF, I was able to get CVEs assigned for the OSSEC SQL injection detailed in my previous post: CVE-2016-1000266 / CVE-2016-1000265.
(2026 note: these were DWF-assigned identifiers and, as far as I can tell, were never published to the official CVE list. See the note on the OSSEC post.)
I was happy to help the guys over at OSSEC patch the problem, and I'm glad it's getting some acknowledgement.
Hijacking DNS with anti-DNS pinning (DNS rebinding)
Last night I got on a router/modem security kick. Considering the recent attacks we've had going on, I thought it might be nice to jump on the bandwagon of researchers and check it out for myself.
With this, I thought I'd simulate an attack I was able to perform in a penetration test because a router had remote management enabled: hijacking the victim's DNS requests via DNSChef and getting a MITM to steal the victim's credentials as they logged into a specific website.
That was all achieved by simply changing the victim's DNS settings on their router.
So the question became: what's stopping me from doing this to my own modem via a web browser, from an internet-facing URL?
Immediately I started looking for any code which may not enforce the same-origin policy. To explain briefly, the same-origin policy was created to protect against attacks where web code attempts to make a request to a server it's not authorized to talk to (which includes local network resources like modems and routers).
While researching this I kept coming up blank for my specific use case:
- img tag to pull a URL lets you perform a GET request.
- This doesn't allow us to retrieve page content, and DNS can't be changed via a GET request.
- form tag with JavaScript for the submission.
- Could work, but there's a CSRF token in place (on the DNS page).
- This can actually be used to log in, as the login form doesn't require a CSRF token.
- iframe capture: maybe I could CSRF the login with a forced POST, then grab the token from the DNS page via an iframe on it, capturing content with JavaScript out of the iframe.
- SOP (same-origin policy) prevents you from obtaining information from the iframe.
- SVG scripting?
- I didn't look too deeply into this, though I recall there was some recent commotion regarding the way a few popular websites handle sandboxing it.
- WebSockets?
- They use their own protocol, so to my knowledge this wouldn't have allowed me to simulate HTTP over port 80 on the modem, which was my goal.
- Flash sockets?
- I was always intrigued by an 'underground' paper I was sent from a zine/group called SSH (Secret Society Hackers) around 2007–2008, which used Flash sockets to port scan local networks when a victim browsed to it. Since then, Adobe wisely implemented restrictions on how the sockets can be used, leaving this attack useless for what I was trying to accomplish.
- Chrome: chrome.sockets.tcp
- It's my understanding there's no way to trigger this from an actual site; it would have to be built into an extension. Because of that I did no further research on whether it would've let me make requests with no security policy in place on the target, as my goal was simply to have a page load attack the router, not require extension downloads.
- Firefox: TCPSocket
- Would not only require additional user interaction but, it seems, certification or 'trust' from the Mozilla Foundation. Not what I was looking for.
- WebRTC
- No ability to make raw connections.
- Exhausted for options, I'd looked into every capability to establish any kind of network connection (including HTML5 methods and the proposed W3C Sockets).
- Not one seemed to achieve what I was looking for.
- There may be other options still: HTML Imports? "Iframe in an iframe"? (http://blog.cakemail.com/the-iframe-cross-domain-policy-problem/)
At this point I was out of ideas. I could make the browser log in to the modem, but I couldn't bypass the CSRF token, so I had to go back to the drawing board.
This was when the idea hit me that maybe I could bypass SOP by simply "racing" my DNS, or rather what I later came to discover was already called "anti-DNS pinning" or "DNS rebinding".
Essentially, I could load my original page on my subdomain with some JavaScript that did nothing more than fetch the content of the DNS page, as a proof of concept to demonstrate to myself that I could at the very least retrieve the CSRF token I needed to submit new DNS settings.
With a bit of time I was able to do exactly this:
- A PHP script which, when loaded, adjusted DNS settings to point at the modem.
- The PHP script echoed JavaScript which persisted on the client side.
- The JavaScript waited a period of time for the DNS change to take effect, then attempted loading
/RgSetup.asp(my modem's DNS page). - Pwned. I was able to get the CSRF token from the returned data, bypassing SOP, because it was the same domain, just a different IP.
- My first thought was: why wouldn't SOP also validate the IP? But that would break in many cases where people achieve load balancing with a round-robin configuration.
- And I'm sure there are other issues it could cause; I just personally couldn't think of any while writing this article.
Now, I was surprised this was even possible and I had to research it.
It was such a simple method there was no way someone hadn't discovered it before…
The questions ran through my head over and over again:
- Why is this still possible?
- Why has no one reported this yet?
- Why didn't this turn up in my Google searches for "Bypass same-origin policy", "JavaScript access external domains", "HTML5 access external domains", etc.?
As it turns out, it had been covered several times before, and had even been used in attacks against other services and systems, not just modems and routers.
I managed to find a few resources which referred to it as both "DNS rebinding" and "anti-DNS pinning". The original attacks seem to go back to 1996, when it was first reported by Princeton in "Java Security: From HotJava to Netscape and Beyond".
- Wikipedia: https://en.wikipedia.org/wiki/DNS_rebinding
- Stanford: https://crypto.stanford.edu/dns/
- 0CTF 2016 (Monkey) write-up: http://secgroup.github.io/2016/03/14/0ctf-writeup-monkey/
- Positive Research white paper: https://www.ptsecurity.com/ww-en/download/DNS-rebinding.pdf
- How to Hack Millions of Routers: https://www.defcon.org/images/defcon-18/dc-18-presentations/Heffner/DEFCON-18-Heffner-Routers.pdf
- Intranet Invasion Through Anti-DNS Pinning: https://www.blackhat.com/presentations/bh-usa-07/Byrne/Presentation/bh-usa-07-byrne.pdf
- Stealing WiFi passwords with a website: https://miki.it/blog/2015/4/20/the-power-of-dns-rebinding-stealing-wifi-passwords-with-a-website/
- Attackers use phishing emails to compromise routers: http://www.securityweek.com/attackers-use-phishing-emails-exploits-hijack-routers
So now the question was: if it's so widely known, how am I still vulnerable to this? Why have browser developers done nothing to protect against it? In fact, it was reported to both Chrome and the Mozilla Foundation…
- https://bugs.chromium.org/p/chromium/issues/detail?id=98357
- https://bugzilla.mozilla.org/show_bug.cgi?id=1106687
- https://bugzilla.mozilla.org/show_bug.cgi?id=689835
After digging further, it seems the browser developers decided it was up to vendors and sysadmins to resolve the issue by checking the Host header. The scary part is that, as we're realizing today, router and modem vendors are completely irresponsible and ignore security flaws like this.
So I'd independently rediscovered a technique that's apparently been around since the beginning of time (well, 1996), which honestly told me I was thinking along the right lines. Better still, it answered something I've always been curious about: whether I could overwrite my router's configuration with nothing more than a snippet of JavaScript. I could.
The interesting part is the different methods that have been used to try to protect against this.
Like not allowing DNS responses to contain RFC 1918 addresses for domain names. Some saw this as an inconvenience or a problem because they were serving internal portals on subdomains of their corporate domain (I actually ran into this with a client).
The problem there is that serving internal DNS records from a WAN-facing server is never a good idea; DNS forwarders should be used internally to serve these kinds of requests.
So at the end of the day, what did I take home and learn from this?
- DNS rebinding is an extremely old attack, dating back to 1996.
- DNS rebinding has been reused and abused in talks.
- So far there's been no active malicious exploitation seen of it.
- It's not necessarily common knowledge among newer security researchers.
- I've asked a few different people if they've heard of this attack vector, only to learn that not many had.
- Browser developers refuse to protect against it.
- There are still websites that don't check the Host header and let users connect via the dedicated IP assigned to the site.
- Router and modem vendors still aren't protecting their devices appropriately.
- Even without knowing the username/password for my device, the modem kept me authenticated by IP address or MAC for a period of time, meaning I didn't need to steal cookies as long as the 'victim' had logged in before visiting the page.
I'll be writing an additional article with a proof-of-concept code release and a video demonstration against a few different routers within a few days. In the meantime, I'm attempting to contact the vendor of my modem to see if I can get them to implement the appropriate Host header check.
What can you do to protect yourself?
- NoScript
- DNSWall
- Hardware like SonicWall
- Some home-grade routers do protect against this attack, like those from ASUS.
The problem I see with most of these protections is that they still don't fix the root problem, which is very simple: verifying the Host header.

Comments