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" "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 } output, err := json.MarshalIndent(response, "", " ") if err != nil { return fmt.Errorf("failed to format response: %w", err) } fmt.Println(string(output)) return nil } 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 } output, err := json.MarshalIndent(response, "", " ") if err != nil { return fmt.Errorf("failed to format response: %w", err) } fmt.Println(string(output)) return nil }