mirror of
https://github.com/anotherhadi/github-recon.git
synced 2026-10-05 10:58:25 +02:00
+25
-21
@@ -13,13 +13,6 @@ import (
|
|||||||
"github.com/google/go-github/v72/github"
|
"github.com/google/go-github/v72/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
func folderExists(path string) bool {
|
|
||||||
if stat, err := os.Stat(path); err == nil && stat.IsDir() {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
type AuthorOccurrence struct {
|
type AuthorOccurrence struct {
|
||||||
Name string
|
Name string
|
||||||
Email string
|
Email string
|
||||||
@@ -31,6 +24,19 @@ type EmailOccurrence struct {
|
|||||||
FoundIn []string
|
FoundIn []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DeepResult struct {
|
||||||
|
Repositories []Repositorie
|
||||||
|
Authors []AuthorOccurrence
|
||||||
|
Emails []EmailOccurrence
|
||||||
|
}
|
||||||
|
|
||||||
|
type Repositorie struct {
|
||||||
|
Repository string
|
||||||
|
Owner string
|
||||||
|
Name string
|
||||||
|
Size int
|
||||||
|
}
|
||||||
|
|
||||||
func findEmailsAndOccurrencesInDir(rootPath string) ([]EmailOccurrence, error) {
|
func findEmailsAndOccurrencesInDir(rootPath string) ([]EmailOccurrence, error) {
|
||||||
emailLocations := make(map[string]map[string]bool)
|
emailLocations := make(map[string]map[string]bool)
|
||||||
emailRegex := regexp.MustCompile(`[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}`)
|
emailRegex := regexp.MustCompile(`[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}`)
|
||||||
@@ -87,14 +93,8 @@ func findEmailsAndOccurrencesInDir(rootPath string) ([]EmailOccurrence, error) {
|
|||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeepResult struct {
|
func (r Recon) Deep(username, excludeRepos string, refresh bool) (response DeepResult) {
|
||||||
Repository string
|
repositories := []Repositorie{}
|
||||||
Owner string
|
|
||||||
Name string
|
|
||||||
Size int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Recon) Deep(username, excludeRepos string, refresh bool) (response []DeepResult) {
|
|
||||||
excludeReposList := strings.Split(excludeRepos, ",")
|
excludeReposList := strings.Split(excludeRepos, ",")
|
||||||
repos, resp, err := r.Client.Repositories.ListByUser(
|
repos, resp, err := r.Client.Repositories.ListByUser(
|
||||||
r.Ctx,
|
r.Ctx,
|
||||||
@@ -134,7 +134,7 @@ func (r Recon) Deep(username, excludeRepos string, refresh bool) (response []Dee
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
response = append(response, DeepResult{
|
repositories = append(repositories, Repositorie{
|
||||||
Repository: repo.GetCloneURL(),
|
Repository: repo.GetCloneURL(),
|
||||||
Owner: repo.GetOwner().GetLogin(),
|
Owner: repo.GetOwner().GetLogin(),
|
||||||
Name: repo.GetName(),
|
Name: repo.GetName(),
|
||||||
@@ -162,7 +162,7 @@ func (r Recon) Deep(username, excludeRepos string, refresh bool) (response []Dee
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, repo := range response {
|
for _, repo := range repositories {
|
||||||
destination := tmp_folder + "/" + repo.Owner + "/" + repo.Name
|
destination := tmp_folder + "/" + repo.Owner + "/" + repo.Name
|
||||||
if folderExists(destination) {
|
if folderExists(destination) {
|
||||||
r.PrintInfo("INFO", "Directory already downloaded, skipping "+repo.Owner+"/"+repo.Name)
|
r.PrintInfo("INFO", "Directory already downloaded, skipping "+repo.Owner+"/"+repo.Name)
|
||||||
@@ -198,7 +198,7 @@ func (r Recon) Deep(username, excludeRepos string, refresh bool) (response []Dee
|
|||||||
|
|
||||||
authorOccurrences := []AuthorOccurrence{}
|
authorOccurrences := []AuthorOccurrence{}
|
||||||
mapAuthorToIndex := make(map[string]int)
|
mapAuthorToIndex := make(map[string]int)
|
||||||
for _, repo := range response {
|
for _, repo := range repositories {
|
||||||
destination := tmp_folder + "/" + repo.Owner + "/" + repo.Name
|
destination := tmp_folder + "/" + repo.Owner + "/" + repo.Name
|
||||||
if !folderExists(filepath.Join(destination, ".git")) {
|
if !folderExists(filepath.Join(destination, ".git")) {
|
||||||
r.Logger.Error(
|
r.Logger.Error(
|
||||||
@@ -275,21 +275,25 @@ func (r Recon) Deep(username, excludeRepos string, refresh bool) (response []Dee
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.PrintInfo("INFO", "Now searching for emails in cloned repositories, this may take a while...")
|
r.PrintInfo("INFO", "Now searching for emails in cloned repositories, this may take a while...")
|
||||||
results, err := findEmailsAndOccurrencesInDir(tmp_folder)
|
emails, err := findEmailsAndOccurrencesInDir(tmp_folder)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Logger.Error("Failed to find emails in directory", "err", err)
|
r.Logger.Error("Failed to find emails in directory", "err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(results) == 0 {
|
if len(emails) == 0 {
|
||||||
r.PrintInfo("INFO", "No emails found")
|
r.PrintInfo("INFO", "No emails found")
|
||||||
} else {
|
} else {
|
||||||
r.PrintInfo("INFO", "Found emails:")
|
r.PrintInfo("INFO", "Found emails:")
|
||||||
for _, email := range results {
|
for _, email := range emails {
|
||||||
r.PrintInfo("Email", email.Email, "found in:"+strings.Join(email.FoundIn, ", "))
|
r.PrintInfo("Email", email.Email, "found in:"+strings.Join(email.FoundIn, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.Repositories = repositories
|
||||||
|
response.Authors = authorOccurrences
|
||||||
|
response.Emails = emails
|
||||||
|
|
||||||
r.PrintNewline()
|
r.PrintNewline()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,3 +165,11 @@ func (r Recon) WriteJson(data any) {
|
|||||||
}
|
}
|
||||||
r.PrintInfo("INFO", "JSON file created successfully", "file", r.JsonFile)
|
r.PrintInfo("INFO", "JSON file created successfully", "file", r.JsonFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func folderExists(path string) bool {
|
||||||
|
if stat, err := os.Stat(path); err == nil && stat.IsDir() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user