summaryrefslogtreecommitdiff
path: root/prober/cache_prober.go
blob: 94adeb017f7a042d552f2e2fd0dc00c7a7cb5d94 (plain)
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
package prober

import (
	"dtool/utils"
	_ "fmt"
	"strconv"
	"strings"
	"time"

	"github.com/miekg/dns"
)

const query_num = 20

type CacheStruct struct {
	target string
	dict   map[int]map[string]bool
}

func RecursiveCacheProbe(ip string, sld string) CacheStruct {
	data := CacheStruct{ip, make(map[int]map[string]bool)}
	stop := 0
	time_now := strconv.FormatInt(time.Now().Unix(), 10)
	for i := 0; i < query_num; i++ {
		if stop >= 3 {
			break
		}
		subdomain := strings.Join([]string{strings.Replace(ip, ".", "-", -1), "fwd", strconv.Itoa(i), time_now}, "-")
		domain := dns.Fqdn(subdomain + "." + sld)
		res, err := utils.SendQuery(ip, domain)
		if err != nil {
			//fmt.Printf("Error sending query: %s\n", err)
			stop += 1
			continue
		}
		cache_id, rdns, err := utils.ParseCNAMEChain(res)
		if err != nil {
			//fmt.Printf("Error parsing response: %s\n", err)
			stop += 1
			continue
		}
		if data.dict[cache_id] == nil {
			data.dict[cache_id] = make(map[string]bool)
		}
		data.dict[cache_id][rdns] = true
		stop = 0
	}
	return data
}

func RecursiveCacheTest(ip string, num int) {
	res := make(map[string]map[int][]string)
	temp := make(map[int][]string)
	data := RecursiveCacheProbe(ip, "echodns.xyz")
	if len(data.dict) > 0 {
		for cache_id := range data.dict {
			for rdns := range data.dict[cache_id] {
				temp[cache_id] = append(temp[cache_id], rdns)
			}
		}
	}
	res[ip] = temp
	utils.OutputJSON(res, "-", "    ")
}

func ClientCacheProbe(ip string) {

}