forked from j3ssie/metabigor
/
ip.go
102 lines (86 loc) · 2.4 KB
/
ip.go
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
package cmd
import (
"fmt"
"os"
"strings"
"sync"
"github.com/j3ssie/metabigor/core"
"github.com/j3ssie/metabigor/modules"
"github.com/spf13/cobra"
)
func init() {
var ipCmd = &cobra.Command{
Use: "ip",
Short: "IP OSINT Search",
Long: fmt.Sprintf(`Metabigor - Intelligence Tool but without API key - %v by %v`, core.VERSION, core.AUTHOR),
RunE: runIP,
}
ipCmd.Flags().StringP("source", "s", "all", "Search Engine Select")
ipCmd.Flags().StringSliceP("query", "q", []string{}, "Query to search (Multiple -q flags are accepted)")
RootCmd.AddCommand(ipCmd)
}
func runIP(cmd *cobra.Command, _ []string) error {
options.Search.Source, _ = cmd.Flags().GetString("source")
options.Search.Source = strings.ToLower(options.Search.Source)
options.Search.More, _ = cmd.Flags().GetBool("brute")
options.Search.Optimize, _ = cmd.Flags().GetBool("optimize")
queries, _ := cmd.Flags().GetStringSlice("query")
var inputs []string
if options.Input != "-" && options.Input != "" {
if strings.Contains(options.Input, "\n") {
inputs = strings.Split(options.Input, "\n")
} else {
inputs = append(inputs, options.Input)
}
}
if len(queries) > 0 {
inputs = append(inputs, queries...)
}
if len(inputs) == 0 {
core.ErrorF("No input found")
os.Exit(1)
}
if options.Search.More {
inputs = addMoreQuery(inputs, options)
}
var wg sync.WaitGroup
jobs := make(chan string)
for i := 0; i < options.Concurrency; i++ {
wg.Add(1)
go func() {
defer wg.Done()
// do real stuff here
for job := range jobs {
searchResult := runIPSingle(job, options)
StoreData(searchResult, options)
}
}()
}
for _, input := range inputs {
jobs <- input
}
close(jobs)
wg.Wait()
if !core.FileExists(options.Output) {
core.ErrorF("No data found")
}
core.DebugF("Unique Output: %v", options.Output)
core.Unique(options.Output)
return nil
}
func runIPSingle(input string, options core.Options) []string {
var data []string
core.BannerF(fmt.Sprintf("Search on %v for: ", options.Search.Source), input)
if options.Search.Source == "all" {
options.Search.Source = "ony,shodan,trails"
}
options.Search.Query = input
// select source
if strings.Contains(options.Search.Source, "ony") {
data = append(data, modules.Onyphe(options.Search.Query, options)...)
}
if strings.Contains(options.Search.Source, "sho") {
data = append(data, modules.Shodan(options.Search.Query, options)...)
}
return data
}