Skip to content

Commit 4b38379

Browse files
committed
Prepping for flatz's remote installer release, building GUI now
1 parent 2cc55b9 commit 4b38379

File tree

4 files changed

+112
-8
lines changed

4 files changed

+112
-8
lines changed

pkgs/PUT PKGS HERE

Whitespace-only changes.

start.py

+75-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from cgi import parse_qs
1111
import copy
1212
from distutils.version import StrictVersion
13+
import http.client
1314
from http.server import BaseHTTPRequestHandler
1415
from http.server import HTTPServer
1516
import hashlib
@@ -54,6 +55,7 @@
5455
UPDATE_LOC = os.path.join(CWD, 'updates')
5556
THEME_LOC = os.path.join(CWD, 'themes')
5657
DEBUG_LOC = os.path.join(CWD, 'debug')
58+
PKG_LOC = os.path.join(CWD, 'pkgs')
5759
SETTINGS = None
5860
MENU_OPEN = False
5961
DEBUG_VAR = {}
@@ -209,6 +211,25 @@ def api_edit_settings(self, data):
209211
# TODO
210212
pass
211213

214+
def api_pkg_list(self):
215+
try:
216+
pkgs = os.listdir(PKG_LOC)
217+
for entry in pkgs:
218+
print(entry)
219+
if not os.path.isfile(os.path.join(PKG_LOC, entry)) or entry == 'PUT PKGS HERE':
220+
pkgs.remove(entry)
221+
pkgs.sort()
222+
if len(pkgs) == 0:
223+
data = b'["No PKGs Found"]'
224+
else:
225+
data = bytes(json.dumps(pkgs), 'utf-8')
226+
except (IOError, PermissionError):
227+
data = b'["I/O Error on Host"]'
228+
229+
# TODO: Combine partial pkgs based on names
230+
231+
self.my_sender('application/json', data)
232+
212233
def menu(self):
213234
with open(os.path.join(THEME_LOC, SETTINGS['Theme'], 'index.html'), 'rb') as buf:
214235
data = buf.read()
@@ -385,6 +406,8 @@ def check_ua(self):
385406
return False
386407

387408
def do_GET(self):
409+
global DEBUG_VAR
410+
388411
self.path = self.path.split('?')[0]
389412
try:
390413
if re.match(r'^\/update\/(ps4|psp2)\/list\/[a-z]{2}\/(ps4|psp2)\-updatelist\.xml', self.path):
@@ -414,9 +437,15 @@ def do_GET(self):
414437
else:
415438
self.send_error(404)
416439
return
440+
elif re.match(r'^\/api\/serverip$', self.path) and not SETTINGS['Public']:
441+
self.my_sender('text/plain', bytes(SETTINGS['HTTP_Interface_IP'] + ':' + str(SETTINGS['HTTP_Port']) , 'utf-8'))
442+
return
417443
elif re.match(r'^\/api\/settings\/view$', self.path) and not SETTINGS['Public']:
418444
self.api_view_settings()
419445
return
446+
elif re.match(r'^\/api\/pkglist$', self.path):
447+
self.api_pkg_list()
448+
return
420449
else:
421450
self.send_error(404)
422451
return
@@ -464,19 +493,23 @@ def do_GET(self):
464493
elif re.match(r'^\/themes\/', self.path):
465494
self.static_request()
466495
return
467-
elif re.match(r'\/news$', self.path):
496+
elif re.match(r'^\/news$', self.path):
468497
self.news()
469498
return
470-
elif re.match(r'\/blank.html$', self.path):
499+
elif re.match(r'^\/blank.html$', self.path):
471500
self.my_sender('text/html', b'<html><head><meta charset="utf-8"><title>Deus Machina</title></head><body>ZmzJCgLnJ43j2FK4NUR/EmFc7hJRN7Ub4adlqCRLfsXoswDsjyvn5vGwLj2FZdOlVLNmi/l0mjiuHgCYSZqPSndVhg6U8ODSl1+/aDxQLZE=</body></html>')
472501
return
473-
elif re.match(r'^\/debug\/var\/[a-zA-Z0-9\-\_\.]*$', self.path):
502+
elif re.match(r'^\/debug\/var\/[a-zA-Z0-9\-\_\.]*$', self.path) and not SETTINGS['Public']:
474503
try:
475504
result = re.search(r'^\/debug\/var\/([a-zA-Z0-9\-\_\.]*)$', self.path)
476505
self.my_sender('text/plain', DEBUG_VAR[result.group(1)])
477506
except KeyError:
478507
self.send_error(404)
479508
return
509+
elif re.match(r'\/debug\/varclear$', self.path) and not SETTINGS['Public']:
510+
DEBUG_VAR = {}
511+
self.my_sender('text/plain', b'')
512+
return
480513
else:
481514
self.send_error(404)
482515
return
@@ -491,6 +524,9 @@ def parse_POST(self):
491524
elif ctype == 'application/x-www-form-urlencoded':
492525
length = int(self.headers['content-length'])
493526
postvars = parse_qs(self.rfile.read(length), keep_blank_values=1)
527+
elif ctype == 'application/json':
528+
length = int(self.headers['content-length'])
529+
postvars = self.rfile.read(length)
494530
else:
495531
postvars = {}
496532
return postvars
@@ -506,6 +542,26 @@ def do_POST(self):
506542
self.api_edit_settings(post_data)
507543
self.my_sender('text/plain', b'')
508544
return
545+
elif re.match(r'^\/api\/remote\_pkg$', self.path) and not SETTINGS['Public']:
546+
try:
547+
json_request = json.loads(str(post_data, 'utf-8').replace('\\"', '"'))
548+
ps4_IP = json_request['PS4_IP']
549+
endpoint = json_request['Endpoint']
550+
command = bytes(json.dumps(json_request['Command']), 'utf-8')
551+
with urllib.request.urlopen('http://{}:12800/api/{}'.format(ps4_IP, endpoint), data=command) as buf:
552+
response = buf.read()
553+
response = response.strip()
554+
self.my_sender('application/json', response)
555+
return
556+
except http.client.RemoteDisconnected:
557+
self.my_sender('application/json', b'{ "status": "fail", "error": "Remote disconnect" }')
558+
return
559+
except (KeyError, urllib.error.HTTPError, json.JSONDecodeError):
560+
self.my_sender('application/json', b'{ "status": "fail", "error": "Bad input" }')
561+
return
562+
except IOError:
563+
self.my_sender('application/json', b'{ "status": "fail", "error": "IO error" }')
564+
return
509565
elif re.match(r'^\/debug\/jserrorlog$', self.path):
510566
message = '--------------------------------------------------------------------------------\n'
511567
message += ' Message: ' + post_data[b'message'][0].decode('utf-8') + '\n'
@@ -514,7 +570,7 @@ def do_POST(self):
514570
message += ' URL: ' + post_data[b'url'][0].decode('utf-8') + '\n'
515571
message += ' User-Agent: ' + post_data[b'useragent'][0].decode('utf-8') + '\n'
516572
message += ' Stack: ' + post_data[b'stack'][0].decode('utf-8') + '\n'
517-
with open(os.path.join(DEBUG_LOC, 'js-error.log'), 'a+') as buf:
573+
with open(os.path.join(DEBUG_LOC, 'js-error.log'), 'a') as buf:
518574
buf.write(message)
519575
self.my_sender('text/plain', b'')
520576
return
@@ -539,6 +595,20 @@ def do_POST(self):
539595
else:
540596
self.send_error(404)
541597
return
598+
elif re.match(r'\/debug\/clearlogs$', self.path) and not SETTINGS['Public']:
599+
with open(os.path.join(DEBUG_LOC, 'js-error.log'), 'w') as buf:
600+
pass
601+
with open(os.path.join(DEBUG_LOC, 'httpd.log'), 'w') as buf:
602+
pass
603+
self.my_sender('text/plain', b'')
604+
return
605+
elif re.match(r'\/debug\/vardump$', self.path) and not SETTINGS['Public']:
606+
if post_data[b'filename'][0].decode('utf-8') != 'js-error.log' and \
607+
post_data[b'filename'][0].decode('utf-8') != 'httpd.log':
608+
with open(os.path.join(DEBUG_LOC, post_data[b'filename'][0].decode('utf-8')), 'w') as buf:
609+
buf.write(json.dumps(DEBUG_VAR, indent=2, sort_keys=True))
610+
self.my_sender('text/plain', b'')
611+
return
542612
elif re.match(r'^\/debug\/var\/[a-zA-Z0-9\-\_\.]*$', self.path) and not SETTINGS['Public']:
543613
result = re.search(r'^\/debug\/var\/([a-zA-Z0-9\-\_\.]*)$', self.path)
544614
DEBUG_VAR[result.group(1)] = self.rfile.read(int(self.headers['Content-Length']))
@@ -553,7 +623,7 @@ def do_POST(self):
553623

554624
def log_message(self, format, *args):
555625
try:
556-
with open(os.path.join(DEBUG_LOC, 'httpd.log'), 'a+') as buf:
626+
with open(os.path.join(DEBUG_LOC, 'httpd.log'), 'a') as buf:
557627
buf.write("%s - - [%s] %s\n" % (self.address_string(), self.log_date_time_string(), format % args))
558628
except (IOError, PermissionError):
559629
pass

themes/default/common.js

+27
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ function sleep(time) {
4545
return new Promise((resolve) => setTimeout(resolve, time));
4646
}
4747

48+
function getServerIP() {
49+
$.ajax({
50+
async: false,
51+
url: "/api/serverip",
52+
success: function(html) {
53+
strReturn = html;
54+
},
55+
async: false
56+
})
57+
58+
return strReturn;
59+
}
60+
4861
function getJson(url) {
4962
"use strict";
5063
var result = $.ajax({
@@ -56,6 +69,20 @@ function getJson(url) {
5669
return result;
5770
}
5871

72+
function sendJson(url, data) {
73+
"use strict";
74+
var result = $.ajax({
75+
type: "POST",
76+
contentType:"application/json; charset=utf-8",
77+
dataType: "json",
78+
url: url,
79+
data: data,
80+
async: false
81+
}).responseText;
82+
83+
return result;
84+
}
85+
5986
function getCategories() {
6087
"use strict";
6188
var url = "/api/categories";

themes/default/default.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
function hostRedirect() {
44
"use strict";
5-
// For DNS Usage
6-
// var redirect = "https://cthugha.thegate.network/";
7-
// location.replace(redirect);
5+
// For DNS Usage:
6+
// location.replace("https://cthugha.thegate.network/");
7+
// Otherwise:
8+
location.replace(getServerIP());
89
}
910

1011
function defaultHomepages() {
@@ -155,6 +156,12 @@ function loadPage(title, header) {
155156
}
156157

157158
if (title === "Category Selection") {
159+
var categoryList = getCategories();
160+
if (categoryList.length == 1) {
161+
loadPage("Exploit Selection", categoryList[0]);
162+
return;
163+
}
164+
158165
var categoryButtons = buildCategoryButtons();
159166
if (categoryButtons !== undefined) {
160167
$(document).attr("title", title + " | Exploit Host by Al Azif");

0 commit comments

Comments
 (0)