0x00 引入
为啥我会突然想到用搭建一个自己的dns服务器呢~因为在一次现场安全教育科普中,我们决定发起一次现场钓鱼…
思路是这样的:内网中有一台服务器来提供**网页服务**,并且在上面开启**dns服务**。在apache配置里面设置虚拟主机,访问ip的话,提供正常的网页服务(报名页),其他的网址请求,一律重定向至`wlan.js139.com`。在此之前我们下载了移动手机登录端的前端界面,作为钓鱼前端。
0x01 bind9 配置 传送门->参考wiki
1 $ sudo apt-get install bind9
安装完成后,我们就要配置dns劫持了。因为是内网环境,并不会污染外网,所以随便搞~ 在/etc/bind目录下新建文件named.fakeroot,作为假根域名服务器,所有域名指向同一个ip 文件内容
1 2 3 @ IN SOA ns.domain.com. hostmaster.domain.com. ( 1 3h 1h 1w 1d ) IN NS 192.168.2.222 * IN A 192.168.2.222
对特定的域名进行特定的解析 新建文件db.kexie,讲 www.kexie.com 指向192.168.2.222这台服务器
1 2 3 4 5 6 7 8 9 10 $TTL 604800 @ IN SOA www.kexie.com. root.www.kexie.com. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS www.kexie.com. @ IN A 192.168.2.219
最后更改named.conf.default-zones,将根域名服务器配置文件替换为假根域名,对于要单独处理的域名单独处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 // prime the server with knowledge of the root servers /*zone "." { type hint; file "/etc/bind/db.root"; };*/ zone "." { type master; file "/etc/bind/named.fakeroot"; }; // be authoritative for the localhost forward and reverse zones, and for // broadcast zones as per RFC 1912 zone "localhost" { type master; file "/etc/bind/db.local"; }; zone "127.in-addr.arpa" { type master; file "/etc/bind/db.127"; }; zone "0.in-addr.arpa" { type master; file "/etc/bind/db.0"; }; zone "255.in-addr.arpa" { type master; file "/etc/bind/db.255"; }; zone "www.kexie.com" { type master; file "/etc/bind/db.kexie"; };
0x02 apache虚拟主机配置 在apache的bin目录下的httpd.conf文件末尾添加代码,这样就实现了通过不同的ip/域名访问同一台服务器而映射不同的网页目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Listen 80 #将域名kexie.com指向www1目录 <VirtualHost *:80 > SeverName kexie.com SeverAlias www.kexie.com DocumentRoot "/var/www1/html" </VirtualHost > <Directory "/var /www1 /html "> Options FllowSymLinks AllowOverride all Require all granted </Directory > #将ip指向www目录 <VirtualHost *:80 > SeverName 192.168.2.222 DocumentRoot "/var/www/html" </VirtualHost > <Directory "/var /www /html "> Options FllowSymLinks AllowOverride all Require all granted </Directory >
0x03 钓鱼php编写 其他域名会指向这个网页,所以我们要将url一并伪造。
1 2 3 4 5 6 7 8 9 10 <?php if (!isset ($_SERVER ['HTTP_REFERER' ])||$_SERVER ['HTTP_REFERER' ]!="http://wlan.jsyd139.com/?token=a5d77894bdcabff5644495423&id=156161616515618498&bxs" ){ echo "<script>window.location.href='http://wlan.jsyd139.com/?token=a5d77894bdcabff5644495423&id=156161616515618498&bxs'</script>" ; die (); } ?> <!DOCTYPE html> 省略... </html>
0x04 网关配置 在网关中配置首选dns,填写dns服务器的ip,补充一点,服务器应该配置静态ip
0x05 小结 dns劫持危险切不容易被察觉,所以连入公共网络的时候,一定要谨慎小心,如果可以的话,尽量配置公共dns,常见的有8.8.8.8、114.114.114.114等 擦亮眼睛啦~
Author:
Appl3s
Permalink:
https://appl3s.github.io/2016/12/08/bind9/
License:
Copyright (c) 2025 CC-BY-NC-4.0 LICENSE
Slogan:
Do you believe in DESTINY ?