111 lines
No EOL
3.7 KiB
Python
111 lines
No EOL
3.7 KiB
Python
import os
|
|
import argparse
|
|
import logging
|
|
from github import Github, Auth, GithubException
|
|
|
|
# Configure logging
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
def auth():
|
|
access_token = os.getenv("GITHUB_ACCESS_TOKEN")
|
|
if not access_token:
|
|
raise ValueError("GITHUB_ACCESS_TOKEN environment variable not set")
|
|
auth = Auth.Token(access_token)
|
|
g = Github(auth=auth)
|
|
return g
|
|
|
|
class GithubSearcher():
|
|
def __init__(self, query):
|
|
self.g = auth()
|
|
self.query = query
|
|
self.result = None
|
|
|
|
def search_repo(self):
|
|
try:
|
|
self.result = self.g.search_repositories(self.query)
|
|
except GithubException as e:
|
|
logging.error(f"Error searching repositories: {e}")
|
|
self.result = None
|
|
|
|
def search_users(self):
|
|
try:
|
|
self.result = self.g.search_users(self.query)
|
|
except GithubException as e:
|
|
logging.error(f"Error searching users: {e}")
|
|
self.result = None
|
|
|
|
def search_in_name(self):
|
|
try:
|
|
self.result = self.g.search_repositories('in:name ' + self.query)
|
|
except GithubException as e:
|
|
logging.error(f"Error searching in name: {e}")
|
|
self.result = None
|
|
|
|
def get_repo_open_issues(self, repo):
|
|
try:
|
|
return repo.get_issues(state='open')
|
|
except GithubException as e:
|
|
logging.error(f"Error getting open issues: {e}")
|
|
return None
|
|
|
|
def get_repo_contents(self, repo):
|
|
try:
|
|
contents = repo.get_contents("")
|
|
for content_file in contents:
|
|
print(content_file)
|
|
return contents
|
|
except GithubException as e:
|
|
logging.error(f"Error getting repository contents: {e}")
|
|
return None
|
|
|
|
def get_result(self):
|
|
return self.result
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Search GitHub repositories and users for PoC exploits and CVEs.")
|
|
parser.add_argument("--query", type=str, required=True, help="The search query.")
|
|
parser.add_argument("--search_type", type=str, required=True, choices=["repo", "users", "name"], help="The type of search to perform: 'repo', 'users', or 'name'.")
|
|
parser.add_argument("--get_file_contents", action="store_true", help="Get the contents of a repository.")
|
|
parser.add_argument("--get_open_issues", action="store_true", help="Get the open issues of a repository.")
|
|
args = parser.parse_args()
|
|
|
|
searcher = GithubSearcher(args.query)
|
|
|
|
if args.search_type == "repo":
|
|
searcher.search_repo()
|
|
elif args.search_type == "users":
|
|
searcher.search_users()
|
|
elif args.search_type == "name":
|
|
searcher.search_in_name()
|
|
|
|
result = searcher.get_result()
|
|
if result is None:
|
|
print("No results found.")
|
|
return
|
|
|
|
for item in result:
|
|
if args.search_type == "users":
|
|
user_repos = item.get_repos()
|
|
for repo in user_repos:
|
|
print(repo.html_url)
|
|
else:
|
|
print(item.html_url)
|
|
|
|
if args.get_open_issues:
|
|
issues = searcher.get_repo_open_issues(item)
|
|
if issues:
|
|
print("Open issues:")
|
|
for issue in issues:
|
|
print(f"Issue: {issue.title}")
|
|
print("\n")
|
|
|
|
if args.get_file_contents:
|
|
contents = searcher.get_repo_contents(item)
|
|
if contents:
|
|
print("Contents:")
|
|
for content in contents:
|
|
print(f"File: {content.path}")
|
|
print("\n")
|
|
|
|
if __name__ == "__main__":
|
|
main() |