From 402cbb94a604cb94b6990716fa1afd240f09f521 Mon Sep 17 00:00:00 2001
From: Felix Brendel
Date: Tue, 13 Apr 2021 14:02:06 +0200
Subject: [PATCH] yes
---
decipher.js | 122 ++++++++++++++++++++++++++++++++++++++
input_form.html | 4 ++
passwordify_html.py | 131 +++++++++++++++++++++++++++++++++++++++++
test/test.html | 9 +++
test/test.html.pw.html | 87 +++++++++++++++++++++++++++
5 files changed, 353 insertions(+)
create mode 100644 decipher.js
create mode 100644 input_form.html
create mode 100644 passwordify_html.py
create mode 100644 test/test.html
create mode 100644 test/test.html.pw.html
diff --git a/decipher.js b/decipher.js
new file mode 100644
index 0000000..f53e7ca
--- /dev/null
+++ b/decipher.js
@@ -0,0 +1,122 @@
+// function clone_script_node(node){
+// // console.log("\n\n\nnew script!")
+// var script = document.createElement("script");
+// script.text = node.innerHTML;
+// // console.log("text: " + script.text)
+// var i = -1, attrs = node.attributes, attr;
+// while (++i < attrs.length) {
+// script.setAttribute((attr = attrs[i]).name, attr.value);
+// if (attr.name === "src")
+// console.log(attr.value)
+// }
+// return script;
+// }
+
+
+// function replace_all_script_nodes(node) {
+// if (node.tagName === 'SCRIPT') {
+// node.parentNode.replaceChild(clone_script_node(node), node);
+// } else {
+// var i = -1, children = node.childNodes;
+// while (++i < children.length) {
+// replace_all_script_nodes(children[i]);
+// }
+// }
+
+// return node;
+// }
+
+function insertHTML(html){
+ // if no append is requested, clear the target element
+ // if(!append) dest.innerHTML = '';
+ // create a temporary container and insert provided HTML code
+ let container = document.createElement('div');
+ container.innerHTML = html;
+ // cache a reference to all the scripts in the container
+ let scripts = container.querySelectorAll('script');
+ // get all child elements and clone them in the target element
+ let nodes = container.childNodes;
+ // for( let i=0; i< nodes.length; i++) dest.appendChild( nodes[i].cloneNode(true) );
+ // force the found scripts to execute...
+ for( let i=0; i< scripts.length; i++){
+ let script = document.createElement('script');
+ script.type = scripts[i].type || 'text/javascript';
+ if( scripts[i].hasAttribute('src') ) script.src = scripts[i].src;
+ script.innerHTML = scripts[i].innerHTML;
+ document.head.appendChild(script);
+ document.head.removeChild(script);
+ }
+ // done!
+ return true;
+}
+
+
+function decrypt_page() {
+ var key_str = ""
+ var html_name = window.location.pathname;
+ var allcookies = document.cookie;
+ cookiearray = allcookies.split(';');
+ for(var i=0; i"
+
+ // insertHTML(document.body.innerHTML)
+ // replace_all_script_nodes(document.getElementsByTagName("body")[0]);
+}
+
+window.onload = decrypt_page
diff --git a/input_form.html b/input_form.html
new file mode 100644
index 0000000..9f339db
--- /dev/null
+++ b/input_form.html
@@ -0,0 +1,4 @@
+
diff --git a/passwordify_html.py b/passwordify_html.py
new file mode 100644
index 0000000..886a2a4
--- /dev/null
+++ b/passwordify_html.py
@@ -0,0 +1,131 @@
+#!/usr/bin/env python3
+import argparse
+import pyaes
+import os
+import sys
+import random
+import string
+
+sample_usage = """example:
+ python passwordify_html.py file.html --password "this is the password"
+ python passwordify_html.py file.html --password "this is the password" --master-password "master-password"
+"""
+
+parser = argparse.ArgumentParser(description="Generate a chart showing character traits.",
+ epilog=sample_usage,
+ formatter_class=argparse.RawDescriptionHelpFormatter)
+
+parser.add_argument('input_file', type=str, metavar="input",
+ help='the html file')
+parser.add_argument("--password", "-p", dest="password",
+ required=False, type=str, metavar="page password",
+ help="The names of the character traits")
+parser.add_argument("--master-password", "-m", dest="master_password",
+ required=False, type=str, metavar="master password",
+ help="The values for the character traits")
+parser.add_argument("--output", "-o", dest="output_file",
+ required=False, type=str, metavar="output",
+ help="The file which should be created")
+
+args = parser.parse_args()
+
+script_dir = os.path.dirname(__file__)
+
+# passwords length must be in [16, 24, 32]
+# at least one must be supplied, the other is chosen random
+if args.password:
+ assert(len(args.password) in [16, 24, 32])
+ if not args.master_password:
+ args.master_password = "".join(random.choice(string.ascii_letters) for i in range(32))
+elif args.master_password:
+ assert(len(args.master_password) in [16, 24, 32])
+ if not args.password:
+ args.password = "".join(random.choice(string.ascii_letters) for i in range(32))
+else:
+ assert(not "At least one of password or master password must be supplied")
+
+
+# if no out_file was passed, append .pw.html to in_file
+in_file = args.input_file
+out_file = args.output_file
+if not out_file:
+ out_file = f"{in_file}.pw.html"
+
+print(f"passwordifying {in_file} -> {out_file}")
+
+# read the whole html file
+with open(in_file, "r") as in_file_handle:
+ text = in_file_handle.read()
+
+# if the html has no body tag, then just copy it over
+if " tag only appears once
+if len(text_list) != 2:
+ print(f"len(text_list) is {len(text_list)}")
+ assert(False)
+
+header = text_list[0]
+text_list = text_list[1].split("")
+# assert that the
+{html_prompt_text}
+
+ This is an example of a simple HTML page with one paragraph.
+ tag only appears once
+assert(len(text_list) == 2)
+body, footer = text_list
+
+# read in the decipher function text
+with open(os.path.join(script_dir, "decipher.js"), "r") as decipher_file:
+ decipher_function_text = decipher_file.read()
+
+# read in the html input prompt
+with open(os.path.join(script_dir, "input_form.html"), "r") as html_prompt_file:
+ html_prompt_text = html_prompt_file.read()
+
+
+# have a "correct_marker" so the decrypter can check if the password was correct
+# by identifiying if the decryped text ends with the correct_marker
+correct_key_marker = ""
+body = body + correct_key_marker
+aes = pyaes.AESModeOfOperationCTR(real_key,
+ counter=pyaes.Counter(initial_value=initial_counter))
+
+real_key_enc_body = aes.encrypt(body.encode("utf-8")).hex()
+header = header.replace("", f"""
+
+
+
+""")
+text = " ".join([header, f"""
+
""", footer])
+
+# write html to new location
+with open(out_file, "wb") as new_html:
+ new_html.write(text.encode('utf-8'))
+
+print(f"successfully passwordified {in_file}")
diff --git a/test/test.html b/test/test.html
new file mode 100644
index 0000000..40ff876
--- /dev/null
+++ b/test/test.html
@@ -0,0 +1,9 @@
+
+
+