Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alpkeskin
GitHub Repository: alpkeskin/mosint
Path: blob/master/v3/pkg/services/breachdirectory/breachdirectory.go
689 views
1
/*
2
Copyright © 2023 github.com/alpkeskin
3
*/
4
package breachdirectory
5
6
import (
7
"encoding/json"
8
"fmt"
9
"io"
10
"net/http"
11
"strings"
12
13
"github.com/alpkeskin/mosint/v3/internal/config"
14
"github.com/alpkeskin/mosint/v3/internal/spinner"
15
"github.com/fatih/color"
16
)
17
18
type BreachDirectory struct {
19
Response BreachDirectoryResponse
20
}
21
22
type BreachDirectoryResponse struct {
23
Success bool `json:"success"`
24
Found int `json:"found"`
25
Result []struct {
26
HasPassword bool `json:"has_password"`
27
Sources []string `json:"sources"`
28
Password string `json:"password,omitempty"`
29
Sha1 string `json:"sha1,omitempty"`
30
Hash string `json:"hash,omitempty"`
31
} `json:"result"`
32
}
33
34
func New() *BreachDirectory {
35
return &BreachDirectory{}
36
}
37
38
func (b *BreachDirectory) Lookup(email string) {
39
spinner := spinner.New("Breached Password Searching")
40
spinner.Start()
41
42
key := config.Cfg.Services.BreachDirectoryApiKey
43
if strings.EqualFold(key, "") {
44
spinner.StopFail()
45
spinner.SetMessage("BreachDirectory Api Key is empty")
46
return
47
}
48
49
url := fmt.Sprintf("https://breachdirectory.p.rapidapi.com/?func=auto&term=%s", email)
50
51
req, err := http.NewRequest("GET", url, nil)
52
53
if err != nil {
54
spinner.StopFail()
55
spinner.SetMessage(err.Error())
56
return
57
}
58
59
req.Header.Add("x-rapidapi-host", "breachdirectory.p.rapidapi.com")
60
req.Header.Add("x-rapidapi-key", key)
61
62
client := &http.Client{}
63
resp, err := client.Do(req)
64
65
if err != nil {
66
spinner.StopFail()
67
spinner.SetMessage(err.Error())
68
return
69
}
70
71
defer resp.Body.Close()
72
body, err := io.ReadAll(resp.Body)
73
74
if err != nil {
75
spinner.StopFail()
76
spinner.SetMessage(err.Error())
77
return
78
}
79
80
var response BreachDirectoryResponse
81
err = json.Unmarshal(body, &response)
82
83
if err != nil {
84
spinner.StopFail()
85
spinner.SetMessage(err.Error())
86
return
87
}
88
89
b.Response = response
90
spinner.Stop()
91
}
92
93
func (b *BreachDirectory) Print() {
94
key := config.Cfg.Services.BreachDirectoryApiKey
95
if strings.EqualFold(key, "") {
96
return
97
}
98
99
if !b.Response.Success {
100
fmt.Println(color.RedString("[!]"), "BreachDirectory Internal Error")
101
return
102
}
103
104
fmt.Println("[*] Breached Sources and Passwords")
105
for _, v := range b.Response.Result {
106
for _, v2 := range v.Sources {
107
fmt.Println(color.GreenString("[+]"), v2)
108
}
109
if v.HasPassword {
110
fmt.Println("[*] Password")
111
fmt.Println(color.GreenString("[+]"), v.Password)
112
fmt.Println(color.GreenString("[+]"), v.Sha1)
113
fmt.Println(color.GreenString("[+]"), v.Hash)
114
}
115
if !v.HasPassword {
116
fmt.Println(color.RedString("[!]"), "Password Not Found")
117
}
118
}
119
}
120
121