mirror of
https://github.com/anotherhadi/github-recon.git
synced 2026-10-05 19:08:24 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66030c1c16 | ||
|
|
bb8f34055d | ||
|
|
26a1cfdd37 | ||
|
|
3064cdbf7a | ||
|
|
52f9f1f3e7 |
@@ -98,7 +98,7 @@ nix run github:anotherhadi/github-recon -- [--flags value] target_username_or_em
|
||||
|
||||
# then add it to your packages
|
||||
environment.systemPackages = with pkgs; [ # or home.packages
|
||||
github-recon
|
||||
inputs.github-recon.defaultPackage.${pkgs.system}
|
||||
];
|
||||
```
|
||||
|
||||
@@ -123,7 +123,7 @@ github-recon [--flags value] target_username_or_email
|
||||
--trufflehog Run trufflehog on cloned repositories (only for deep scan) (default true)
|
||||
-S, --silent Suppress all non-essential output
|
||||
--spoof-email Spoof email (only for email mode) (default true)
|
||||
-a, --hide-avatar Hide the avatar in the output
|
||||
-a, --print-avatar Show the avatar in the output
|
||||
-j, --json string Write results to specified JSON file
|
||||
```
|
||||
|
||||
|
||||
@@ -13,7 +13,11 @@ import (
|
||||
type CloseFriendsResult []CloseFriendResult
|
||||
|
||||
type CloseFriendResult struct {
|
||||
Name string
|
||||
Username string
|
||||
Orgs []string
|
||||
Company string
|
||||
Location string
|
||||
Score int
|
||||
}
|
||||
|
||||
@@ -96,8 +100,12 @@ func CloseFriends(s github_recon_settings.Settings) (results CloseFriendsResult)
|
||||
// Add candidate if they matched at least one condition
|
||||
if score > 0 {
|
||||
results = append(results, CloseFriendResult{
|
||||
Name: candidateDetails.GetName(),
|
||||
Username: candidateLogin,
|
||||
Orgs: candidateOrgsToNames(candidateOrgs),
|
||||
Score: score,
|
||||
Location: candidateDetails.GetLocation(),
|
||||
Company: candidateDetails.GetCompany(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -130,6 +138,15 @@ func checkIfUserFollows(s github_recon_settings.Settings, sourceUser, targetUser
|
||||
}
|
||||
return isFollowing, nil
|
||||
}
|
||||
func candidateOrgsToNames(orgs []*github.Organization) []string {
|
||||
var orgNames []string
|
||||
for _, org := range orgs {
|
||||
if org.GetLogin() != "" {
|
||||
orgNames = append(orgNames, org.GetLogin())
|
||||
}
|
||||
}
|
||||
return orgNames
|
||||
}
|
||||
|
||||
func getOrgs(s github_recon_settings.Settings, user string) ([]*github.Organization, error) {
|
||||
orgs, resp, err := s.Client.Organizations.List(s.Ctx, user, nil)
|
||||
|
||||
+44
-25
@@ -32,7 +32,7 @@ type Settings struct {
|
||||
Silent bool
|
||||
DeepScan bool
|
||||
MaxDistance int
|
||||
HideAvatar bool
|
||||
PrintAvatar bool
|
||||
SpoofEmail bool
|
||||
Trufflehog bool
|
||||
|
||||
@@ -42,7 +42,34 @@ type Settings struct {
|
||||
Ctx context.Context
|
||||
}
|
||||
|
||||
func GetDefaultSettings() Settings {
|
||||
return Settings{
|
||||
Token: "null",
|
||||
Target: "",
|
||||
TargetType: TargetUsername,
|
||||
ShowSource: false,
|
||||
Refresh: false,
|
||||
MaxRepoSize: 150,
|
||||
ExcludedRepos: []string{},
|
||||
JsonOutput: "",
|
||||
Silent: false,
|
||||
DeepScan: false,
|
||||
MaxDistance: 20,
|
||||
PrintAvatar: true,
|
||||
SpoofEmail: true,
|
||||
Trufflehog: true,
|
||||
|
||||
Client: github.NewClient(nil),
|
||||
Logger: log.NewWithOptions(os.Stderr, log.Options{
|
||||
ReportCaller: false,
|
||||
ReportTimestamp: false,
|
||||
}),
|
||||
Ctx: context.WithValue(context.Background(), github.SleepUntilPrimaryRateLimitResetWhenRateLimited, true),
|
||||
}
|
||||
}
|
||||
|
||||
func GetSettings() (settings Settings) {
|
||||
settings = GetDefaultSettings()
|
||||
//// Flag settings
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
|
||||
@@ -56,74 +83,66 @@ func GetSettings() (settings Settings) {
|
||||
flag.CommandLine.SortFlags = false
|
||||
|
||||
//// Flags
|
||||
flag.StringVarP(&settings.Token, "token", "t", "null", "Github personal access token (e.g. ghp_aaa...). Can also be set via GITHUB_RECON_TOKEN environment variable. You also need to set the token in $HOME/.config/github-recon/env file if you want to use this tool without passing the token every time.")
|
||||
flag.StringVarP(&settings.Token, "token", "t", settings.Token, "Github personal access token (e.g. ghp_aaa...). Can also be set via GITHUB_RECON_TOKEN environment variable. You also need to set the token in $HOME/.config/github-recon/env file if you want to use this tool without passing the token every time.")
|
||||
|
||||
// DeepScan
|
||||
flag.BoolVarP(&settings.DeepScan, "deepscan", "d", false, "Enable deep scan (clone repos, regex search, analyse licenses, etc.)")
|
||||
flag.BoolVarP(&settings.DeepScan, "deepscan", "d", settings.DeepScan, "Enable deep scan (clone repos, regex search, analyse licenses, etc.)")
|
||||
flag.IntVar(
|
||||
&settings.MaxRepoSize,
|
||||
"max-size",
|
||||
150,
|
||||
settings.MaxRepoSize,
|
||||
"Limit the size of repositories to scan (in MB) (only for deep scan)",
|
||||
)
|
||||
flag.StringSliceVarP(
|
||||
&settings.ExcludedRepos,
|
||||
"exclude-repo",
|
||||
"e",
|
||||
[]string{},
|
||||
settings.ExcludedRepos,
|
||||
"Exclude repos from deep scan (comma-separated list, only for deep scan)",
|
||||
)
|
||||
flag.BoolVarP(
|
||||
&settings.Refresh,
|
||||
"refresh",
|
||||
"r",
|
||||
false,
|
||||
settings.Refresh,
|
||||
"Refresh the cache (only for deep scan)",
|
||||
)
|
||||
flag.BoolVarP(
|
||||
&settings.ShowSource,
|
||||
"show-source",
|
||||
"s",
|
||||
false,
|
||||
settings.ShowSource,
|
||||
"Show where the information (authors, emails, etc) were found (only for deep scan)",
|
||||
)
|
||||
flag.IntVarP(
|
||||
&settings.MaxDistance,
|
||||
"max-distance",
|
||||
"m",
|
||||
20,
|
||||
settings.MaxDistance,
|
||||
"Maximum Levenshtein distance for matching usernames & emails (only for deep scan)",
|
||||
)
|
||||
flag.BoolVar(
|
||||
&settings.Trufflehog,
|
||||
"trufflehog",
|
||||
true,
|
||||
settings.Trufflehog,
|
||||
"Run trufflehog on cloned repositories (only for deep scan)",
|
||||
)
|
||||
|
||||
flag.BoolVarP(&settings.Silent, "silent", "S", false, "Suppress all non-essential output")
|
||||
flag.BoolVarP(&settings.SpoofEmail, "spoof-email", "", true, "Spoof email (only for email mode)")
|
||||
flag.BoolVarP(&settings.HideAvatar, "hide-avatar", "a", false, "Hide the avatar in the output")
|
||||
flag.StringVarP(&settings.JsonOutput, "json", "j", "", "Write results to specified JSON file")
|
||||
flag.BoolVarP(&settings.Silent, "silent", "S", settings.Silent, "Suppress all non-essential output")
|
||||
flag.BoolVarP(&settings.SpoofEmail, "spoof-email", "", settings.SpoofEmail, "Spoof email (only for email mode)")
|
||||
flag.BoolVarP(&settings.PrintAvatar, "print-avatar", "a", settings.PrintAvatar, "Show the avatar in the output")
|
||||
flag.StringVarP(&settings.JsonOutput, "json", "j", settings.JsonOutput, "Write results to specified JSON file")
|
||||
|
||||
//// Parse
|
||||
flag.Parse()
|
||||
|
||||
//// Setup
|
||||
settings.Client = github.NewClient(nil)
|
||||
settings.Logger = log.NewWithOptions(os.Stderr, log.Options{
|
||||
ReportCaller: false,
|
||||
ReportTimestamp: false,
|
||||
})
|
||||
settings.Ctx = context.WithValue(context.Background(), github.SleepUntilPrimaryRateLimitResetWhenRateLimited, true)
|
||||
|
||||
//// Tail
|
||||
nonFlagArgs := flag.Args()
|
||||
if len(nonFlagArgs) > 1 {
|
||||
settings.Logger.Error("Please provide only one target (username or email)")
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
} else if len(nonFlagArgs) < 1 {
|
||||
} else if len(nonFlagArgs) == 0 {
|
||||
settings.Logger.Error("Please provide a target (username or email)")
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
@@ -143,11 +162,11 @@ func GetSettings() (settings Settings) {
|
||||
}
|
||||
|
||||
// If token is not set via flag, get it from env
|
||||
if settings.Token == "null" {
|
||||
settings.Token = getToken()
|
||||
if settings.Token == "null" || settings.Token == "" {
|
||||
settings.Token = GetToken()
|
||||
}
|
||||
|
||||
if settings.Token == "null" {
|
||||
if settings.Token == "null" || settings.Token == "" {
|
||||
settings.Logger.Warn("No Github token provided. You might hit the rate limit. Check the help menu for more information.")
|
||||
} else {
|
||||
settings.Client = settings.Client.WithAuthToken(settings.Token)
|
||||
|
||||
+2
-1
@@ -9,7 +9,8 @@ import (
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
func getToken() string {
|
||||
// GetToken retrieves the GitHub token from the environment variable or config file
|
||||
func GetToken() string {
|
||||
token := os.Getenv("GITHUB_RECON_TOKEN")
|
||||
if token != "" {
|
||||
return token
|
||||
|
||||
+1
-1
@@ -143,7 +143,7 @@ func PrintTitle(silent bool, title string) {
|
||||
}
|
||||
|
||||
func PrintAvatar(settings github_recon_settings.Settings, url string) {
|
||||
if settings.HideAvatar || url == "" || settings.Silent {
|
||||
if !settings.PrintAvatar || url == "" || settings.Silent {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user