-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaslgit.py
More file actions
executable file
·208 lines (188 loc) · 8.09 KB
/
aslgit.py
File metadata and controls
executable file
·208 lines (188 loc) · 8.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File name : aslgit.py
# Author : BlueCtx (AnonSecLab)
# Date created : 21 Aug 2022
from email.mime import base
import json
import requests
import binascii
import re
from requests.auth import HTTPBasicAuth
import sys
import base64
import argparse
import shutil
import webbrowser
version_number = '1.0.4'
def get_banner():
"""Génère le banner adapté à la taille du terminal"""
try:
terminal_width = shutil.get_terminal_size().columns
except:
terminal_width = 80
banner_full = f"""\x1b[0;33m
.aMMMb dMMMMb .aMMMb dMMMMb .dMMMb dMMMMMP .aMMMb dMP .aMMMb dMMMMb
dMP"dMP dMP dMP dMP"dMP dMP dMP dMP" VP dMP dMP"VMP dMP dMP"dMP dMP"dMP
dMMMMMP dMP dMP dMP dMP dMP dMP VMMMb dMMMP dMP dMP dMMMMMP dMMMMK"
dMP dMP dMP dMP dMP.aMP dMP dMP dP .dMP dMP dMP.aMP dMP dMP dMP dMP.aMF
dMP dMP dMP dMP VMMMP" dMP dMP VMMMP" dMMMMMP VMMMP" dMMMMMP dMP dMP dMMMMP"
\x1b[1;33mv{version_number}\x1b[0;33m
\x1b[0;1;3mBy BlueCtx\x1b[0;33m | \x1b[0;1mhttps://bluectx.github.io\x1b[0m | \x1b[0;1mhttps://anonseclab.org\x1b[0m
\x1b[0;36mcontact@anonseclab.org\x1b[0m
"""
banner_medium = f"""\x1b[0;33m
.aMMMb dMMMMb .aMMMb dMMMMb .dMMMb dMMMMMP .aMMMb dMP
dMP"dMP dMP dMP dMP"dMP dMP dMP dMP" VP dMP dMP"VMP dMP
dMMMMMP dMP dMP dMP dMP dMP dMP VMMMb dMMMP dMP dMP
dMP dMP dMP dMP dMP.aMP dMP dMP dP .dMP dMP dMP.aMP dMP
dMP dMP dMP dMP VMMMP" dMP dMP VMMMP" dMMMMMP VMMMP" dMMMMMP
\x1b[1;33mv{version_number}\x1b[0;33m
\x1b[0;1;3mBy BlueCtx\x1b[0;33m | \x1b[0;1mhttps://bluectx.github.io\x1b[0m
\x1b[0;36mcontact@anonseclab.org\x1b[0m
"""
banner_compact = f"""\x1b[0;33m
.aMMMb dMMMMb .aMMMb dMMMMb
dMP"dMP dMP dMP dMP"dMP dMP dMP
dMMMMMP dMP dMP dMP dMP dMP dMP
dMP dMP dMP dMP dMP.aMP dMP dMP
dMP dMP dMP dMP VMMMP" dMP dMP
\x1b[1;33mv{version_number}\x1b[0;33m
\x1b[0;1;3mBlueCtx\x1b[0;33m | \x1b[0;1mbluectx.github.io\x1b[0m
\x1b[0;36mcontact@anonseclab.org\x1b[0m
"""
if terminal_width >= 100:
return banner_full
elif terminal_width >= 70:
return banner_medium
else:
return banner_compact
jsonOutput = {}
output = []
email_out = []
def findReposFromUsername(username):
response = requests.get('https://api.github.com/users/%s/repos?per_page=100&sort=pushed' % username).text
repos = re.findall(r'"full_name":"%s/(.*?)",.*?"fork":(.*?),' % username, response)
nonForkedRepos = []
for repo in repos:
if repo[1] == 'false':
nonForkedRepos.append(repo[0])
return nonForkedRepos
def findEmailFromContributor(username, repo, contributor):
response = requests.get('https://github.com/%s/%s/commits?author=%s' % (username, repo, contributor), auth=HTTPBasicAuth(username, '')).text
latestCommit = re.search(r'href="/%s/%s/commit/(.*?)"' % (username, repo), response)
if latestCommit:
latestCommit = latestCommit.group(1)
else:
latestCommit = 'dummy'
commitDetails = requests.get('https://github.com/%s/%s/commit/%s.patch' % (username, repo, latestCommit), auth=HTTPBasicAuth(username, '')).text
email = re.search(r'<(.*)>', commitDetails)
if email:
email = email.group(1)
email_out.append(email)
return
def findEmailFromUsername(username):
repos = findReposFromUsername(username)
for repo in repos:
findEmailFromContributor(username, repo, username)
def findPublicKeysFromUsername(username):
gpg_response = requests.get(f'https://github.com/{username}.gpg').text
ssh_response = requests.get(f'https://github.com/{username}.keys').text
if not "hasn't uploaded any GPG keys" in gpg_response:
output.append(f'[+] GPG_keys : https://github.com/{username}.gpg')
jsonOutput['GPG_keys'] = f'https://github.com/{username}.gpg'
# extract email from gpg key
regex_pgp = re.compile(r"-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----", re.MULTILINE)
matches = regex_pgp.findall(gpg_response)
if matches:
# Base64 decode the signature block
b64 = base64.b64decode(matches[0])
# Convert the base64 to hex
hx = binascii.hexlify(b64)
# Get the offsets for the Key ID
keyid = hx.decode()[48:64]
output.append(f'[+] GPG_key_id : {keyid}')
jsonOutput['GPG_key_id'] = keyid
# find email adress
emails = re.findall(r"[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+", b64.decode('Latin-1'))
if emails:
for email in emails:
email_out.append(email)
if ssh_response :
output.append(f'[+] SSH_keys : https:/github.com/{username}.keys')
jsonOutput['SSH_keys'] = f'https://github.com/{username}.keys'
def findInfoFromUsername(username):
url = f'https://api.github.com/users/{username}'
response = requests.get(url)
if response.status_code == 200 and requests.codes.ok:
data = response.json()
for i in data:
if i in ['login','id','avatar_url','name','blog','location','twitter_username','email','company','bio','public_gists','public_repos','followers','following','created_at','updated_at']:
if data[i] != None and data[i] != '':
if i == 'email':
email_out.append(data[i])
jsonOutput[i] = data[i]
output.append(f'[+] {i} : {data[i]}')
jsonOutput['public_gists'] = f'https://gist.github.com/{username}'
output.append(f'[+] public_gists : https://gist.github.com/{username}')
return True
elif response.status_code == 404:
jsonOutput['error'] = 'username does not exist'
return False
def findUsernameFromEmail(email):
response = requests.get('https://api.github.com/search/users?q=%s' % email).text
username = re.findall(r'"login":"(.*?)"', response)
if username:
output.append(f'[+] username : {username[0]}')
jsonOutput['username'] = username[0]
else:
output.append(f'[-] username : Not found')
jsonOutput['username'] = 'Not found'
class CustomParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write('Error: %s\n' % message)
self.print_help()
sys.exit(2)
def parse_args():
parser = argparse.ArgumentParser(
prog=sys.argv[0],
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument("-u", "--username", default=None, help="Github username of the account to search for")
parser.add_argument("-e", "--email", default=None, help="Email of the account to search for github username")
parser.add_argument("--json", default=False, action="store_true", help="Return a json output")
args = parser.parse_args()
return args
if __name__ == '__main__':
print(get_banner())
args = parse_args()
if(args.username):
username_exists = findInfoFromUsername(args.username)
if username_exists:
findEmailFromUsername(args.username)
findPublicKeysFromUsername(args.username)
if(args.json):
jsonOutput['email'] = list(set(email_out))
print(json.dumps(jsonOutput, sort_keys=True, indent=4))
else:
for data in output:
print(data)
if email_out != []:
print('[+] email :', end='')
for email in list(set(email_out)):
print(f' {email}', end='')
else:
if(args.json):
print(json.dumps(jsonOutput, sort_keys=True, indent=4))
else:
print(f'Username does not exist')
elif(args.email):
findUsernameFromEmail(args.email)
if(args.json):
print(json.dumps(jsonOutput, sort_keys=True, indent=4))
else:
for data in output:
print(data)
else:
print('Help: ./aslgit -h')
sys.exit(1)