-
Notifications
You must be signed in to change notification settings - Fork 2
/
dnsrecon.go
88 lines (65 loc) · 1.61 KB
/
dnsrecon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"github.com/gorilla/mux"
"dnsrecon/config"
"dnsrecon/dnsrecon"
"dnsrecon/handlers"
"dnsrecon/logging"
"dnsrecon/resolvers"
"log"
"net/http"
"time"
)
func main() {
s := handlers.Server{}
resolvers.CreateResolversFile()
created := config.CreateConfig()
if created {
return
}
s.Config = config.LoadConfig()
resolvers := resolvers.LoadResolvers()
cache := dnsrecon.NewLruCache()
s.Log = logging.NewLogger()
s.DnsClientChan = make(chan *dnsrecon.DnsClient, len(resolvers.DnsServers))
rCount := 0
// Load the resolvers
for _, resolver := range resolvers.DnsServers {
if rCount != 0 && rCount == s.Config.MaximumDnsServers {
break
}
client := dnsrecon.NewDnsClient()
client.Resolver = resolver
client.RetryResolvers = resolvers.RetryServers
client.Ratelimit = resolver.Ratelimit
client.Cache = cache
client.Log = logging.NewLogger()
client.Start()
s.DnsClientChan <- client
rCount++
}
fmt.Printf("Using %d public dns servers\n", rCount)
// Clear the LRU cache every 24 hours
go func() {
for range time.Tick(time.Hour * 24) {
cache.Mu.Lock()
cache.Lru.Clear()
cache.Mu.Unlock()
}
}()
r := mux.NewRouter()
r.HandleFunc("/", healthCheckHandler)
r.Path("/domain/{domain}").Methods("GET").HandlerFunc(s.HandleFunc(s.TargetDomainHandler))
fmt.Println("Listening on port 8080")
http.Handle("/", r)
srv := &http.Server{
ReadTimeout: 80 * time.Second,
WriteTimeout: 80 * time.Second,
Addr: ":8080",
}
log.Fatal(srv.ListenAndServe())
}
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "ok")
}