def collect(self, collectors): collected = [] if self.args.username: Helpers.print_success("Collecting information for {}".format( self.args.username)) collected = self.collect_users(self.args.username, collectors) elif self.args.organization: Helpers.print_success("Collecting information for {}".format( self.args.organization)) collected = self.collect_organizations(self.args.organization, collectors) if not collected: Helpers.print_error("gitmails: Could not collect any information") return False return collected
def check_email(self, email): try: url = "{}/{}?{}".format(self.base_url, email, self.url_parameters) r = requests.get(url) if r.status_code == 503: Helpers.print_error( "hibp: IP got in DDoS protection by CloudFare") elif r.status_code == 429: Helpers.print_error("hibp: Throttled by HIBP API") elif r.text: r = r.json() print("\n{} leaks:".format(email)) for leak in r: print("\t- {}".format(leak["Name"])) return True return False except Exception as e: Helpers.print_error(e) return False
def parse_commits(self, request_result): return set([Helpers().parse_git_author(commit["author"]["raw"]) for commit in request_result if request_result])
def set_authors(self, repos): if self.args.verbose: Helpers().print_success("Collecting authors") return GitUtils(self.args).set_repos_authors(repos)
def print_repos(self, repos, indentation=0): if not repos: Helpers().print_error(self.indent("No repositories", (indentation + 4))) for repo in repos: self.print_repo(repo, indentation=(indentation + 4)) self.print_authors(repo.authors, indentation=(indentation + 8))
def __init__(self, args): self.args = args Helpers.ensure_dir(self.args.path)
def get_repo_authors_by_url(self, repo_url): Helpers.print_success("Clonning {}".format(repo_url)) self.clone_repo_by_url(repo_url) return self.get_authors(self.get_repo_path_by_url(repo_url))
def main(): collected = Gitmails(args).execute() if not args.no_cleanup: Helpers.cleanup(args.path)
) parser.add_argument( "-v", "--verbose", help="Increase verbosity level", action="store_true" ) print_group = parser.add_mutually_exclusive_group(required=False) print_group.add_argument( "--raw", help="Print raw results separated by comma", action="store_true" ) print_group.add_argument( "--include-repositories", help="Print emails and repositories relation", action="store_true", ) args = parser.parse_args() def main(): collected = Gitmails(args).execute() if not args.no_cleanup: Helpers.cleanup(args.path) if __name__ == "__main__": try: main() except KeyboardInterrupt: Helpers.cleanup(args.path) print("\nQuiting...") sys.exit(1)
help="Do not delete the repositories after analysis", action="store_true") parser.add_argument("-v", "--verbose", help="Increase verbosity level", action="store_true") print_group = parser.add_mutually_exclusive_group(required=False) print_group.add_argument("--raw", help="Print raw results separated by comma", action="store_true") print_group.add_argument("--include-repositories", help="Print emails and repositories relation", action="store_true") args = parser.parse_args() def main(): collected = Gitmails(args).execute() if not args.no_cleanup: Helpers().cleanup(args.path) if __name__ == '__main__': try: main() except KeyboardInterrupt: Helpers().cleanup(args.path) print("\nQuiting...") sys.exit(1)
def get_userid(self, username): url = "{}/users?username={}".format(self.base_url, username) result = Helpers().request(url) if result: return result[0]["id"] return False
def get_collected_authors(self, collection): all_authors = [] if collection: for c in collection: all_authors.append(self.get_authors(c)) return set(Helpers.flatten(all_authors))
def get_authors(self, target): authors = [] if target: for repo in target.repositories: authors.append(repo.authors) return set(Helpers.flatten(authors))
def all_unique_emails(self, collection): all_emails = [] if collection: for c in collection: all_emails.append(self.unique_emails(c)) return set(Helpers.flatten(all_emails))