#!/usr/bin/env python3 from http.server import HTTPServer, BaseHTTPRequestHandler from urllib.parse import parse_qsl _HTML_FORM_TEMPLATE = """ Decryption

Decryption

Some of your files are encrypted.

Please provide the decryption password.

{password_fields}
""" POST_RESPONSE = """
""" HTML_FORM = None class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() self.wfile.write(HTML_FORM.encode()) def do_POST(self): content_length = int(self.headers['Content-Length']) body = self.rfile.read(content_length) for mapping, password in parse_qsl(body.decode('UTF-8')): with open('/tmp/.pwnagotchi-secret-{}'.format(mapping), 'wt') as pwfile: pwfile.write(password) self.send_response(200) self.end_headers() self.wfile.write(POST_RESPONSE.encode()) with open('/root/.pwnagotchi-crypted') as crypted_file: mappings = [line.split()[0] for line in crypted_file.readlines()] fields = ''.join(['\n
'.format(m=m) for m in mappings]) HTML_FORM = _HTML_FORM_TEMPLATE.format(password_fields=fields) httpd = HTTPServer(('0.0.0.0', 80), SimpleHTTPRequestHandler) httpd.serve_forever()