You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

123 rivejä
4.3 KiB

  1. // function clone_script_node(node){
  2. // // console.log("\n\n\nnew script!")
  3. // var script = document.createElement("script");
  4. // script.text = node.innerHTML;
  5. // // console.log("text: " + script.text)
  6. // var i = -1, attrs = node.attributes, attr;
  7. // while (++i < attrs.length) {
  8. // script.setAttribute((attr = attrs[i]).name, attr.value);
  9. // if (attr.name === "src")
  10. // console.log(attr.value)
  11. // }
  12. // return script;
  13. // }
  14. // function replace_all_script_nodes(node) {
  15. // if (node.tagName === 'SCRIPT') {
  16. // node.parentNode.replaceChild(clone_script_node(node), node);
  17. // } else {
  18. // var i = -1, children = node.childNodes;
  19. // while (++i < children.length) {
  20. // replace_all_script_nodes(children[i]);
  21. // }
  22. // }
  23. // return node;
  24. // }
  25. function insertHTML(html){
  26. // if no append is requested, clear the target element
  27. // if(!append) dest.innerHTML = '';
  28. // create a temporary container and insert provided HTML code
  29. let container = document.createElement('div');
  30. container.innerHTML = html;
  31. // cache a reference to all the scripts in the container
  32. let scripts = container.querySelectorAll('script');
  33. // get all child elements and clone them in the target element
  34. let nodes = container.childNodes;
  35. // for( let i=0; i< nodes.length; i++) dest.appendChild( nodes[i].cloneNode(true) );
  36. // force the found scripts to execute...
  37. for( let i=0; i< scripts.length; i++){
  38. let script = document.createElement('script');
  39. script.type = scripts[i].type || 'text/javascript';
  40. if( scripts[i].hasAttribute('src') ) script.src = scripts[i].src;
  41. script.innerHTML = scripts[i].innerHTML;
  42. document.head.appendChild(script);
  43. document.head.removeChild(script);
  44. }
  45. // done!
  46. return true;
  47. }
  48. function decrypt_page() {
  49. var key_str = ""
  50. var html_name = window.location.pathname;
  51. var allcookies = document.cookie;
  52. cookiearray = allcookies.split(';');
  53. for(var i=0; i<cookiearray.length; i++) {
  54. name = cookiearray[i].split('=')[0].trim();
  55. value = cookiearray[i].split('=')[1];
  56. if (name == html_name)
  57. key_str = value;
  58. if (name == "__master__") {
  59. key_str = value;
  60. break;
  61. }
  62. }
  63. if (key_str.length == 0)
  64. key_str = document.querySelector('input[name=pwd]').value
  65. // check key length
  66. if (key_str.length != 16 &&
  67. key_str.length != 24 &&
  68. key_str.length != 32)
  69. {
  70. return;
  71. }
  72. var entered_key = aesjs.utils.utf8.toBytes(key_str);
  73. var enc_bytes = aesjs.utils.hex.toBytes(enc_hex_body)
  74. // check if the user input / loaded cookie is the master key
  75. var aesCtr = new aesjs.ModeOfOperation.ctr(entered_key, new aesjs.Counter(initial_counter))
  76. var master_key_dec_real_key = aesCtr.decrypt(aesjs.utils.hex.toBytes(master_key_enc_real_key))
  77. aesCtr = new aesjs.ModeOfOperation.ctr(master_key_dec_real_key, new aesjs.Counter(initial_counter))
  78. var dec_bytes = aesCtr.decrypt(enc_bytes)
  79. // Convert our bytes back into text
  80. var dec_text = aesjs.utils.utf8.fromBytes(dec_bytes)
  81. if (!dec_text.endsWith(correct_key_marker)) {
  82. // check if it is a regular password
  83. aesCtr = new aesjs.ModeOfOperation.ctr(entered_key, new aesjs.Counter(initial_counter))
  84. var org_key_dec_real_key = aesCtr.decrypt(aesjs.utils.hex.toBytes(org_key_enc_real_key))
  85. aesCtr = new aesjs.ModeOfOperation.ctr(org_key_dec_real_key, new aesjs.Counter(initial_counter))
  86. dec_bytes = aesCtr.decrypt(enc_bytes)
  87. dec_text = aesjs.utils.utf8.fromBytes(dec_bytes)
  88. if (!dec_text.endsWith(correct_key_marker)) {
  89. key_str = "";
  90. return
  91. } else {
  92. // entered correct file key
  93. document.cookie = html_name + "=" + key_str;
  94. }
  95. } else {
  96. // entered correct master key
  97. document.cookie = "__master__=" + key_str;
  98. }
  99. // Convert our bytes back into text
  100. // var dec_text = aesjs.utils.utf8.fromBytes(dec_bytes)
  101. var dec_text = new TextDecoder().decode(dec_bytes)
  102. document.body.outerHTML = "<body" + dec_text + "</body>"
  103. // insertHTML(document.body.innerHTML)
  104. // replace_all_script_nodes(document.getElementsByTagName("body")[0]);
  105. }
  106. window.onload = decrypt_page