This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrecon.cloud.go
193 lines (160 loc) · 4.69 KB
/
recon.cloud.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package main
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"time"
)
type JsonStatusRes struct{
Msg_type string `json:"msg_type"`
Step string `json:"step"`
Total_subdomains int `json:"total_subdomains"`
Request_id string `json:"request_id"`
}
type JsonInitRes struct {
MsgType string `json:"msg_type"`
RequestID string `json:"request_id"`
OnCache bool `json:"on_cache"`
Step string `json:"step"`
CloudAssetsList []struct {
Key string `json:"key"`
Domain string `json:"domain"`
Ip []map[string]string `json:"ip"`
Cname string `json:"cname"`
Service string `json:"service"`
Region string `json:"region"`
CloudProvider string `json:"cloud_provider"`
Enrich struct {
Ports interface{} `json:"ports"`
Cves interface{} `json:"cves"`
Tags interface{} `json:"tags"`
StorageAccess interface{} `json:"storage_access"`
} `json:"enrich"`
} `json:"cloud_assets_list"`
TotalSubdomains int `json:"total_subdomains"`
ScanTime string `json:"scan_time"`
}
func readFile(file string) []string{
var domains []string
f, err := os.Open(file)
logError(err)
rd := bufio.NewScanner(f)
for rd.Scan(){
if rd.Text() != "" {
domains = append(domains, rd.Text())
}
}
return domains
}
func outPut(content []string, name string){
if name != "none" {
file, err := os.OpenFile(name, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
logError(err)
defer file.Close()
w := bufio.NewWriter(file)
for _, line := range content {
fmt.Fprintln(w, line)
}
w.Flush()
} else {
for _, line := range content {
fmt.Println(line)
}
}
}
func logError(err error){
if err != nil{
log.Fatal(err)
os.Exit(1)
}
}
func reconCloud(domain string, onlyIP bool, outFile string) {
initReq, err := http.Get("https://recon.cloud/api/search?domain=" + domain)
logError(err)
defer initReq.Body.Close()
var jsonInitRes JsonInitRes
dataBytes, err := ioutil.ReadAll(initReq.Body)
logError(err)
json.Unmarshal(dataBytes, &jsonInitRes)
if jsonInitRes.Step != "finished"{
reqID := jsonInitRes.RequestID
var jsonStatusRes JsonStatusRes
var step string
for step != "finished" {
time.Sleep(3 * time.Second)
statusReq, err := http.Get("https://recon.cloud/api/get_status?request_id=" + reqID)
logError(err)
defer statusReq.Body.Close()
bytes, err := ioutil.ReadAll(statusReq.Body)
logError(err)
json.Unmarshal(bytes, &jsonStatusRes)
step = jsonStatusRes.Step
}
var jsonAnsRes JsonInitRes
resultReq, err := http.Get("https://recon.cloud/api/get_results?request_id=" + reqID)
logError(err)
defer resultReq.Body.Close()
resultBytes, err := ioutil.ReadAll(resultReq.Body)
logError(err)
json.Unmarshal(resultBytes, &jsonAnsRes)
filterOutput(jsonAnsRes, onlyIP, outFile)
} else {
filterOutput(jsonInitRes, onlyIP, outFile)
}
}
func filterOutput(jsonRes JsonInitRes, onlyIP bool, outFile string){
var out []string
if onlyIP {
for _, value := range jsonRes.CloudAssetsList {
for _, list := range value.Ip {
for ip := range list {
out = append(out, ip)
}
}
}
} else {
for _, value := range jsonRes.CloudAssetsList {
out = append(out, value.Domain)
}
}
outPut(out, outFile)
}
func main() {
var domains []string
domain := flag.String("d", "", "Only Domain")
var inFile string
flag.StringVar(&inFile, "l", "", "List of file containing Domains")
var onlyIP bool
flag.BoolVar(&onlyIP, "only-ip", false, "Get IPs instead of Domains")
var outFile string
flag.StringVar(&outFile,"o", "none", "Path of output file")
flag.Parse()
if *domain == "" {
if inFile == "" {
sc := bufio.NewScanner(os.Stdin)
for sc.Scan() {
if sc.Text() != "" {
domains = append(domains, sc.Text())
for _, domain := range domains {
reconCloud(domain, onlyIP, outFile)
}
}
}
if err := sc.Err(); err != nil {
log.Fatal(err)
}
} else {
domains = readFile(inFile)
for _, domain := range domains {
reconCloud(domain, onlyIP, outFile)
}
}
} else {
reconCloud(*domain, onlyIP, outFile)
}
}