-
Notifications
You must be signed in to change notification settings - Fork 43
/
extract_commit.go
172 lines (164 loc) · 4.22 KB
/
extract_commit.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package core
import (
"crypto/sha1"
"encoding/hex"
"fmt"
"github.com/yaklang/yaklang/common/log"
"github.com/yaklang/yaklang/common/utils"
"github.com/yaklang/yaklang/common/yak/yaklib/codec"
"strings"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/proto"
)
func (m *Manager) PageBack(page *rod.Page) error {
err := page.NavigateBack()
if err != nil {
return utils.Errorf("page back error: %s", err)
}
return nil
}
func (m *Manager) extractCommit(page_block *PageBlock) error {
// origin_url := page.MustInfo().URL
page := page_block.page
origin_info, err := page.Info()
if err != nil {
return utils.Errorf("get page info error: %s", err)
}
origin_url := origin_info.URL
html, err := page.HTML()
if err != nil {
return utils.Errorf("get page html error: %s", err)
}
hash := requestToUniqueHash(origin_url, "unknown", html, nil)
if m.visited.Exist(hash) {
return nil
} else {
m.visited.Insert(hash)
}
// do push every button
// cotinue push button while url jump not happen
// do scan next while url jump happen
buttons, err := page.Elements("button")
if err != nil {
return utils.Errorf("get element button error: %s", err)
}
for _, button := range buttons {
button_type, err := button.Attribute("type")
if err != nil {
if m.detailLog {
log.Errorf("__element inputs type get error:%s", err)
}
// return utils.Errorf("__element inputs type get error:%s", err)
continue
}
if button_type != nil && strings.Compare(*button_type, "hidden") == 0 {
continue
}
button.Eval(`()=>this.click()`)
// page.MustWaitLoad()
current_url, err := m.GetCurrentUrl(page)
if err != nil {
// return utils.Errorf("get current url error: %s", err)
if m.detailLog {
log.Errorf("get current url error: %s", err)
}
continue
}
if strings.Compare(origin_url, current_url) != 0 {
page_block.GoDeeper()
m.extractInput(page)
m.extractUrls(page_block)
m.PageBack(page)
page_block.GoBack()
} else {
m.extractInput(page)
m.extractUrls(page_block)
}
}
// so do the submit as button
inputs, err := page.Elements("input")
if err != nil {
return utils.Errorf("__element inputs get error:%s", err)
}
for _, input := range inputs {
input_type, err := input.Attribute("type")
if err != nil {
// return utils.Errorf("__element inputs type get error:%s", err)
if m.detailLog {
log.Errorf("__element inputs type get error:%s", err)
}
continue
}
if input_type != nil && strings.Compare(*input_type, "submit") != 0 {
continue
}
input.Eval(`()=>this.click()`)
current_url, err := m.GetCurrentUrl(page)
if err != nil {
// return utils.Errorf("__element input current url error: %s", err)
if m.detailLog {
log.Errorf("__element input current url error: %s", err)
}
continue
}
if strings.Compare(origin_url, current_url) != 0 {
page_block.GoDeeper()
m.extractInput(page)
m.extractUrls(page_block)
m.PageBack(page)
page_block.GoBack()
} else {
m.extractInput(page)
m.extractUrls(page_block)
}
}
return nil
}
func (m *Manager) CheckSensitive(element *rod.Element) bool {
value, err := element.Attribute("value")
if err != nil {
return false
} else if value == nil {
return false
}
for _, sensiStr := range sensitiveWords {
if strings.Contains(*value, sensiStr) {
return true
}
}
for _, sensiStr := range sensitiveWordsCN {
if strings.Contains(*value, sensiStr) {
return true
}
}
return false
}
func requestToUniqueHash(url string, method string, body string, cookie []*proto.NetworkCookie) string {
var cookieRaw []string
for _, c := range cookie {
if c == nil {
continue
}
cookieRaw = append(cookieRaw, cookieToHash(c))
}
identify := fmt.Sprintf(
"%v METHOD[%v] BODYSHA256:%v COOKIE:SHA256:%v",
url, method, codec.Sha256(body), codec.Sha256(strings.Join(cookieRaw, "|")),
)
return codec.Sha256(identify)
}
func cookieToHash(c *proto.NetworkCookie) string {
return CalcSha1(
c.Value, c.Name,
c.Domain, c.Path, c.Expires.String(),
c.Size, c.HTTPOnly, c.Secure,
c.Secure, c.SameSite,
c.Priority, c.SameParty,
c.SourceScheme, c.SourcePort,
)
}
func CalcSha1(items ...interface{}) string {
s := fmt.Sprintf("%v", items)
raw := sha1.Sum([]byte(s))
return hex.EncodeToString(raw[:])
}