summaryrefslogtreecommitdiffstats
path: root/cmd/osint.go
blob: 5aa8799d76cbfc498b510867fe1938575ed89ec2 (plain)
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
package cmd

import (
	"encoding/json"
	"fmt"
	"git.db.org.ai/dborg/internal/client"
	"git.db.org.ai/dborg/internal/config"
	"git.db.org.ai/dborg/internal/models"
	"git.db.org.ai/dborg/internal/utils"

	"github.com/spf13/cobra"
)

var osintCmd = &cobra.Command{
	Use:   "osint",
	Short: "OSINT tools and searches",
	Long:  `Open Source Intelligence tools for username, email, and other searches`,
}

var osintUsernameCmd = &cobra.Command{
	Use:   "username [username]",
	Short: "Check username availability across websites",
	Long:  `Check username availability across hundreds of websites using WhatsMyName dataset`,
	Args:  cobra.ExactArgs(1),
	RunE:  runOsintUsernameCheck,
}

var osintBSSIDCmd = &cobra.Command{
	Use:   "bssid [bssid]",
	Short: "Lookup WiFi access point location by BSSID",
	Long:  `Lookup geographic location of a WiFi access point by its BSSID (MAC address) using Apple's location services`,
	Args:  cobra.ExactArgs(1),
	RunE:  runOsintBSSIDLookup,
}

var osintBreachForumCmd = &cobra.Command{
	Use:   "breachforum [search]",
	Short: "Search BreachForum data",
	Long:  `Search breachdetect index for BreachForum messages and detections`,
	Args:  cobra.ExactArgs(1),
	RunE:  runOsintBreachForumSearch,
}

func init() {
	rootCmd.AddCommand(osintCmd)
	osintCmd.AddCommand(osintUsernameCmd)
	osintCmd.AddCommand(osintBSSIDCmd)
	osintCmd.AddCommand(osintBreachForumCmd)

	osintUsernameCmd.Flags().StringSliceP("sites", "s", []string{}, "Specific sites to check (comma-separated)")
	osintUsernameCmd.Flags().BoolP("fuzzy", "f", false, "Enable fuzzy validation mode")
	osintUsernameCmd.Flags().IntP("max_tasks", "m", 50, "Maximum concurrent tasks")

	osintBSSIDCmd.Flags().BoolP("all", "a", false, "Show all related results instead of exact match only")
	osintBSSIDCmd.Flags().BoolP("google", "g", false, "Include Google Maps URL for the location")
	osintBSSIDCmd.Flags().BoolP("osm", "o", false, "Include OpenStreetMap URL for the location")

	osintBreachForumCmd.Flags().IntP("max_hits", "m", 10, "Maximum number of hits to return")
}

func runOsintUsernameCheck(cmd *cobra.Command, args []string) error {
	apiKey, _ := cmd.Flags().GetString("api-key")
	cfg := config.New().WithAPIKey(apiKey)

	c, err := client.New(cfg)
	if err != nil {
		return err
	}

	params := &models.USRSXParams{
		Username: args[0],
	}
	params.Sites, _ = cmd.Flags().GetStringSlice("sites")
	params.Fuzzy, _ = cmd.Flags().GetBool("fuzzy")
	params.MaxTasks, _ = cmd.Flags().GetInt("max_tasks")

	err = c.CheckUsernameStream(params, func(result json.RawMessage) error {
		fmt.Println(string(result))
		return nil
	})

	if err != nil {
		return err
	}

	return nil
}

func runOsintBSSIDLookup(cmd *cobra.Command, args []string) error {
	apiKey, _ := cmd.Flags().GetString("api-key")
	cfg := config.New().WithAPIKey(apiKey)

	c, err := client.New(cfg)
	if err != nil {
		return err
	}

	params := &models.BSSIDParams{
		BSSID: args[0],
	}
	params.All, _ = cmd.Flags().GetBool("all")
	params.Google, _ = cmd.Flags().GetBool("google")
	params.OSM, _ = cmd.Flags().GetBool("osm")

	response, err := c.LookupBSSID(params)
	if err != nil {
		return err
	}

	return utils.PrintJSON(response)
}

func runOsintBreachForumSearch(cmd *cobra.Command, args []string) error {
	apiKey, _ := cmd.Flags().GetString("api-key")
	cfg := config.New().WithAPIKey(apiKey)

	c, err := client.New(cfg)
	if err != nil {
		return err
	}

	params := &models.BreachForumSearchParams{
		Search: args[0],
	}
	params.MaxHits, _ = cmd.Flags().GetInt("max_hits")

	response, err := c.SearchBreachForum(params)
	if err != nil {
		return err
	}

	return utils.PrintJSON(response)
}