Created
October 3, 2016 19:24
-
-
Save image72/42b5f7357514ff256d50734bb5ffcb6e to your computer and use it in GitHub Desktop.
dns-hijacking via https://www.npmjs.com/package/dns-hijacking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| const util = require('util'); | |
| const net = require('net'); | |
| const cares = process.binding('cares_wrap'); | |
| const _getaddrinfo = cares.getaddrinfo; | |
| class DNSHijacking { | |
| constructor(hosts) { | |
| this._hosts = util._extend({}, hosts); | |
| } | |
| set config(hosts) { | |
| Object.assign(this._hosts, hosts); | |
| } | |
| setup() { | |
| const _hosts = this._hosts; | |
| cares.getaddrinfo = (req, hostname, family, hints) => { | |
| if (_hosts[hostname]) { | |
| return req.callback(null, _hosts[hostname], net.isIPv6(_hosts[ | |
| hostname]) ? 6 : 4); | |
| } | |
| return _getaddrinfo(req, hostname, family, hints); | |
| }; | |
| } | |
| reset() { | |
| cares.getaddrinfo = _getaddrinfo; | |
| } | |
| resetConfig() { | |
| Object.keys(this._hosts).map(key => delete this._hosts[key]); | |
| } | |
| } | |
| module.exports = DNSHijacking; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment