diff --git a/main.go b/main.go index 21086ec..2bf09d4 100644 --- a/main.go +++ b/main.go @@ -1,28 +1,30 @@ package main import ( - "strings" - "fmt" + "bufio" "flag" + "fmt" "os" - "bufio" + "strings" - printing "github.com/hahwul/gitls/pkg/printing" - module "github.com/hahwul/gitls/pkg/modules" model "github.com/hahwul/gitls/pkg/model" + module "github.com/hahwul/gitls/pkg/modules" + printing "github.com/hahwul/gitls/pkg/printing" ) -func main(){ - list := flag.String("l","","List of targets (e.g -l sample.lst)") - output := flag.String("o","","write output file (optional)") - version := flag.Bool("version",false,"version of gitls") - proxy := flag.String("proxy","","using custom proxy") - useTor := flag.Bool("tor",false,"using tor proxy / localhost:9050") +func main() { + list := flag.String("l", "", "List of targets (e.g -l sample.lst)") + output := flag.String("o", "", "write output file (optional)") + version := flag.Bool("version", false, "version of gitls") + proxy := flag.String("proxy", "", "using custom proxy") + useTor := flag.Bool("tor", false, "using tor proxy / localhost:9050") + includeAccount := flag.Bool("include-account", false, "include repo of account in targeet") flag.Parse() options := model.Options{ - Proxy: *proxy, - UseTor: *useTor, - Output: *output, + Proxy: *proxy, + UseTor: *useTor, + Output: *output, + IncludeAccount: *includeAccount, } if *version { fmt.Println(printing.VERSION) @@ -34,7 +36,10 @@ func main(){ for sc.Scan() { line := strings.ToLower(sc.Text()) if line != "" { - checkURL(line, options) + module.CheckURL(line, options) + } + if *includeAccount { + module.CheckAccount(line, options) } } } else { @@ -42,20 +47,11 @@ func main(){ _ = err for i, v := range target { _ = i - checkURL(v, options) - } - } -} -func checkURL(s string, options model.Options) { - str := strings.Split(s,"/") - size := len(str) // 4 is user/org , 5 is repository - if size == 4 { - if strings.Contains(str[2],"github") { - module.GetRepoListFromUser(str[3], str[2], options) - } else if strings.Contains(str[2], "gitlab") { - // TODO gitlab getting repos + module.CheckURL(v, options) + if *includeAccount { + module.CheckAccount(v, options) + } } - } else if size == 5 { - fmt.Println(s) + } } diff --git a/pkg/model/model.go b/pkg/model/model.go index d0d990d..6ed537c 100644 --- a/pkg/model/model.go +++ b/pkg/model/model.go @@ -1,7 +1,8 @@ package model type Options struct { - Proxy string - UseTor bool - Output string + Proxy string + UseTor bool + Output string + IncludeAccount bool } diff --git a/pkg/modules/check.go b/pkg/modules/check.go new file mode 100644 index 0000000..44e72f2 --- /dev/null +++ b/pkg/modules/check.go @@ -0,0 +1,38 @@ +package modules + +import ( + "fmt" + "strings" + + "github.com/hahwul/gitls/pkg/model" +) + +// CheckAccount is repo list of accounts in target +func CheckAccount(s string, options model.Options) { + str := strings.Split(s, "/") + size := len(str) // 4 is user/org , 5 is repository + if size == 4 { + if strings.Contains(str[2], "github") { + GetRepoListFromIncludeAccount(str[3], str[2], options) + } else if strings.Contains(str[2], "gitlab") { + // TODO gitlab getting repos + } + } else if size == 5 { + fmt.Println(s) + } +} + +// CheckURL is repo list of target +func CheckURL(s string, options model.Options) { + str := strings.Split(s, "/") + size := len(str) // 4 is user/org , 5 is repository + if size == 4 { + if strings.Contains(str[2], "github") { + GetRepoListFromUser(str[3], str[2], options) + } else if strings.Contains(str[2], "gitlab") { + // TODO gitlab getting repos + } + } else if size == 5 { + fmt.Println(s) + } +} diff --git a/pkg/modules/github.go b/pkg/modules/github.go index b912f20..ce92a3e 100644 --- a/pkg/modules/github.go +++ b/pkg/modules/github.go @@ -1,11 +1,11 @@ package modules import ( + "encoding/json" "fmt" + "io/ioutil" "net/http" "time" - "io/ioutil" - "encoding/json" model "github.com/hahwul/gitls/pkg/model" transport "github.com/hahwul/gitls/pkg/transport" @@ -13,16 +13,53 @@ import ( // GithubObject is json object of github api type GithubObject struct { - Html_URL string `"json:html_url"` - Fork bool `"json:fork"` + URL string `json:"html_url"` + Fork bool `json:"fork"` +} + +// GetRepoListFromIncludeAccount is get repo list from account of org +func GetRepoListFromIncludeAccount(user, repoHost string, options model.Options) { + check := true + for i := 1; check; i++ { + apiAddress := fmt.Sprintf("https://api."+repoHost+"/orgs/%v/members?page=%v&per_page=100", user, i) + req, err := http.NewRequest("GET", apiAddress, nil) + transport := transport.GetTransport(options) + client := &http.Client{ + Timeout: 5 * time.Second, + Transport: transport, + } + + resp, err := client.Do(req) + if err != nil { + + } + + defer resp.Body.Close() + data, err := ioutil.ReadAll(resp.Body) + if err != nil { + panic(err) + } + if string(data) == "[]" { + check = false + } + var objects []GithubObject + json.Unmarshal(data, &objects) + for k, v := range objects { + _ = k + if !v.Fork { + fmt.Println(v.URL) + CheckURL(v.URL, options) + } + } + } } // GetRepoListFromUser is gettting repo list from github -func GetRepoListFromUser(user,repoHost string, options model.Options){ +func GetRepoListFromUser(user, repoHost string, options model.Options) { check := true - for i:=1 ; check ; i++ { + for i := 1; check; i++ { apiAddress := fmt.Sprintf("https://api."+repoHost+"/users/%v/repos?page=%v&per_page=100", user, i) - req, err := http.NewRequest("GET",apiAddress,nil) + req, err := http.NewRequest("GET", apiAddress, nil) transport := transport.GetTransport(options) client := &http.Client{ Timeout: 5 * time.Second, @@ -30,7 +67,7 @@ func GetRepoListFromUser(user,repoHost string, options model.Options){ } resp, err := client.Do(req) - if err != nil { + if err != nil { } @@ -43,11 +80,11 @@ func GetRepoListFromUser(user,repoHost string, options model.Options){ check = false } var objects []GithubObject - json.Unmarshal(data,&objects) + json.Unmarshal(data, &objects) for k, v := range objects { _ = k if !v.Fork { - fmt.Println(v.Html_URL) + fmt.Println(v.URL) } } } diff --git a/pkg/modules/modules b/pkg/modules/modules deleted file mode 100755 index 8316c09..0000000 Binary files a/pkg/modules/modules and /dev/null differ