Skip to content

Commit 34e0912

Browse files
committed
Added .env for API key and updated request headers
1 parent faef84c commit 34e0912

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env
4.68 KB
Binary file not shown.

github_autopwn.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
Author: Cody Winkler (twitter: c2thewinkler | github: m0rph-1)
55
Date: 2/12/2020
66
"""
7+
import os
78
import time
89
import requests
910
import json
1011
import sys
12+
from dotenv import load_dotenv
1113
from termcolor import colored
1214
from base64 import b64decode
1315
from indicators import *
@@ -27,9 +29,13 @@ def parse_options():
2729
args = parser.parse_args()
2830
return args
2931

30-
def get_code_snippet(git_url_key):
32+
def get_code_snippet(git_url_key, authorization):
33+
authorization
34+
headers = {
35+
"Authorization":"Bearer {authorization}"
36+
}
3137

32-
this_req = requests.get(git_url_key, verify=True)
38+
this_req = requests.get(git_url_key, verify=True, headers=headers)
3339
json_data = json.loads(this_req.content)
3440
if this_req.status_code == 200:
3541
repo_code = str(b64decode(json_data["content"]).decode('utf-8')).split('\n')
@@ -39,14 +45,25 @@ def get_code_snippet(git_url_key):
3945
print(str(repo_code[i]))
4046

4147
def check_rate_limit():
42-
43-
this_req = requests.get("https://api.github.com/rate_limit", verify=True)
48+
this_req = requests.get("https://api.github.com/rate_limit", verify=True, headers=headers)
4449
json_data = json.loads(this_req.content)
4550
pprint(json_data["rate"])
4651
return
4752

4853
def main(args):
4954

55+
load_dotenv()
56+
57+
api_key = os.getenv("API_KEY")
58+
59+
if api_key == None or api_key == '':
60+
print(colored("[!] API key is not set. Specify it in .env.", "red"))
61+
exit(1)
62+
63+
headers = {
64+
"Authorization": f"Bearer {api_key}"
65+
}
66+
5067
separator = "-"*100
5168

5269
if args.rate:
@@ -60,7 +77,7 @@ def main(args):
6077
try:
6178

6279
github_api = ("https://api.github.com/search/code?q=user:{} {}").format(args.org, args.query)
63-
this_req = requests.get(github_api, verify=True)
80+
this_req = requests.get(github_api, verify=True, headers=headers)
6481
json_data = json.loads(this_req.content)
6582

6683
if this_req.status_code == 200:
@@ -78,7 +95,7 @@ def main(args):
7895

7996
print(colored("This should be printed if -g is specified", "yellow"))
8097
git_url_key = key["git_url"]
81-
get_code_snippet(git_url_key)
98+
get_code_snippet(git_url_key, )
8299

83100
except KeyError:
84101
print(colored("[-] Didn't find anything. Moving on!", "red"))

todo.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add token to .env and test it

0 commit comments

Comments
 (0)