summaryrefslogtreecommitdiffstats
path: root/cmd/osint.go
blob: 4f459ad7652649d32f1a8469c077ddd7019ed9c4 (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
package cmd

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

	"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,
}

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

	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("map", "m", false, "Include Google Maps URL for the location")
}

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.Map, _ = cmd.Flags().GetBool("map")

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

	output, err := json.MarshalIndent(response, "", "  ")
	if err != nil {
		return fmt.Errorf("failed to format response: %w", err)
	}

	fmt.Println(string(output))
	return nil
}