-
Notifications
You must be signed in to change notification settings - Fork 46
/
process.go
141 lines (129 loc) · 3.36 KB
/
process.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package main
import (
"bytes"
"crypto/tls"
"fmt"
"log"
"net/http"
"net/url"
"regexp"
"strings"
"sync"
"time"
"github.com/gocolly/colly"
"golang.org/x/net/html"
)
func (p *ProcJob) FingerPrint() {
log.Println("Trying to identify tech stack:", p.Host)
heads, body, err := makeRequest(p.Host)
if err != nil {
log.Println("Error during tech stack detection:", err.Error())
return
}
fresp := heads + "\n\n" + string(*body)
outBreak:
for tech, ddata := range dbData {
for _, drex := range ddata.Detectors {
rex := regexp.MustCompile(drex)
if rex.MatchString(fresp) {
log.Printf("Identified tech stack for %s: %s", p.Host, tech)
p.Host = p.Host + ":::" + tech
break outBreak
}
}
}
}
func (p *ProcJob) ExecuteCrawler() {
hastechs := false
mainurl := p.Host
if strings.Contains(p.Host, ":::") {
hastechs = true
mainurl = strings.Split(p.Host, ":::")[0]
}
log.Println("Processing:", p.Host)
if !strings.Contains(p.Host, "://") {
mainurl = "http://" + p.Host
} else {
p.Host = strings.Split(p.Host, "://")[1]
}
var c *colly.Collector
if !wildcardCrawl {
c = colly.NewCollector(
colly.AllowedDomains(strings.Split(mainurl, "://")[1]),
colly.UserAgent(USERAGENT),
colly.ParseHTTPErrorResponse(),
colly.MaxDepth(crawlDepth),
colly.CacheDir(".colly_cache/"),
)
} else {
c = colly.NewCollector(
colly.UserAgent(USERAGENT),
colly.ParseHTTPErrorResponse(),
colly.MaxDepth(crawlDepth),
colly.CacheDir(".colly_cache/"),
)
}
c.WithTransport(&http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: !verifySSL,
},
DisableKeepAlives: true, // we disable keep alive targets
})
c.SetRequestTimeout(time.Duration(httpTimeout) * time.Second)
c.Limit(&colly.LimitRule{
Parallelism: concurrentURLs,
DomainGlob: "*",
})
c.OnHTML("a[href]", func(e *colly.HTMLElement) {
link := e.Attr("href")
c.Visit(e.Request.AbsoluteURL(link))
})
c.OnResponse(func(r *colly.Response) {
crawlProgress++
/*
if crawlProgress > MAXCRAWLVAL {
log.Println("Stopping crawling due to max URLs visit exceeded!")
return
}
*/
thisTime := time.Now()
fmt.Printf("\r%d/%02d/%02d %02d:%02d:%02d Total processed: %d | Current: %s",
thisTime.Year(), thisTime.Month(), thisTime.Day(), thisTime.Hour(),
thisTime.Minute(), thisTime.Second(), crawlProgress, r.Request.URL.String())
wg := new(sync.WaitGroup)
// start finding secrets on the html sources
findSecrets(mainurl, r.Request.URL.String(), &r.Body)
// start finding secrets within JS files
wg.Add(1)
go getJavascript(*r.Request.URL, &r.Body, wg)
if hastechs {
executeLoot(p.Host, r.Request.URL.String(), r.StatusCode, &r.Body)
if submitForm {
buff := bytes.NewReader(r.Body)
root, err := html.Parse(buff)
if err != nil {
log.Println("error parsing html body:", err.Error(), r.Request.URL.String())
return
}
forms := parseForms(root)
for _, form := range forms {
actionURL, err := url.Parse(form.Action)
if err != nil {
log.Println(err.Error())
continue
}
actionURL = r.Request.URL.ResolveReference(actionURL)
mval := setValues(&form.Values)
err = c.Post(actionURL.String(), mval)
if err != nil {
log.Printf("Error posting form %s: %s", r.Request.URL.String(), err.Error())
}
}
}
}
wg.Wait()
})
c.Visit(mainurl)
// c.Wait()
fmt.Print("\n")
}