From 585b208e9ef691857e8703800cc3d2b5ed22164a Mon Sep 17 00:00:00 2001
From: dadav <33197631+dadav@users.noreply.github.com>
Date: Wed, 15 Apr 2020 16:05:56 +0200
Subject: [PATCH] support multiple passwords
---
builder/data/usr/bin/decryption-webserver | 90 ++++++++++++++++++-----
builder/data/usr/bin/pwnlib | 11 +--
2 files changed, 79 insertions(+), 22 deletions(-)
diff --git a/builder/data/usr/bin/decryption-webserver b/builder/data/usr/bin/decryption-webserver
index 72e4016c4..96e7ba6b4 100755
--- a/builder/data/usr/bin/decryption-webserver
+++ b/builder/data/usr/bin/decryption-webserver
@@ -1,35 +1,36 @@
#!/usr/bin/env python3
from http.server import HTTPServer, BaseHTTPRequestHandler
+from urllib.parse import parse_qsl
-HTML_FORM = """
+_HTML_FORM_TEMPLATE = """
Decryption
@@ -39,7 +40,7 @@ HTML_FORM = """
Please provide the decryption password.
@@ -48,6 +49,55 @@ HTML_FORM = """
"""
+POST_RESPONSE = """
+
+
+
+
+
+
+
+
+
+
+
+
+"""
+
+HTML_FORM = None
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
@@ -59,13 +109,19 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
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()
- password = body.decode('UTF-8').split('=')[1]
+ self.wfile.write(POST_RESPONSE.encode())
- with open('/tmp/.pwnagotchi-secret', 'wt') as pwfile:
- pwfile.write(password)
+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()
diff --git a/builder/data/usr/bin/pwnlib b/builder/data/usr/bin/pwnlib
index 2b7a8204f..cbf358c86 100755
--- a/builder/data/usr/bin/pwnlib
+++ b/builder/data/usr/bin/pwnlib
@@ -103,12 +103,11 @@ is_decrypted() {
# fail if not mounted
if ! mountpoint -q "$mount" >/dev/null 2>&1; then
- if [ -f /tmp/.pwnagotchi-secret ]; then
- /dev/null 2>&1; then
echo "Container decrypted!"
-
fi
fi
@@ -151,8 +150,10 @@ EOF
fi
done /tmp/.pwnagotchi-secret python3 -c 'print("A"*4096)'
+ # overwrite passwords
+ python3 -c 'print("A"*4096)' | tee /tmp/.pwnagotchi-secret-* >/dev/null
+ # delete
+ rm /tmp/.pwnagotchi-secret-*
sync # flush
pkill wpa_supplicant