import requests
import re
import time
import os
# === Configuration ===
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") # Set this via Replit's Secrets tab
HEADERS = {"Authorization": f"token {GITHUB_TOKEN}"}
KEYWORDS = [
"api_key",
"secret",
".env",
"password",
"AWS_SECRET_ACCESS_KEY",
"DATABASE_URL",
"PRIVATE_KEY"
]
SEARCH_URL = "https://api.github.com/search/code"
RESULTS_PER_PAGE = 5
def search_github(keyword, page=1):
params = {
"q": f"{keyword} in:file",
"per_page": RESULTS_PER_PAGE,
"page": page
}
response = requests.get(SEARCH_URL, headers=HEADERS, params=params)
if response.status_code == 200:
return response.json()
else:
print(f"Error: {response.status_code} - {response.text}")
return None
def extract_info(item):
repo_name = item['repository']['full_name']
file_path = item['path']
html_url = item['html_url']
return f"Repo: {repo_name}\nFile: {file_path}\nURL: {html_url}\n"
def main():
print("Starting GitHub API Key Scanner...\n")
for keyword in KEYWORDS:
print(f"🔍 Searching: {keyword}")
results = search_github(keyword)
if results and 'items' in results:
for item in results['items']:
print(extract_info(item))
time.sleep(2) # Respect GitHub rate limits
if __name__ == "__main__":
main()