├── CNAME ├── domain.txt ├── requirements.txt ├── README.md └── domainTakeover.py /CNAME: -------------------------------------------------------------------------------- 1 | wiki.designer.xiaomi.com -------------------------------------------------------------------------------- /domain.txt: -------------------------------------------------------------------------------- 1 | www.baidu.com 2 | baidu.com 3 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | tld 2 | dnspython 3 | requests 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # domainTakeover 2 | ## 简介 3 | 域名接管检测工具 4 | 没什么好说的就是获取域名cname解析,进行判断是否域名能购买 5 | 6 | 如果乱码请把 # -*- coding:utf-8 -*-替换为 # -*- encoding:gb2312 -*- 7 | ## 使用说明 8 | 9 | 1. domain.txt文件 10 | >www.baidu.com 11 | >baidu.com 12 | 2. TakeoverResult.txt (检测到生成) 13 | >www.baidu.com|True 14 | >baidu.com|False 15 | 3. 扫描启动 16 | >python domainTakeover.py(输出的内容不用管,就是怕你感觉他没动静,才输出) 17 | -------------------------------------------------------------------------------- /domainTakeover.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding:utf-8 -*- 3 | import dns.resolver 4 | import requests 5 | import json 6 | import re 7 | import threading 8 | import time 9 | import inspect 10 | import ctypes 11 | from tld import get_tld 12 | #tld,dnspython,requests 13 | class ThreadPool: 14 | def __init__(self, size, timeout): 15 | self._size = size 16 | self._timeout = timeout 17 | 18 | def _async_raise(self, tid, exctype): 19 | """raises the exception, performs cleanup if needed""" 20 | tid = ctypes.c_long(tid) 21 | if not inspect.isclass(exctype): 22 | exctype = type(exctype) 23 | res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 24 | ctypes.py_object( 25 | exctype)) 26 | if res == 0: 27 | raise ValueError("invalid thread id") 28 | elif res != 1: 29 | ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) 30 | raise SystemError("PyThreadState_SetAsyncExc failed") 31 | 32 | def _stop_thread(self, thread): 33 | self._async_raise(thread.ident, SystemExit) 34 | 35 | def start(self, func, task, data): 36 | record = dict() 37 | while len(task) or len(record) > 0: #任务必须有 记录线程 38 | while len(record) < self._size and len(task) > 0: 39 | item = task.pop() 40 | t = threading.Thread(target=func, args=(item, data,)) 41 | t.start() 42 | record[t.getName()] = {'thread': t, 'time': time.time(),'data':item} #记录 43 | dellist = [] 44 | for k, v in record.items(): 45 | print('检测:' + k) 46 | if v['thread'].isAlive(): 47 | if time.time() - v['time'] > self._timeout: 48 | self._stop_thread(v['thread']) 49 | dellist.append(k) 50 | else: 51 | dellist.append(k) 52 | time.sleep(1) 53 | for dl in dellist: 54 | del (record[dl]) 55 | 56 | def takeover(domain): 57 | n = 0 58 | if domain: 59 | domain = "http://" + domain[:-1] 60 | url = get_tld(domain, as_object=True) 61 | while True: 62 | try: 63 | r = requests.get( 64 | 'https://checkapi.aliyun.com/check/checkdomain?domain={0}&command=&token=Y3d83b57bc8aca0f156381976a6171f4a&ua=¤cy=&site=&bid=&_csrf_token=&callback=jsonp_1569557125267_14652'.format( 65 | url.fld), timeout=5).text 66 | if str(json.loads(re.match(".*?({.*}).*", r, re.S).group(1))['module'][0]['avail']) == '1': 67 | return True 68 | else: 69 | return False 70 | except Exception as e: 71 | print e 72 | n = n + 1 73 | if n >= 3: 74 | break 75 | else: 76 | continue 77 | 78 | def main(domain, data): 79 | try: 80 | cn = dns.resolver.query(domain, 'CNAME') 81 | for list in cn.response.answer: 82 | for cname in list.items: 83 | judge = takeover(cname.to_text()) 84 | if judge: 85 | data.append(domain + "|" + str(judge)) 86 | return judge 87 | except: 88 | return False 89 | 90 | if __name__ == '__main__': 91 | f = open(r'domain.txt', 'rb') 92 | final_domain_list = [] 93 | for line in f.readlines(): 94 | final_domain = line.strip('\n') 95 | if final_domain.strip(): 96 | final_domain_list.append(final_domain) 97 | data = [] 98 | pool = ThreadPool(20, 300) 99 | pool.start(main, final_domain_list, data) 100 | if len(data) >0: 101 | with open(r'TakeoverResult.txt', 'ab+') as ff: 102 | for i in data: 103 | ff.write(i + '\n') 104 | --------------------------------------------------------------------------------