Path: blob/master/v3/pkg/services/breachdirectory/breachdirectory.go
689 views
/*1Copyright © 2023 github.com/alpkeskin2*/3package breachdirectory45import (6"encoding/json"7"fmt"8"io"9"net/http"10"strings"1112"github.com/alpkeskin/mosint/v3/internal/config"13"github.com/alpkeskin/mosint/v3/internal/spinner"14"github.com/fatih/color"15)1617type BreachDirectory struct {18Response BreachDirectoryResponse19}2021type BreachDirectoryResponse struct {22Success bool `json:"success"`23Found int `json:"found"`24Result []struct {25HasPassword bool `json:"has_password"`26Sources []string `json:"sources"`27Password string `json:"password,omitempty"`28Sha1 string `json:"sha1,omitempty"`29Hash string `json:"hash,omitempty"`30} `json:"result"`31}3233func New() *BreachDirectory {34return &BreachDirectory{}35}3637func (b *BreachDirectory) Lookup(email string) {38spinner := spinner.New("Breached Password Searching")39spinner.Start()4041key := config.Cfg.Services.BreachDirectoryApiKey42if strings.EqualFold(key, "") {43spinner.StopFail()44spinner.SetMessage("BreachDirectory Api Key is empty")45return46}4748url := fmt.Sprintf("https://breachdirectory.p.rapidapi.com/?func=auto&term=%s", email)4950req, err := http.NewRequest("GET", url, nil)5152if err != nil {53spinner.StopFail()54spinner.SetMessage(err.Error())55return56}5758req.Header.Add("x-rapidapi-host", "breachdirectory.p.rapidapi.com")59req.Header.Add("x-rapidapi-key", key)6061client := &http.Client{}62resp, err := client.Do(req)6364if err != nil {65spinner.StopFail()66spinner.SetMessage(err.Error())67return68}6970defer resp.Body.Close()71body, err := io.ReadAll(resp.Body)7273if err != nil {74spinner.StopFail()75spinner.SetMessage(err.Error())76return77}7879var response BreachDirectoryResponse80err = json.Unmarshal(body, &response)8182if err != nil {83spinner.StopFail()84spinner.SetMessage(err.Error())85return86}8788b.Response = response89spinner.Stop()90}9192func (b *BreachDirectory) Print() {93key := config.Cfg.Services.BreachDirectoryApiKey94if strings.EqualFold(key, "") {95return96}9798if !b.Response.Success {99fmt.Println(color.RedString("[!]"), "BreachDirectory Internal Error")100return101}102103fmt.Println("[*] Breached Sources and Passwords")104for _, v := range b.Response.Result {105for _, v2 := range v.Sources {106fmt.Println(color.GreenString("[+]"), v2)107}108if v.HasPassword {109fmt.Println("[*] Password")110fmt.Println(color.GreenString("[+]"), v.Password)111fmt.Println(color.GreenString("[+]"), v.Sha1)112fmt.Println(color.GreenString("[+]"), v.Hash)113}114if !v.HasPassword {115fmt.Println(color.RedString("[!]"), "Password Not Found")116}117}118}119120121