This repository has been archived by the owner on Apr 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
app.py
265 lines (225 loc) · 9.27 KB
/
app.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
from flask import Flask, render_template, redirect, url_for, \
request, send_from_directory, make_response, abort, send_file
from OpenSSL import SSL
import json
import random
import os
from _winreg import *
import subprocess
import argparse
import sys
import win32serviceutil
import threading
import time
import io
import shutil
import mmap
app = Flask(__name__)
try:
this_file = __file__
except NameError:
this_file = sys.argv[0]
this_file = os.path.abspath(this_file)
CURRENT_DIR = os.path.dirname(this_file)
PATH_ITEMS = os.path.join(CURRENT_DIR, "json\\items.json")
PATH_PRODUCTS = os.path.join(CURRENT_DIR, "json\\products.json")
#build to executable
if getattr(sys, 'frozen', False):
CURRENT_DIR = os.path.dirname(sys.executable)
PATH_ITEMS = os.path.join(CURRENT_DIR, "json\\items.json")
PATH_PRODUCTS = os.path.join(CURRENT_DIR, "json\\products.json")
if not os.path.exists(PATH_ITEMS) and not os.path.exists(PATH_PRODUCTS):
shutil.copytree(os.path.join(sys._MEIPASS, 'json'), os.path.join(CURRENT_DIR, 'json'))
@app.route("/")
def index():
return redirect("/accounts/login/?next=/", code = 302)
@app.route('/<path:path>')
def proxy(path):
#return "\n", 101
abort(404)
@app.route("/accounts/login/", methods=['GET',])
def login():
return 'OK'
@app.route('/api/v1/rest-auth/login/', methods=['POST'])
def auth_login():
payload = '{"code": 0, "token": "9d1253d4acb57cb90d58b12b342967f7b2c0a2bf", "url": null}'
resp = make_response(payload)
resp.headers['Content-Type'] = 'application/json'
return resp
@app.route("/api/v1/me/products/")
def products():
resp = make_response(send_file(PATH_PRODUCTS))
resp.headers['Content-Type'] = 'application/json'
resp.headers['Set-Cookie'] = 'sessionid=nrbw43idxks9hfkqpsp0nwlpzbdlqi7p; expires=Wed, 06-Jun-2518 19:31:03 GMT; HttpOnly; Max-Age=1209600; Path=/'
resp.headers['X-Bdrive-Session-Key'] = 'd90ab0a3b35a4d59bba2f0cfed1de192'
return resp
@app.route("/api/v1/NetDrive3/items/", methods=["POST"])
def add_item():
dataNew = request.get_json()
dataNew['id'] = random.randint(1, 999999)
with open(PATH_ITEMS, 'r+') as f:
database = json.load(f)
database['count'] += 1
database['results'].append(dataNew)
f.seek(0)
f.truncate()
json.dump(database, f)
resp = make_response(json.dumps(dataNew))
resp.headers['X-Bdrive-Session-Key'] = 'd90ab0a3b35a4d59bba2f0cfed1de192'
resp.headers['Content-Type'] = 'application/json'
return resp
@app.route("/api/v1/NetDrive3/items/", methods=["GET"])
def get_item():
if not os.path.exists(PATH_ITEMS):
with open(PATH_ITEMS, 'w') as f:
f.write('{"count": 0, "previous": null, "results": [], "next": null}')
resp = make_response(send_file(PATH_ITEMS))
resp.headers['Content-Type'] = 'application/json'
resp.headers['Set-Cookie'] = 'sessionid=nrbw43idxks9hfkqpsp0nwlpzbdlqi7p; expires=Wed, 06-Jun-2518 19:31:03 GMT; HttpOnly; Max-Age=1209600; Path=/'
resp.headers['X-Bdrive-Session-Key'] = 'd90ab0a3b35a4d59bba2f0cfed1de192'
return resp
@app.route("/api/v1/NetDrive3/items/<int:item_id>/", methods=['PATCH', 'DELETE'])
def items(item_id):
item_id = int(item_id)
if request.method == "PATCH":
dataUpdate = request.get_json()
dataUpdate['id'] = item_id
with open(PATH_ITEMS, 'r+') as f:
database = json.load(f)
for i in xrange(len(database['results'])):
if database['results'][i]['id'] == item_id:
database['results'][i] = dataUpdate
break
f.seek(0)
f.truncate()
json.dump(database, f)
resp = make_response(json.dumps(dataUpdate))
resp.headers['X-Bdrive-Session-Key'] = 'd90ab0a3b35a4d59bba2f0cfed1de192'
resp.headers['Content-Type'] = 'application/json'
return resp
if request.method == "DELETE":
with open(PATH_ITEMS, 'r+') as f:
database = json.load(f)
for i in xrange(len(database['results'])):
if database['results'][i]['id'] == item_id:
del database['results'][i]
database['count'] -= 1
break
f.seek(0)
f.truncate()
json.dump(database, f)
resp = make_response()
resp.headers['X-Bdrive-Session-Key'] = 'd90ab0a3b35a4d59bba2f0cfed1de192'
resp.headers['Set-Cookie'] = 'sessionid=nrbw43idxks9hfkqpsp0nwlpzbdlqi7p; expires=Wed, 06-Jun-2518 19:31:03 GMT; HttpOnly; Max-Age=1209600; Path=/'
return resp, 204
@app.route('/api/v1/sso_guard/')
def sso_guard():
payload = '{"guard":"MTUyNzUyODA3LTI3Ljc0LjI1NS4yNDE=","encoding":"sha3-256","format":"token-guard"}'
resp = make_response(payload)
resp.headers['Content-Type'] = 'application/json'
resp.headers['Set-Cookie'] = 'sessionid=nrbw43idxks9hfkqpsp0nwlpzbdlqi7p; expires=Wed, 06-Jun-2518 19:31:03 GMT; HttpOnly; Max-Age=1209600; Path=/'
return resp
def crackNetDrive():
try:
os.system('taskkill /f /im ndagent.exe')
os.system('taskkill /f /im nd3svc.exe')
os.system('taskkill /f /im NetDrive.exe')
os.system('taskkill /f /im ndmnt.exe')
key = OpenKey(HKEY_LOCAL_MACHINE, r'SOFTWARE\Bdrive Inc\NetDrive3')
DirNetDrive = QueryValue(key, 'Path')
NetDrivePath = os.path.join(DirNetDrive, 'NetDrive.exe')
ndagentPath = os.path.join(DirNetDrive, 'ndagent.exe')
shutil.copy2(NetDrivePath, os.path.join(DirNetDrive, 'NetDrive.exe.bak'))
shutil.copy2(ndagentPath, os.path.join(DirNetDrive, 'ndagent.exe.bak'))
with open(NetDrivePath, 'rb+') as f:
#f.seek(0x1AF51C)
f.seek(FindOffsetBypass(NetDrivePath))
f.write('://127.0.0.1:52221')
with open(ndagentPath, 'rb+') as f:
#f.seek(0x103A70)
f.seek(FindOffsetBypass(ndagentPath))
f.write('://127.0.0.1:52221')
pathFileHosts = os.path.join(os.environ['windir'], r'System32\drivers\etc\hosts')
if not os.path.exists(pathFileHosts):
with open(pathFileHosts, "a+") as f:
f.write('127.0.0.1 localhost\r\n')
with open(pathFileHosts, "a+") as f:
f.write('\r\n127.0.0.1 push.bdrive.com\r\n')
os.system('gpupdate /force')
except Exception as e:
print ("Crack failed - %s" % e)
return
print "Crack OK"
try:
win32serviceutil.StartService('NetDrive3_Service_x64_NetDrive3')
except:
win32serviceutil.StartService('NetDrive3_Service_NetDrive3')
win32serviceutil.StartService('NetDrive3 Agent')
subprocess.Popen([os.path.join(DirNetDrive, 'NetDrive.exe'),], cwd = DirNetDrive)
def startNetDrive3():
time.sleep(5)
try:
win32serviceutil.StartService('NetDrive3_Service_x64_NetDrive3')
except:
win32serviceutil.StartService('NetDrive3_Service_NetDrive3')
win32serviceutil.StartService('NetDrive3 Agent')
key = OpenKey(HKEY_LOCAL_MACHINE, r'SOFTWARE\Bdrive Inc\NetDrive3')
DirNetDrive = QueryValue(key, 'Path')
subprocess.Popen([os.path.join(DirNetDrive, 'NetDrive.exe'),], cwd = DirNetDrive)
def runServer():
os.system('taskkill /f /im ndagent.exe')
os.system('taskkill /f /im nd3svc.exe')
os.system('taskkill /f /im NetDrive.exe')
os.system('taskkill /f /im ndmnt.exe')
thread = threading.Thread(target = startNetDrive3)
thread.setDaemon(True)
thread.start()
app.run(threaded = True, debug = False, port = 52221, host = '127.0.0.1')#, ssl_context=(PATH_CERT, PATH_KEY))
def RunAtStartup():
try:
key = OpenKey(HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Run', 0, KEY_WRITE)
SetValueEx(key, 'AutoServerNetDrive3', 0, REG_SZ, sys.executable)
CloseKey(key)
return True
except WindowsError:
return False
def FindOffsetBypass(FileName):
with open(FileName, 'rb+') as f:
mm = mmap.mmap(f.fileno(), 0)
return int(mm.find('api.bdrive.com')) - 4
def RemoveRunAtStartup():
try:
key = OpenKey(HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Run', 0, KEY_WRITE)
DeleteValue(key, 'AutoServerNetDrive3')
CloseKey(key)
return True
except WindowsError:
return False
def main():
description = """\
Please enter -a or --auto to crack NetDrive3
If no arguments, program will run the fake server\
"""
parser = argparse.ArgumentParser(description = description, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-a', '--auto', action = 'store_true', help = 'Auto crack NetDrive3')
parser.add_argument('-s', '--startup', action = 'store_true', help = 'Run at startup')
parser.add_argument('-r', '--remove', action = 'store_true', help = 'Remove run at startup')
args = parser.parse_args()
if args.auto:
crackNetDrive()
if args.startup:
if RunAtStartup():
print "StartUp OK"
return
print "StartUp Failed"
return
if args.remove:
if RemoveRunAtStartup():
print "Remove OK"
return
print "Remove Failed"
return
print "Please enter --help for infomation."
runServer()
if __name__ == '__main__':
main()