66
771 . 克隆或者下载本仓库到你的服务器上
88
9- 不多说。
10-
1192 . 决定是否开放公网访问?
1210
1311 倒数第几行中的` http.ListenAndServe("localhost:8000", nil) ` ,这样写的话只能通过localhost进行访问,墙裂建议不要修改,而后通过中间件反向代理后对外开放,方便做访问控制、日志管理等。如果想直接对外开放的话可以修改为:` http.ListenAndServe(":8000", nil) `
2018
2119
2220 先执行
23-
21+
2422 ``` shell
2523 $ go env -w GO111MODULE=on
2624 $ go env -w GOPROXY=https://goproxy.cn,direct # 可选,国内机器不能上github则需要执行此处以设置{代}{理}
25+ $ go mod download github.com/miekg/dns # 拉取需要的库
2726 ```
28-
29- 而后` go run main.go ` 即可看到如下字样,说明已经正常拉取需要的库 。
30-
27+
28+ 而后` go run main.go ` 即可看到如下字样,说明已经可以正常运行 。
29+
3130 ``` shell
3231 [root@centos dnslog] go run main.go
33- go: downloading github.com/miekg/dns v1.1.41
34- go: downloading golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
35- go: downloading golang.org/x/sys v0.0.0-20210303074136-134d130e1a04
3632 2021/03/24 13:58:54 Dnslog Platform requires a domain name parameter, such as ` dns1.tk` or ` go.dns1.tk` , And check your domain' s ns server point to this server
3733 exit status 1
3834 ```
39-
35+
4036 `go run main.go yourdomain` 可先在shell前台运行,看功能是否正常使用与检查数据存放目录是否成功创建。如果没问题的话 直接 `nohup go run main.go yourdomain &`
4137
4238## 使用
4541
46421. /new_gen
4743
48- 生成随机的八位字符,组合到domain中并返回。当然也可以本地生成,没做限制,无所谓。
44+ 生成子域名,返回格式如下:
4945
50- 2. /八位字符
46+ ```json
47+ {
48+ "domain":"09fbd867.www.com.",
49+ "key":"09fbd867",
50+ "token":"iepdbo4yz1vn"
51+ }
52+ ```
5153
52- 第一步生成的八位字符可以直接访问,可以获取到相关的DNS解析记录。返回为null或者正常数据的JSON形式。
54+ token字段为新引进。随机生成的12位字符。而后通过md5运算后取得key作为子域名部分。
55+
56+ ```go
57+ token := randSeq(12)
58+ key := md5sum(token)[0:8]
59+ ```
60+
61+ 当然你也可以本地进行生成。不过要注意的是所有访问均进行了强制转换为小写,所以你自己本地生成的token要是一个 12 位的小写字符串。
62+
63+ 2. /$yourtoken
64+
65+ 通过访问/$yourtoken(此处也就是/iepdbo4yz1vn)可以获取到相关的DNS解析记录。返回为null或者正常数据的JSON形式。
5366
5467
5568PS:当然,你也可以通过 go build 打包成可执行文件进行跨平台或者离线运行。这都依赖于go的特性。
@@ -59,39 +72,53 @@ PS:当然,你也可以通过 go build 打包成可执行文件进行跨平
59721. 临时数据存放目录
6073 ```go
6174 localdir, _ := os.Getwd()
62- tmplogdir = localdir + "/ dnslog/" //DNS日志存放目录,可自行更改。
75+ tmplogdir = localdir + string(os.PathSeparator)+" dnslog"+string(os.PathSeparator) //DNS日志存放目录,可自行更改。
6376 ```
6477
65782. html页面
6679
6780 HelloHandler方法中的res变量
6881
69- 3. 子域名长度
70-
71- 数据接口判断了访问路径是否为9,是才会尝试读取文件中储存的记录。
72-
73- ```go
74- if len(r.URL.Path) == 9 {
75- w.Header().Set("Content-Type", "application/json")
76- res = GetDnslog(r.URL.Path)
77- ```
78-
79- new_gen接口返回的随机key长度为8
80-
81- ```go
82- key := randSeq(8)
83- ```
84-
85- 写入文件时判断了子域名长度是否为8
86-
87- ```go
88- if len(idkey) == 8 {
89- ```
90-
9182## 检查NS指向是否成功?
9283
9384可以通过linux下命令行工具`host -t ns sub.youdomain.com`来确认NS服务器。也可以通过在线工具:https://myssl.com/dns_check.html (选择NS类型)
9485
86+ ## Demo
87+
88+ ```python
89+ #coding:utf-8
90+ import requests
91+ import json
92+
93+ base = "http://localhost:8000/"
94+ try:
95+ print("[-] try to get a subdomain.")
96+ subdomaindata = requests.get(base+"new_gen",timeout=5).json()
97+ token = subdomaindata[' token' ]
98+ subdomain = subdomaindata[' domain' ]
99+ print("[+] this is your subdomain [ %s ], try to resolve it!" % subdomain)
100+ print("[+] this is your token [ %s ]" % token)
101+ try:
102+ requests.get("http://"+subdomain,timeout=2)
103+ except:
104+ pass
105+ data = requests.get(base+token,timeout=5).text
106+ if(data=="null"):
107+ print("no data")
108+ else:
109+ res = json.loads(data)
110+ for x in res:
111+ print(res[x])
112+ except:
113+ print("error")
114+ ```
115+
116+ ## 更新日志:
117+
118+ + 2021/4/3 引入token机制,保证隐私性。
119+
120+ + 1970-2021/4/2 初版本。
121+
95122## 其他
96123
97124感谢高学长给予的大力帮助:https://github.com/netchiso
0 commit comments