2025-05-14 22:00:38 -04:00
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2025-05-17 10:00:59 -04:00
|
|
|
|
"crowsnest/internal/badger"
|
2025-05-14 22:00:38 -04:00
|
|
|
|
"fmt"
|
2025-05-17 10:00:59 -04:00
|
|
|
|
"github.com/fatih/color"
|
2025-05-14 22:00:38 -04:00
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
"os"
|
2025-05-15 15:08:32 -04:00
|
|
|
|
"strings"
|
2025-05-14 22:00:38 -04:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
// Global Flags
|
2025-05-16 15:33:29 -04:00
|
|
|
|
debugGlobal bool
|
2025-05-14 22:00:38 -04:00
|
|
|
|
|
|
|
|
|
|
// rootCmd is the base command for the CLI.
|
|
|
|
|
|
rootCmd = &cobra.Command{
|
2025-05-22 10:47:10 -04:00
|
|
|
|
Use: "crowsnest",
|
|
|
|
|
|
Short: `CrowsNest is a cli tool for querying the common OSINT api's.`,
|
2025-05-14 22:00:38 -04:00
|
|
|
|
Long: fmt.Sprintf(
|
2025-05-17 10:00:59 -04:00
|
|
|
|
"%s\n",
|
2025-05-14 22:00:38 -04:00
|
|
|
|
`
|
2025-05-17 10:25:16 -04:00
|
|
|
|
╔═╗┬─┐┌─┐┬ ┬┌─┐╔╗╔┌─┐┌─┐┌┬┐
|
|
|
|
|
|
║ ├┬┘│ ││││└─┐║║║├┤ └─┐ │
|
|
|
|
|
|
╚═╝┴└─└─┘└┴┘└─┘╝╚╝└─┘└─┘ ┴
|
2025-05-17 10:00:59 -04:00
|
|
|
|
|
2025-05-17 10:25:16 -04:00
|
|
|
|
Crow’s Nest OSINT Recon Suite
|
|
|
|
|
|
⚓ A KrakenTech Intelligence Tool
|
2025-05-14 22:00:38 -04:00
|
|
|
|
`,
|
|
|
|
|
|
),
|
2025-05-16 20:21:36 -04:00
|
|
|
|
Version: "v1.2.1",
|
2025-05-14 22:00:38 -04:00
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
|
|
|
|
func Execute() {
|
|
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
|
|
|
|
zap.L().Fatal("execute_root_command",
|
|
|
|
|
|
zap.String("message", "failed to execute root command"),
|
|
|
|
|
|
zap.Error(err),
|
|
|
|
|
|
)
|
|
|
|
|
|
fmt.Printf("[!] %v", err)
|
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
// Hide the default help command
|
|
|
|
|
|
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
|
|
|
|
|
|
2025-05-16 15:33:29 -04:00
|
|
|
|
// Add global flags
|
2025-05-16 20:21:36 -04:00
|
|
|
|
rootCmd.PersistentFlags().BoolVar(&debugGlobal, "debug", false, "Show debug information")
|
2025-05-15 15:35:02 -04:00
|
|
|
|
|
2025-05-14 22:00:38 -04:00
|
|
|
|
// Add subcommands
|
2026-04-07 09:09:12 -04:00
|
|
|
|
rootCmd.AddCommand(setCmd)
|
2025-05-15 15:08:32 -04:00
|
|
|
|
rootCmd.AddCommand(setLocalDb)
|
2025-05-17 10:00:59 -04:00
|
|
|
|
rootCmd.AddCommand(buyMeCoffeeCmd)
|
2026-04-07 09:09:12 -04:00
|
|
|
|
|
|
|
|
|
|
setCmd.AddCommand(setDehashedKeyCmd)
|
|
|
|
|
|
setCmd.AddCommand(setHunterKeyCmd)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var setCmd = &cobra.Command{
|
|
|
|
|
|
Use: "set",
|
|
|
|
|
|
Short: "Set CrowsNest configuration values",
|
|
|
|
|
|
Long: "Set CrowsNest configuration values such as API keys.",
|
2025-05-14 22:00:38 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Command to set API key
|
2025-05-16 23:46:55 -04:00
|
|
|
|
var setDehashedKeyCmd = &cobra.Command{
|
2026-04-07 09:09:12 -04:00
|
|
|
|
Use: "dehashed [key]",
|
2025-05-16 23:46:55 -04:00
|
|
|
|
Short: "Set and store Dehashed.com API key",
|
2025-05-14 22:00:38 -04:00
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
key := args[0]
|
|
|
|
|
|
// Store key in badger DB
|
2025-05-16 23:46:55 -04:00
|
|
|
|
err := storeDehashedApiKey(key)
|
2025-05-14 22:00:38 -04:00
|
|
|
|
if err != nil {
|
2025-05-16 23:46:55 -04:00
|
|
|
|
fmt.Printf("Error storing Dehashed API key: %v\n", err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
fmt.Println("API key stored successfully")
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var setHunterKeyCmd = &cobra.Command{
|
2026-04-07 09:09:12 -04:00
|
|
|
|
Use: "hunter [key]",
|
2025-05-16 23:46:55 -04:00
|
|
|
|
Short: "Set and store Hunter.io API key",
|
|
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
key := args[0]
|
|
|
|
|
|
// Store key in badger DB
|
|
|
|
|
|
err := storeHunterApiKey(key)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Printf("Error storing Hunter API key: %v\n", err)
|
2025-05-14 22:00:38 -04:00
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
fmt.Println("API key stored successfully")
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-15 15:08:32 -04:00
|
|
|
|
var setLocalDb = &cobra.Command{
|
2025-05-15 15:35:02 -04:00
|
|
|
|
Use: "local-db [true|false]",
|
2025-05-22 10:47:10 -04:00
|
|
|
|
Short: "Set crowsnest to use a local database path instead of the default path",
|
2025-05-15 15:08:32 -04:00
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2025-05-15 15:35:02 -04:00
|
|
|
|
var useLocalDatabase bool
|
|
|
|
|
|
|
2025-05-15 15:08:32 -04:00
|
|
|
|
useLocal := strings.ToLower(args[0])
|
|
|
|
|
|
|
|
|
|
|
|
if useLocal == "true" {
|
|
|
|
|
|
useLocalDatabase = true
|
|
|
|
|
|
} else if useLocal == "false" {
|
|
|
|
|
|
useLocalDatabase = false
|
|
|
|
|
|
} else {
|
|
|
|
|
|
fmt.Println("Invalid argument. Please use 'true' or 'false'.")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Store useLocal in badger DB
|
|
|
|
|
|
err := badger.StoreUseLocalDB(useLocalDatabase)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Printf("Error storing local database useLocal: %v\n", err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
fmt.Println("Local database useLocal stored successfully")
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-17 10:00:59 -04:00
|
|
|
|
var buyMeCoffeeCmd = &cobra.Command{
|
|
|
|
|
|
Use: "coffee",
|
|
|
|
|
|
Short: "Support the project by buying a coffee",
|
|
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2025-05-17 10:25:16 -04:00
|
|
|
|
fmt.Println(color.HiRedString(" ;)(; "))
|
2025-05-17 10:00:59 -04:00
|
|
|
|
fmt.Println(color.HiCyanString(" We Hope You Enjoy Our Product :----:"))
|
|
|
|
|
|
fmt.Println(color.HiCyanString(" C|====|"))
|
|
|
|
|
|
fmt.Println(color.HiCyanString(" | |"))
|
|
|
|
|
|
fmt.Print(color.HiGreenString(" Support the project by buying a coffee: "))
|
|
|
|
|
|
fmt.Print(color.BlueString("https://buymeacoffee.com/ehosinskiz "))
|
|
|
|
|
|
fmt.Println(color.HiCyanString("`----'"))
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-14 22:00:38 -04:00
|
|
|
|
// Helper functions to store API credentials
|
2025-05-16 23:46:55 -04:00
|
|
|
|
func storeDehashedApiKey(key string) error {
|
|
|
|
|
|
err := badger.StoreDehashedKey(key)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Printf("Error storing API key: %v\n", err)
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func storeHunterApiKey(key string) error {
|
|
|
|
|
|
err := badger.StoreHunterKey(key)
|
2025-05-14 22:00:38 -04:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Printf("Error storing API key: %v\n", err)
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|