-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(search): username - check status
snoop through usernames atleast for the websites that tells if the username exists by status or not closes #29
- Loading branch information
1 parent
c2dd777
commit 7625bf1
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} | ||
} |