-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Nhoya/develop
v0.4
- Loading branch information
Showing
11 changed files
with
379 additions
and
86 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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
language: go | ||
|
||
go: | ||
- 1.8.x | ||
- master | ||
|
||
os: | ||
|
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
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
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
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,103 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/deckarep/golang-set" | ||
"gopkg.in/src-d/go-git.v4" | ||
"gopkg.in/src-d/go-git.v4/plumbing/object" | ||
"gopkg.in/src-d/go-git.v4/storage/memory" | ||
) | ||
|
||
func gitSearch(target string, WebsiteAPI string, mailSet mapset.Set) mapset.Set { | ||
// TODO: add worker for pagination | ||
domain := "" | ||
targetSplit := strings.Split(target, "/") | ||
commits := "" | ||
|
||
fmt.Println("==== GIT SEARCH FOR " + target + " ==== ") | ||
|
||
//If using GitHub API | ||
if strings.Contains(target, "https://github.com") || WebsiteAPI == "github" { | ||
fmt.Println("[+] Using github API") | ||
domain = targetSplit[0] + "//api." + targetSplit[2] + "/repos/" + targetSplit[3] + "/" + targetSplit[4] + "/commits?per_page=100" | ||
//GitHub Pagination | ||
lastPage := retriveLastGHPage(domain) | ||
fmt.Println("[+] Looping through pages.This MAY take a while...") | ||
for page := 1; page < lastPage+1; page++ { | ||
fmt.Println("[+] Analyzing commits page: " + strconv.Itoa(page)) | ||
commits = retriveRequestBody(domain + "&page=" + strconv.Itoa(page)) | ||
findMailInText(commits, mailSet) | ||
} | ||
} else if strings.Contains(target, "https://bitbucket.org") || WebsiteAPI == "bitbucket" { | ||
// If using BitBucket API | ||
fmt.Println("[+] Using bitbucket API") | ||
domain = targetSplit[0] + "//api." + targetSplit[2] + "/2.0/repositories/" + targetSplit[3] + "/" + targetSplit[4] + "/commits?pagelen=100" | ||
//BitBucket Pagination | ||
page := 1 | ||
fmt.Println("[+] Looping through pages.This MAY take a while...") | ||
for page != 0 { | ||
fmt.Println("[+] Analyzing commits page: " + strconv.Itoa(page)) | ||
pageDom := domain + "&page=" + strconv.Itoa(page) | ||
//This is needed because we can't unluckily retrive max_page from one single request | ||
pageContent := retriveRequestBody(pageDom) | ||
nextPage := "\"next\": \"" + domain + "&page=" | ||
|
||
findMailInText(pageContent, mailSet) | ||
if strings.Contains(pageContent, nextPage) { | ||
page++ | ||
} else { | ||
page = 0 | ||
} | ||
} | ||
} else { | ||
commits = cloneAndSearchCommit(target) | ||
findMailInText(commits, mailSet) | ||
} | ||
|
||
//Check if the mailset has been populated (this avoids problems with mispelled repositories too) | ||
if mailSet == nil { | ||
fmt.Println("[-] Nothing Found") | ||
os.Exit(1) | ||
} | ||
fmt.Println("[+] Mails Found") | ||
readFromSet(mailSet) | ||
return mailSet | ||
} | ||
|
||
func retriveLastGHPage(domain string) int { | ||
req, err := http.Get(domain) | ||
if err != nil { | ||
panic(err) | ||
} | ||
pagInfo := req.Header.Get("Link") | ||
if pagInfo != "" { | ||
re := regexp.MustCompile(`page=(\d+)>;\srel="last"`) | ||
match := re.FindStringSubmatch(pagInfo) | ||
lastPage, _ := strconv.Atoi(match[1]) | ||
return lastPage | ||
} | ||
return 1 | ||
} | ||
|
||
func cloneAndSearchCommit(Url string) string { | ||
fmt.Println("[+] Cloning Repo") | ||
r, _ := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{ | ||
URL: Url, | ||
}) | ||
ref, _ := r.Head() | ||
cIter, _ := r.Log(&git.LogOptions{From: ref.Hash()}) | ||
|
||
commits := "" | ||
_ = cIter.ForEach(func(c *object.Commit) error { | ||
commits += fmt.Sprintf("%s", c.Author) | ||
return nil | ||
}) | ||
|
||
return commits | ||
} |
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
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
Oops, something went wrong.