-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
util.go
72 lines (58 loc) · 1.13 KB
/
util.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
package main
import (
"os"
"regexp"
"archive/zip"
"path/filepath"
)
func isVuln(jar *zip.ReadCloser) bool {
for _, class := range jar.File {
i, s := 0, 0
for s < len(SIGNATURES) {
status, e := false, s+7
if isStr(class.Name, FATAL_CLASS[i]) {
status = !isByt(readClass(class), SIGNATURES[s:e])
if i == 0 {
status = isByt(readClass(class), SIGNATURES[s:e])
}
}
if status {
return true
}
i, s = i+1, s+7
}
}
return false
}
func lookup(path string) ([]string, error) {
var files []string
file, err := os.Open(path)
if err != nil {
return files, err
}
defer file.Close()
stat, err := file.Stat()
if err != nil {
return files, err
}
if !stat.IsDir() {
path, _ = filepath.Abs(path)
files = append(files, path)
} else {
jar, _ := regexp.Compile(JAR_PATTERN)
err = filepath.Walk(path, func(fp string, fi os.FileInfo, fe error) error {
if fe != nil {
return fe
}
if !fi.IsDir() && jar.MatchString(fi.Name()) {
fp, _ = filepath.Abs(fp)
files = append(files, fp)
}
return nil
})
if err != nil {
return files, err
}
}
return files, nil
}