Skip to content

Commit

Permalink
Merge pull request #12 from Vulnpire/master
Browse files Browse the repository at this point in the history
support for reading domains from a file thx @Vulnpire :)
  • Loading branch information
incogbyte authored Jun 9, 2024
2 parents 6e8d48c + a1a4f87 commit 6364965
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 34 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ go install github.com/incogbyte/shosubgo@latest

## Usage
```bash
go run main.go -d target.com -s YourAPIKEY
go run main.go -d target.com -s YourAPIKEY / go run main.go -f file -s YourAPIKEY
```
## Usage download from releases:

Expand All @@ -25,6 +25,7 @@ https://github.com/incogbyte/shosubgo/releases/tag/1.1
# From Download Releases

./shosubgo_linux -d target.com -s YourAPIKEY
./shosubgo_linux -f file -s YourAPIKEY
```

![shosubgo](https://raw.githubusercontent.com/incogbyte/shosubgo/master/shosubgo.png)
Expand Down
96 changes: 63 additions & 33 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bufio"
"flag"
"fmt"
"log"
Expand All @@ -16,57 +17,86 @@ func main() {
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 == "" || *shodanKey == "" {
fmt.Printf("[*] Usage %s -d target.com -s MYShodaNKey\n", os.Args[0])
fmt.Printf("[*] Author: %s \n\n thanks for using this tool =) PR are welcome \n", Author)
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)

domainSearch := *domain
var domains []string

subdomain, err := apiKey.GetSubdomain(domainSearch)
if err != nil {
log.Panicln(err)
if *domain != "" {
// Use domain from command-line argument (-d)
domains = append(domains, *domain)
}

if *verbose == true {

info, err := apiKey.InfoAccount()

if *inputFile != "" {
// Read domains from file specified by -f flag
fileDomains, err := readDomainsFromFile(*inputFile)
if err != nil {
log.Panicln(err)
log.Fatalf("Failed to read domains from file: %v", err)
}
domains = append(domains, fileDomains...)
}

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)
for _, domainSearch := range domains {
subdomain, err := apiKey.GetSubdomain(domainSearch)
if err != nil {
log.Panicln(err)
}

} else {
for _, v := range subdomain.SubDomains {
if *fileName != "" {
f, err := os.Create(*fileName)
if err != nil {
log.Fatal(err)
}

defer f.Close()
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)

_, err2 := f.WriteString(v + "\n")
if err2 != nil {
log.Fatal(err2)
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.Println("[*] DONE write files")
fmt.Printf("%s.%s\n", v, domainSearch)
}
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
}

0 comments on commit 6364965

Please sign in to comment.