网站子域名扫描程序,采用三种扫描方式(crt网站查询、站长网站查询、字典暴力破解)
总体文件结构:
1个主文件common.py,
1个全局配置文件config.py,
1个随机取user_agent头文件user_agent_list.py,
暴力破解方式文件:brute_check.py,brute.py,domain_dic.txt(暴力破解的字典)
crt网站(https://crt.sh/)查询子域名文件:crt_check.py,crt.py
站长网站(http://tool.chinaz.com/subdomain/)查询子域名文件:chinaz_check.py,chinaz.py
主文件common.py:
封装了发送网络请求的方式和main主方法,扫描结果列表去重工作
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import urllib3
import requests
import user_agent_list
from config import *
from brute_check import *
from crt_check import crt_check
from chinaz_check import *
# 网站子域名扫描器
# 当网站主站无从下手时,可以选择从c段或者同IP站点下手进行测试
# 举例,比如某个网站www.test.com 主站基本为静态页面,无从下手,但是扫描后得知存在bbs.test.com,可以从论坛下手拿到管理权限。
# 方式:暴力破解(子域名字典爆破),搜索引擎查询,页面爬取,第三方查询https://crt.sh/(发送请求,分析返回内容,整理数据,展现),
# xxx.com/crossdomain.xml文件,通过HTTPS证书搜集(调用对方api接口获取信息,展现),如 https://censys.io/
# 程序设计,utils目录下存放不同的查询方式脚本。common.py为主程序文件,发送requests网络请求,判断返回信息。config.py为全局配置文件,方便后期修改配置,包括访问超时时间,随机的user_agent头。
# 百度搜索子域名 site:xxx.com,或者xxx.cn
# 站长助手-子域名查询 http://tool.chinaz.com/subdomain/
# common.py这个文件是用来封装get和post网络请求方法
# 因为访问的https网站,所以使用urllib3的disable_warnings方法来屏蔽掉https的警告信息,不会杂乱
requests.packages.urllib3.disable_warnings()
rr = []
def http_requests_get(url, allow_redirects=False):
try:
result = requests.get(
url=url,
headers=user_agent_list.get_user_agent(),
timeout=8,
verify=allow_ssl_verify
)
if result.status_code == 200:
return result
except Exception as e:
return requests.models.Response()
def http_requests_post(url, payload, allow_redirects=allow_redirects):
try:
result = requests.get(
url=url,
data=payload,
headers=headers,
timeout=timeout,
allow_redirects=allow_redirects,
verify=allow_ssl_verify
)
return result
except Exception as e:
return requests.models.Response()
# 检测传入的域名地址是否是完整域名
def is_domain(domain):
domain_regex = re.compile('[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?', re.IGNORECASE)
return True if domain_regex.match(domain) else False
def main(domin):
# crt网站查询子域名
print('正在使用crt网站查询子域名:' + domin)
rr1 = crt_check(domin)
print(rr1)
# 暴力破解查询子域名
print('\n')
print('正在使用暴力破解域名:' + domin)
rr2 = brute_check(domin)
print('\r')
print(rr2)
# 站长网站查询子域名
print('\n')
print('正在使用站长中国网站查询子域名:' + domin)
rr3 = chinazz_check(domin)
print(rr3)
for i in rr1:
if i not in rr:
rr.append(i)
for y in rr2:
if y not in rr:
rr.append(y)
for n in rr3:
if n not in rr:
rr.append(n)
print('\n')
print(domin + '网站的子域名最终查询结果:')
print(rr)
if __name__ == '__main__':
main