This repository was archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbitdiscovery.go
More file actions
75 lines (65 loc) · 1.8 KB
/
bitdiscovery.go
File metadata and controls
75 lines (65 loc) · 1.8 KB
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
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
// "github.com/lib/pq"
)
type BDInventory struct {
Total int
Assets []map[string](interface{})
}
func scanBitDiscovery(args []string) {
log.SetPrefix("[bitdiscovery] ")
fetchOpenPorts()
}
func fetchOpenPorts() {
var (
scanID = getTimestamp(true)
outPath = "bitdiscovery/" + scanID + ".txt"
)
offset := 0
limit := 1000
var allAssets []map[string](interface{})
for {
requestBody := "[{\"column\": \"bd.original_hostname\", \"type\": \"ends with\",\"value\": \".mil\"},{\"column\": \"ports.ports\",\"type\": \"has any value\"}]"
var bdResponse BDInventory
fetchExternalAPI(fmt.Sprintf("https://bitdiscovery.com/api/1.0/inventory?offset=%d&limit=%d&inventory=true", offset, limit),
http.MethodPost,
bytes.NewBuffer([]byte(requestBody)),
map[string]string{
"Authorization": config.BD_API_KEY,
"Content-Type": "application/json",
},
&bdResponse)
allAssets = append(allAssets, bdResponse.Assets...)
if len(bdResponse.Assets) < limit {
break
}
offset += limit
}
var results []byte
for _, asset := range allAssets {
assetJSON := make(map[string](interface{}))
if asset["bd.original_hostname"] != nil {
assetJSON["domain"] = asset["bd.original_hostname"]
} else {
assetJSON["domain"] = asset["bd.hostname"]
}
assetJSON["ip"] = asset["bd.ip_address"]
assetJSON["ports"] = asset["ports.ports"]
assetJSON["services"] = asset["ports.services"]
assetJSON["banners"] = asset["ports.banners"]
if asset["screenshot.screenshot"] != "no" {
assetJSON["screenshot"] = asset["screenshot.screenshot"]
}
bytes, err := json.Marshal(assetJSON)
handleError(err)
bytes = append(bytes, '\n')
results = append(results, bytes...)
}
uploadToS3(outPath, results)
notifyStorageService(outPath)
}