Skip to content

Commit

Permalink
feat(search): username - check status
Browse files Browse the repository at this point in the history
snoop through usernames atleast for the websites that tells if the username exists by status or not

closes #29
  • Loading branch information
thechadgod committed Feb 14, 2022
1 parent c2dd777 commit 7625bf1
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
47 changes: 47 additions & 0 deletions cmd/search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
"github.com/thechadgod/snoopy/internal/helper/search"
)

var searchCmd = &cobra.Command{
Use: "search",
Short: "Use the web for osint searches",
Long: `
Use the web for osint searches.
`,
}

var usernameCmd = &cobra.Command{
Use: "username",
Aliases: []string{"u"},
Short: "Search for usernames",
Args: cobra.MinimumNArgs(1),
Long: `
Search for usernames.
`, Run: func(cmd *cobra.Command, args []string) {

username := args[0]

if priority, err := cmd.Flags().GetBool("priority"); err == nil {
search.Username(username, priority)
} else {
fmt.Println("Error: ", err)

}

},
}

func init() {

usernameCmd.Flags().BoolP("priority", "p", false, "Search only the priority sites")

searchCmd.AddCommand(usernameCmd)

rootCmd.AddCommand(searchCmd)

}
88 changes: 88 additions & 0 deletions internal/helper/search/username.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package search

import (
"fmt"
"net/http"
)

type Site struct {
Name string
URL string
Strategy string
BodyText string
RedirectLink string
Priority bool
}

type Result struct {
Name string
Status bool
Link string
}

const userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"

func checkStatus(username string, url string) (bool, string) {

req, _ := http.NewRequest("GET", fmt.Sprintf("%s%s", url, username), nil)
req.Header.Set("User-Agent", userAgent)

client := http.Client{}
res, err := client.Do(req)

if err != nil {
return false, ""
}

defer res.Body.Close()

// fmt.Println(res.StatusCode)

if condition := res.StatusCode == 200; condition {
usernameurl := fmt.Sprintf("%s%s", url, username)
return true, usernameurl
} else {
return false, ""
}
}

var sites = []Site{
{
Name: "github",
URL: "https://github.com/",
Strategy: "status",
BodyText: "", // if the strategy is status then no bodytext is required
RedirectLink: "", // if the strategy is status then no redirect link is required
Priority: true,
},
}

func Username(username string, priority bool) {

fmt.Println("\nSearching...")

var results = []Result{}

// check for websites
for _, site := range sites {
if site.Priority == priority {

switch expression := site.Strategy; expression {
case "status":
found, url := checkStatus(username, site.URL)
if found {
results = append(results, Result{Name: site.Name, Status: found, Link: url})
}

}
}
}

// loop through results
for _, result := range results {
if condition := result.Status; condition {
fmt.Printf("%s: %s\n", result.Name, result.Link)
}

}
}

0 comments on commit 7625bf1

Please sign in to comment.