JavaScript Tricks: Executing Privately

If it is possible to load and execute JavaScript code in a webpage privately, it would be very beneficial for protecting JavaScript code. In this article, we will explore and demonstrate a technique for privately executing JavaScript code.

Source

<html>
<script>
    window.onload =  function () {
		var  xhr =  new  XMLHttpRequest();
		
		xhr.open("GET" , "http://127.0.0.1:2080/backup/js_png/test.png");
		xhr.send("");

		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				console.log(xhr.responseText);
				
				eval(xhr.responseText);
			}
		}
	}
</script>
</html>

The above is the front-end HTML page code. The principle is: when the page is loaded, an Ajax request is made for a png image file. After obtaining the png file, the file content is executed as js code. The content of the png file on the server is shown in the following figure.

The above image looks like a png image file, but it is actually a javascript file with a png suffix, which is used to disguise it during transmission, making others think it is just a picture.

Execute

This achieves the effect of removing this js code and js file from the webpage, and the js file loading is not visible in the developer tools, but the js function is executed.

However, someone who is attentive may detect abnormalities from two aspects. The first is at the location of Ajax requests in the webpage.

The second is that opening the js file disguised as a png image may reveal its js code.

As shown in the figure below, Firefox browser cannot be identified.

As shown in the figure below, the Chome browser can recognize js.

In comparison, the JavaScript code can be obfuscated to further improve security.

After the javascript code is obfuscated using the a js obfuscator, it can be made impossible to discern the Ajax request logic, as shown in the following image.

The backend disguises a JavaScript file as a PNG image, encrypts it with jjencode to make it appear as gibberish, as shown in the following figure.

In this way, both ends of the JavaScript code are encrypted, making it harder to analyze and making the execution more secretive.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值