-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConst.go
134 lines (119 loc) · 2.97 KB
/
Const.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
package go_utils
import (
"context"
"fmt"
"net/http"
"os"
"regexp"
"strings"
"sync"
)
// 全局线程控制
var Wg *sync.WaitGroup = &sync.WaitGroup{}
// 全局控制
var RootContext = context.Background()
// 全局关闭所有线程
var Ctx_global, StopAll = context.WithCancel(RootContext)
// 多次使用,一次性编译效率更高
var DeleteMe = regexp.MustCompile("rememberMe=deleteMe")
// 自定义http 头
var CustomHeaders []string
/*
X-Forwarded-Host: 127.0.0.1
X-Forwarded-For: 127.0.0.1
X-Originating-IP: 127.0.0.1
X-Remote-IP: 127.0.0.1
X-Remote-Addr: 127.0.0.1
X-Client-IP: 127.0.0.1
X-Host: 127.0.0.1
*/
// 获取 自定义头信息等raw模式
func GetCustomHeadersRaw() string {
if 0 < len(CustomHeaders) {
return "\r\n" + strings.Join(CustomHeaders, "\r\n")
}
return ""
}
// 全局设置header
func SetHeader(m *http.Header) {
if 0 < len(CustomHeaders) && nil != m {
for _, i := range CustomHeaders {
n := strings.Index(i, ":")
m.Set(strings.TrimSpace(i[:n]), strings.TrimSpace(i[n+1:]))
}
}
}
// 设置map格式的header
func SetHeader4Map(m *map[string]string) {
if 0 < len(CustomHeaders) && nil != m {
for _, i := range CustomHeaders {
n := strings.Index(i, ":")
(*m)[strings.TrimSpace(i[:n])] = strings.TrimSpace(i[n+1:])
}
}
}
// 异步执行方法,只适合无返回值、或使用管道返回值的方法
// 程序main整体等待
func DoSyncFunc(cbk func()) {
Wg.Add(1)
go func() {
defer Wg.Done()
for {
select {
case <-Ctx_global.Done():
fmt.Println("接收到全局退出事件")
return
default:
cbk()
return
}
}
}()
}
// 检查 cookie
// Shiro CVE_2016_4437 cookie
// 其他POC cookie同一检查入口
func CheckShiroCookie(header *http.Header) int {
var SetCookieAll string
if nil != header {
//if hd, ok := header["Set-Cookie"]; ok {
for i := range (*header)["Set-Cookie"] {
SetCookieAll += (*header)["Set-Cookie"][i]
}
return len(DeleteMe.FindAllStringIndex(SetCookieAll, -1))
}
return 0
}
// 匹配响应中 www-Authenticate 是否有认证要求都信息
var BaseReg = regexp.MustCompile("(?i)Basic\\s*realm\\s*=\\s*")
// 管道通讯使用
type PocCheck struct {
Wappalyzertechnologies *[]string
URL string
FinalURL string
Checklog4j bool
}
// go POC 检测管道,避免循环引用
var PocCheck_pipe = make(chan *PocCheck, 64)
// 头信息同一检查,并调用合适到go poc进一步爆破、检测
//
// 1、需要认证
// 2、shiro
func CheckHeader(header *http.Header, szUrl string) {
DoSyncFunc(func() {
if nil != header {
a1 := []string{}
if v := (*header)["www-Authenticate"]; 0 < len(v) {
if 0 < len(BaseReg.FindAll([]byte(v[0]), -1)) {
a1 = append(a1, "basic")
}
}
if 0 < CheckShiroCookie(header) {
a1 = append(a1, "shiro")
}
if 0 < len(a1) && os.Getenv("NoPOC") != "true" {
PocCheck_pipe <- &PocCheck{Wappalyzertechnologies: &a1, URL: szUrl, FinalURL: szUrl, Checklog4j: false}
}
}
})
}