text
stringlengths
1
93.6k
def debug_vardump(self, post_data):
try:
if post_data[b"filename"][0].decode("utf-8") != "js-error.log" and post_data[b"filename"][0].decode("utf-8") != "httpd.log":
with open(os.path.join(DEBUG_LOC, post_data[b"filename"][0].decode("utf-8")), "w", encoding="utf-8") as buf:
buf.write(json.dumps(DEBUG_VAR, indent=2, sort_keys=True))
return self.empty_response()
except (KeyError, IOError, PermissionError):
pass
return self.my_send_error(404)
def debug_var_post(self, post_data):
result = re.search(r"^\/debug\/var\/([a-zA-Z0-9\-_\.]*)$", self.path)
length = int(self.headers["Content-Length"])
if length != 0:
try:
DEBUG_VAR[result.group(1)] = self.rfile.read(length)
self.my_sender("text/plain", DEBUG_VAR[result.group(1)]) # TODO: Cache-Control/Last-Modified Headers
except KeyError:
self.my_send_error(404)
else:
try:
del DEBUG_VAR[result.group(1)]
except KeyError:
pass
self.empty_response()
def static_request(self):
path = unquote(self.path.split("/", 2)[-1])
if path[-1:] == "/":
path += "index.html"
mime = mimetypes.guess_type(self.path.rsplit("/", 1)[-1])
if mime[0]:
mime = mime[0]
else:
mime = "application/octet-stream"
try:
with open(os.path.join(THEME_LOC, path), "rb") as buf:
data = buf.read()
self.my_sender(mime, data, {"Cache-Control": "public, max-age=31536000", "Last-Modified": self.last_mod_time(os.path.join(THEME_LOC, path))})
except (IOError, PermissionError):
self.my_send_error(404)
def news(self):
try:
with open(os.path.join(CWD, "news.json"), "rb") as buf:
data = buf.read()
self.my_sender("application/json", data, {"Cache-Control": "public, no-cache, must-revalidate", "Last-Modified": self.last_mod_time(os.path.join(CWD, "news.json"))}) # TODO: Cache-Control Headers
except (IOError, PermissionError):
self.my_send_error(404)
def generate_cacher(self):
if re.match(r"^\/cache\/theme\/index.html$", self.path):
html = b'<!DOCTYPE html><html manifest="./../../theme.manifest"><head><meta charset="utf-8"><title>Cacher</title></head><body><script>"use strict";try{window.applicationCache.ondownloading=function(){parent.cacheInterface("ondownloading-theme")},window.applicationCache.onprogress=function(a){parent.cachePro...
else:
html = b'<!DOCTYPE html><html manifest="./offline.manifest"><head><meta charset="utf-8"><title>Cacher</title></head><body><script>"use strict";try{window.applicationCache.ondownloading=function(){parent.cacheInterface("ondownloading")},window.applicationCache.onprogress=function(a){parent.cacheProgress(Math...
self.my_sender("text/html", html) # TODO: Cache-Control/Last-Modified Headers
def generate_manifest(self):
relative_path = "./../.."
search_loc = EXPLOIT_LOC
hasher = hashlib.md5() # nosec B303
manifest = "CACHE MANIFEST\n\n"
manifest += "CACHE:\n"
if re.match(r"^\/cache\/category\/.*\/offline.manifest$", self.path):
relative_path = "./../../.."
search_loc = os.path.join(EXPLOIT_LOC, unquote(self.path.split("/")[3]))
elif re.match(r"^\/cache\/entry\/.*\/.*\/offline.manifest$", self.path):
relative_path = "./../../../.."
search_loc = os.path.join(EXPLOIT_LOC, unquote(self.path.split("/")[3]), unquote(self.path.split("/")[4]))
elif re.match(r"^\/cache\/all\/offline.manifest$", self.path):
relative_path = "./../.."
search_loc = EXPLOIT_LOC
else:
return self.my_send_error(404)
# TODO: Change to scandir?
for path, subdirs, files in os.walk(search_loc):
UNUSED(subdirs)
for filename in files:
if filename not in ("meta.json", "PUT EXPLOITS HERE"):
try:
with open(os.path.join(path, filename), "rb") as buf:
data = buf.read()
hasher.update(data)
manifest += "{}{}\n".format(relative_path, quote(os.path.join(path, filename).replace(CWD, "").replace("\\", "/"), safe=";,/?:@&=+$-_.!~*'()#"))
except (IOError, PermissionError):
pass
manifest += "\nNETWORK:\n"
manifest += "*\n"
hasher.update(bytes(self.last_mod_time(os.path.join(search_loc)), "utf-8"))
manifest += f"\n# Hash: {hasher.hexdigest().upper()}"
return self.my_sender("text/cache-manifest", bytes(manifest, "utf-8"), {"Last-Modified": self.last_mod_time(search_loc)}) # TODO: Cache-Control Headers