-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbbtargets.go
141 lines (127 loc) · 3.08 KB
/
bbtargets.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
// This repository is under GNU General Public License v3.0.
// see https://github.com/Fricciolosa-Red-Team/crch/blob/main/LICENSE
package main
import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"time"
)
//main function
func main() {
output := GetTargets()
if len(output) == 0 {
fmt.Println("[ ! ] Error while retrieving targets.")
os.Exit(1)
}
for _, elem := range output {
fmt.Println(elem)
}
}
//Target is a struct containing informations about
//a single bug bounty program.
type Target struct {
Name string `json:"name"`
Url string `json:"url"`
Bounty bool `json:"bounty"`
Domains []string `json:"domains"`
}
//Programs is a struct containing informations about
//all the programs.
type Programs struct {
Targets []Target `json:"programs"`
}
//GetTargets is the function that actually retrieves
//the json file containing the informations.
func GetTargets() []string {
client := http.Client{
Timeout: 30 * time.Second,
}
var results Programs
url := "https://raw.githubusercontent.com/projectdiscovery/public-bugbounty-programs/master/chaos-bugbounty-list.json"
resp, err := client.Get(url)
if err != nil {
return []string{}
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if err := json.Unmarshal(body, &results); err != nil {
return []string{}
}
var output []string
for _, res := range results.Targets {
//ony programs with bounty
if res.Bounty {
if strings.Contains(res.Url, "hackerone") || strings.Contains(res.Url, "bugcrowd") ||
strings.Contains(res.Url, "intigriti") || strings.Contains(res.Url, "yeswehack") {
output = append(output, cleanIgnored(res.Domains)...)
}
}
}
return output
}
//cleanIgnored is the function that clean the results
//from ignored targets.
func cleanIgnored(domains []string) []string {
var ignored = readFile("ignored.txt")
var ignoredsubs []string
for _, domain := range domains {
for _, forb := range ignored {
if strings.Contains(domain, forb) {
ignoredsubs = append(ignoredsubs, domain)
}
}
}
return difference(domains, ignoredsubs)
}
//difference returns the elements in `a` that aren't in `b`.
func difference(a, b []string) []string {
mb := make(map[string]struct{}, len(b))
for _, x := range b {
mb[x] = struct{}{}
}
var diff []string
for _, x := range a {
if _, found := mb[x]; !found {
diff = append(diff, x)
}
}
return diff
}
//readFile >
func readFile(inputFile string) []string {
file, err := os.Open(inputFile)
if err != nil {
log.Fatalf("failed to open %s ", inputFile)
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
var text []string
var dir = ""
for scanner.Scan() {
dir = scanner.Text()
if len(dir) > 0 {
text = append(text, dir)
}
}
file.Close()
text = removeDuplicateValues(text)
return text
}
//removeDuplicateValues >
func removeDuplicateValues(strSlice []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range strSlice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}