簡體   English   中英

如何在網頁中隱藏 javascript 代碼 - 重新訪問

[英]How do I hide javascript code in a webpage - revisited

我沒有必要的 10 個信譽點來為這個實時問題添加解決方案( 如何在網頁中隱藏 javascript 代碼? ),但仍然有一個強有力的答案。

功能文件結構如下:

[1] a main .php+html page (i.e.your website) with an src script to an external .js file included.

[2] .js external script that can be obfuscated but it is not necessary, with a XMLHttpRequest() to an associated .php file.

[3] .php file that receives the .js XMLHttpRequest() and includes another .php file

[4] .php file that sends js code back as a plain text string back through the calling files until it is anonymously executed in the calling html+js script in main .php+html page.

隱藏功能是通過在 .js 和 .php 文件之間傳遞有時間限制的憑據(cookie)來實現的,其中攜帶功能 js 的純文本腳本在 php 中隱藏的每個點。

任何時候都不涉及 sql,因此禁止訪問任何數據庫。

最好通過一個示例來說明這一點,該示例中的文件關聯如下(所有文件位於域上的同一目錄中):

[1] = jsHide.php  
[2] = js.js  
[3] = js.php  
[4] = jsFunc.php .

有關代碼,請參見“自我回答”(如下)。

在此示例中,[2] 中的“js function run()”在上傳時包含在 [1] 中,並通過那里的按鈕激活。
“run()”是一個虛擬 js function,一個 shell,它要求將真正的 js 作為文本字符串發送給它。
“run()”設置一個 cookie,其隨機值介於 0 到 1000 之間,生命周期為 2 秒,然后向 [3] 發送“GET XMLHttpRequest()”。
[3] 檢查 cookie,如果一切正常,則包括 [4]。
[4] 檢查它是 [3] 調用它,然后將 js 字符串回顯到 [3],然后將其作為 this.responseText 返回到“run()”,然后使用以下命令匿名執行 js 代碼字符串:“var tmpFunc = new Function() 並調用 tmpFunc()。"
臨時 cookie 在用戶可以直接打開 [3] 或 [4] 以查看 php output 之前過期,但存在足夠長的時間以使“GET XMLHttpRequest()”恢復代碼字符串。

代碼如下:

-------------------------------------------------- -------------------------------------------------- ------------ [1] = jsHide.php

<?php       //  [1] = jsHide.php
session_start();
$_SESSION["pix"] = "";
?>
<!DOCTYPE html>
<html>
<head>
<html lang="en-US" prefix="og: https://cpd-online.net">
<head><meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="icon" href="../favicon.ico">
<script src="js.js"></script>
</head>
<body>
<br>
<button onclick="run()">Press Me!</button>
<br>
</body>
</html>

-------------------------------------------------- -------------------------------------------------- ------------- [2] = js.js

var _$_f14a=["\x65\x78\x70\x69\x72\x65\x73\x3D","\x3D","\x3B","\x3B\x70\x61\x74\x68\x3D\x2F","\x24\x70\x69\x78","\x47\x45\x54","\x6A\x73\x2E\x70\x68\x70"];function setCookie(_0x3424,_0x346A,_0x353C){const _0x34B0= new Date();_0x34B0.setTime(_0x34B0.getTime()+ _0x353C);let _0x34F6=_$_f14a[0]+ _0x34B0.toUTCString();document.cookie= _0x3424+ _$_f14a[1]+ _0x346A+ _$_f14a[2]+ _0x34F6+ _$_f14a[3]}function run(){var _0x3352=Math.floor(Math.random()* 1000);setCookie(_$_f14a[4],_0x3352,1000);var _0x3398= new XMLHttpRequest();_0x3398.onreadystatechange= function(){if(this.readyState== 4&& this.status== 200){var _0x33DE= new Function(this.responseText);_0x33DE()}};_0x3398.open(_$_f14a[5],_$_f14a[6],true);_0x3398.send()}
/*  The above code is unscrambled  as:
function setCookie(cname, cvalue, millisec) {
const d = new Date();
d.setTime(d.getTime() + millisec);
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function run() {
var pixel = Math.floor(Math.random() * 1000);
setCookie('$pix',pixel,1000);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
 var tmpFunc = new Function(this.responseText);
 tmpFunc();
  }
  };
  xhttp.open('GET', 'js.php', true); // true setting is necessary!
  xhttp.send();
}
*/

-------------------------------------------------- -------------------------------------------------- ------------ [4] = jsFunc.php

<?php  //  [3] = js.php
session_start();
$chk1 = intval($_COOKIE['$pix']);
if($chk1 > 0 && $chk1 < 1000){
ob_start();
$content = include "jsFunc.php";
file_put_contents("js.js", $content);
ob_end_flush();
} else {
exit();
}
?>

-------------------------------------------------- -------------------------------------------------- ------------ [4] = jsFunc.php

<?php    //   [4] = jsFunc.php
session_start();
if ( basename($_SERVER['PHP_SELF']) == 'js.php' ) {
exit ( "alert('Hello World');" );
}  else {
exit();
 }
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM