-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
137 lines (110 loc) · 2.76 KB
/
main.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
package main
import (
"log"
"os"
"os/exec"
githubPatches "github.com/0x4f53/github-patches"
gitlabPatches "github.com/0x4f53/gitlab-patches"
)
var signatures []Signature
func main() {
logo()
err := makeDir(cacheDir)
if err != nil {
log.Println(err)
}
setFlags()
signatures = readSignatures()
if *urlList != "" {
urls, _ := readLines(*urlList)
fetchFromUrlList(urls, true)
return
}
if *URL != "" {
var successfulUrls []string
if *selenium {
if !checkDockerInstalled() {
log.Fatalf("Please install Docker to use Selenium mode!")
}
if !checkImageBuilt() {
log.Println("Attempting to build Selenium testing image from Dockerfile...")
err := exec.Command("docker", "build", "-t", "selenium-integration", ".").Run()
if err != nil {
log.Fatalf("Failed to build Docker image: %v", err)
}
}
successfulUrls = []string{scrapeWithSelenium(*URL)}
ScanFiles(successfulUrls)
} else {
fetchFromUrlList([]string{*URL}, true)
}
return
}
if *directory != "" {
files, err := getAllFiles(*directory)
if err != nil {
log.Fatalf("Error getting files from directory: %v", err)
}
ScanFiles(files)
return
}
if *file != "" {
ScanFiles([]string{*file})
return
}
if *github {
githubPatches.GetCommitsInRange(githubPatches.GithubCacheDir, *from, *to, false)
chunks, err := listFiles(githubPatches.GithubCacheDir)
if err != nil {
log.Fatalf("Error listing GitHub cache files: %v", err)
}
var patches []string
for _, chunk := range chunks {
events, err := githubPatches.ParseGitHubCommits(githubPatches.GithubCacheDir + chunk)
if err != nil {
log.Printf("Error parsing GitHub commits from %s: %v", chunk, err)
continue
}
for _, event := range events {
for _, commit := range event.Payload.Commits {
patches = append(patches, commit.PatchURL)
}
}
}
fetchFromUrlList(patches, true)
defer os.RemoveAll(githubPatches.GithubCacheDir)
return
}
if *gitlab {
commitData := gitlabPatches.GetGitlabCommits(100, 100)
var patches []string
for _, patch := range commitData {
patches = append(patches, patch.CommitPatchURL)
}
fetchFromUrlList(patches, true)
defer os.RemoveAll(gitlabPatches.GitlabCacheDir)
return
}
if *githubGists {
gistData := githubPatches.GetLast100Gists()
parsedGists, err := githubPatches.ParseGistData(gistData)
if err != nil {
log.Fatalf("Error parsing GitHub gists: %v", err)
}
var gists []string
for _, gist := range parsedGists {
gists = append(gists, gist.RawURL)
}
fetchFromUrlList(gists, true)
return
}
if *phishtank {
savePhishtankDataset()
urls, err := readLines(phishtankURLCache)
if err != nil {
log.Fatalf("Error reading phishtank URLs: %v", err)
}
fetchFromUrlList(urls, true)
return
}
}