-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
102 lines (86 loc) · 2.35 KB
/
main.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 main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"github.com/pwnosec/pwnshodo/apishodan"
)
const Author = "pwnosec"
func main() {
domain := flag.String("d", "", "> Domain to find subdomains")
shodanKey := flag.String("s", "", "> Shodan api key")
verbose := flag.Bool("v", false, "> Show all output")
fileName := flag.String("o", "", "> Save domains into a file")
inputFile := flag.String("f", "", "> File containing domains to find subdomains")
flag.Parse()
if *domain == "" && *inputFile == "" {
fmt.Printf("[*] Usage: %s -d target.com -s MYShodaNKey [-f input_file]\n", os.Args[0])
fmt.Printf("[*] Author: %s\n", Author)
os.Exit(1)
}
apiKey := apishodan.New(*shodanKey)
var domains []string
if *domain != "" {
// Use domain from command-line argument (-d)
domains = append(domains, *domain)
}
if *inputFile != "" {
// Read domains from file specified by -f flag
fileDomains, err := readDomainsFromFile(*inputFile)
if err != nil {
log.Fatalf("Failed to read domains from file: %v", err)
}
domains = append(domains, fileDomains...)
}
for _, domainSearch := range domains {
subdomain, err := apiKey.GetSubdomain(domainSearch)
if err != nil {
log.Panicln(err)
}
if *verbose == true {
info, err := apiKey.InfoAccount()
if err != nil {
log.Panicln(err)
}
fmt.Printf("[*] Credits: %d\nScan Credits: %d\n\n", info.QueryCredits, info.ScanCredits)
for _, v := range subdomain.Data {
d := v.SubD + subdomain.Domain
fmt.Printf("[*] Domain: %s\nIP/DNS: %s\nLast Scan made by Shodan: %s\n", d, v.Value, v.LastSeen)
}
} else {
for _, v := range subdomain.SubDomains {
if *fileName != "" {
f, err := os.OpenFile(*fileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer f.Close()
_, err = f.WriteString(v + "\n")
if err != nil {
log.Fatal(err)
}
fmt.Println("[*] DONE writing to file:", *fileName)
}
fmt.Printf("%s.%s\n", v, domainSearch)
}
}
}
}
func readDomainsFromFile(filename string) ([]string, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
var domains []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
domains = append(domains, scanner.Text())
}
if err := scanner.Err(); err != nil {
return nil, err
}
return domains, nil
}