6
6
7
7
1 . 克隆或者下载本仓库到你的服务器上
8
8
9
- 不多说。
10
-
11
9
2 . 决定是否开放公网访问?
12
10
13
11
倒数第几行中的` http.ListenAndServe("localhost:8000", nil) ` ,这样写的话只能通过localhost进行访问,墙裂建议不要修改,而后通过中间件反向代理后对外开放,方便做访问控制、日志管理等。如果想直接对外开放的话可以修改为:` http.ListenAndServe(":8000", nil) `
20
18
21
19
22
20
先执行
23
-
21
+
24
22
``` shell
25
23
$ go env -w GO111MODULE=on
26
24
$ go env -w GOPROXY=https://goproxy.cn,direct # 可选,国内机器不能上github则需要执行此处以设置{代}{理}
25
+ $ go mod download github.com/miekg/dns # 拉取需要的库
27
26
```
28
-
29
- 而后` go run main.go ` 即可看到如下字样,说明已经正常拉取需要的库 。
30
-
27
+
28
+ 而后` go run main.go ` 即可看到如下字样,说明已经可以正常运行 。
29
+
31
30
``` shell
32
31
[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
36
32
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
37
33
exit status 1
38
34
```
39
-
35
+
40
36
`go run main.go yourdomain` 可先在shell前台运行,看功能是否正常使用与检查数据存放目录是否成功创建。如果没问题的话 直接 `nohup go run main.go yourdomain &`
41
37
42
38
## 使用
45
41
46
42
1. /new_gen
47
43
48
- 生成随机的八位字符,组合到domain中并返回。当然也可以本地生成,没做限制,无所谓。
44
+ 生成子域名,返回格式如下:
49
45
50
- 2. /八位字符
46
+ ```json
47
+ {
48
+ "domain":"09fbd867.www.com.",
49
+ "key":"09fbd867",
50
+ "token":"iepdbo4yz1vn"
51
+ }
52
+ ```
51
53
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形式。
53
66
54
67
55
68
PS:当然,你也可以通过 go build 打包成可执行文件进行跨平台或者离线运行。这都依赖于go的特性。
@@ -59,39 +72,53 @@ PS:当然,你也可以通过 go build 打包成可执行文件进行跨平
59
72
1. 临时数据存放目录
60
73
```go
61
74
localdir, _ := os.Getwd()
62
- tmplogdir = localdir + "/ dnslog/" //DNS日志存放目录,可自行更改。
75
+ tmplogdir = localdir + string(os.PathSeparator)+" dnslog"+string(os.PathSeparator) //DNS日志存放目录,可自行更改。
63
76
```
64
77
65
78
2. html页面
66
79
67
80
HelloHandler方法中的res变量
68
81
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
-
91
82
## 检查NS指向是否成功?
92
83
93
84
可以通过linux下命令行工具`host -t ns sub.youdomain.com`来确认NS服务器。也可以通过在线工具:https://myssl.com/dns_check.html (选择NS类型)
94
85
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
+
95
122
## 其他
96
123
97
124
感谢高学长给予的大力帮助:https://github.com/netchiso
0 commit comments