Home Web Front-end JS Tutorial Non-JS method for web page shielding (left and right keys, codes, etc.)_javascript skills

Non-JS method for web page shielding (left and right keys, codes, etc.)_javascript skills

May 16, 2016 pm 07:17 PM
code

I have long wanted to write an article about web page source code blocking. This is because after I often compile some JS scripts, while I am complacent, I am also worried that others will see the source code and steal my scripts. So I have been trying my best to maintain the security of the source code of my web pages. Although there is no completely safe shielding method yet (that is to say, when I came up with these methods, I already knew their weaknesses and cracking methods), but I have many shielding ideas here to summarize.
As we all know, to protect a page, the most basic thing is to block the right click. The most commonly used function click() on web pages now is the following code:

〈script〉  
function click(){  
if(event.button==2){  
alert( '本网站欢迎您 !!');  
}  
}  
document.onmousedown=click  
〈/script〉
Copy after login

But the cracking method of this shielding method is also well known. That is, you can see the right-click menu again by clicking the left and right mouse buttons continuously. However, I have seen a good way to block the right click. Its principle is different from what is mentioned above. It is not a script written in JS, but uses defined web page attributes to limit it. Moreover, JS scripts should be avoided as much as possible in shielding. Because as long as the viewer disables the javascript script in IE. Then all shielding is in vain.
Then let’s continue with the method of blocking the right click by modifying the properties of the web page. This method uses the in HTML to make modifications. It only has the following short line of code:

〈body oncontextmenu=self.event.returnValue=false〉
Copy after login

Here, oncontextmenu is defined. Make the value of the right click false, which has the effect of shielding the right click. Now, try the cracking method just now, it no longer works. Left- and right-click combos can no longer open the right-click menu. Not just this, try other methods. No matter how messed up you are, right-clicking is useless. Because in this web page, the right click no longer exists. What can you do with a function key that doesn't exist?
However, blocking the right click does not solve the problem. If I want to copy a piece of text, or a picture. Then, after selecting it, use ctrl C and then ctrl V to copy and paste it. By the way, what I want to talk about next is to block the left button (what? Block the left button? Then this web page is almost useless? Don’t worry, I haven’t finished it yet. It’s annoying that the left button has only one function) Selected functions.
So, as mentioned above, it is useless to use JS to block. It treats the symptoms but not the root cause. So, let’s define it in the most basic language of web pages: HTML. It’s still an old trick, define . The parameter used this time is: onselectstart. It is the parameter selected by the left button. The code is as follows:

〈body onselectstart="return false"〉
Copy after login

In this way, the left-click selection function can be easily blocked. The principle is the same as above. Now, it is no longer useful to select anything with your left click. Naturally, you can't ctrl C or ctrl V. So, now let's merge these two parts. Complete control of the left and right keys! :

〈body oncontextmenu=self.event.returnValue=false onselectstart="return false"〉
Copy after login

Now, the problem of left and right keys has finally been solved.

OK, now let’s look at another question. As we all know, it is in the "View" item in the menu bar of the IE browser. There is a "view source" option. In this way, although we have blocked the view source code in the right click. However, you can still see the source code as long as you use View Source Code in the menu bar. What to do?

My initial idea was to use a framework to avoid viewing the source code. In other words, as long as a web page is embedded in a frame, then if you select View Source Code in the menu bar, you will only see the source code of the frame web page. The general format is as follows:

〈html〉  
〈head〉  
〈meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312"〉  
〈title〉本网站标题〈/title〉  
〈/head〉  
〈frameset rows="47,*" framespacing="0" border="0" frameborder="0"〉  
〈frame name="header" scrolling="no" noresize target="main" src="top.htm"〉  
〈frame name="main" src="main.htm" scrolling="auto" target="_self"〉  
〈noframes〉  
〈body〉  
〈p〉此网页使用了框架,但您的浏览器不支持框架。〈/p〉  
〈/body〉  
〈/noframes〉  
〈/frameset〉  
〈/html〉
Copy after login

This way it seems that the other party has not directly seen your source code. However, if a person wants to read your source code, he will probably be able to understand it. If you know a little HTML, you can see what these two sentences mean:

〈frame name="header" scrolling="no" noresize target="main" src="top.htm"〉  
〈frame name="main" src="main.htm" scrolling="auto" target="_self"〉
Copy after login

  这两句的意思就是:在header(也就是网页顶部)处引用相对路径下的top.htm网页文件。而在main(也就是占据网页大部分页面的位置)处引用相对路径下的main.htm网页文件。就这两点是关键的,其他就不作解释了,大家也都懂的。而上面所讲的利用框架来隐藏源代码的方法就是将要显示页面放在main部分。而将header部分的大小设为0。但是这样一来,利用菜单栏里的查看源代码,还是能查看到框架网页的源代码。只要看到这两句,就知道我们前面用的手法了。也就是说,只要将框架网页的名字改为目标网页,便可以用相同的方法直接看到目标网页的源代码了。如:框架网页:http://www.php.cn/的源代码如上,就可以改为http://www.php.cn/。这样便可直接浏览被保护网页,屏蔽源代码的效果还是没有达到。

  那么,有些人就会想到,如果对方看不到框架网页的源代码。又何谈去直接打开被保护网页?对,这就是接下来我要讲的。如果要一个页面的菜单栏内的查看源代码失去效用。那最简单的办法就是去掉菜单栏。而这一点是可以通过弹出窗口来实现的。之所以不选用超链接打开无菜单栏窗口是因为那样会暴露目标地址,浏览者可以直接在浏览器中敲入地址,而绕过这个屏蔽的菜单栏。要使用超链接打开无菜单栏窗口,就必须在一个已受到源代码屏蔽保障的网页中使用相关链接。
  那么,我们就看看如何利用弹出窗口来去掉菜单栏。其实,我们要做的,就是让目标网页在一个广告条中打开。这个代码几乎每个大型网站都会有的。代码如下:

〈script〉  
〈!--  
window.open("red.htm", "red", "resizable=yes,width=500,height=300");  
--〉  
〈/script〉
Copy after login

  这里,在window.open后的括号里的第一个参数就是弹出窗口所显示的网页的位置,这里例子里是先对位置下的red.htm网页文件。这时运行便会谈出一个显示有red.htm的无菜单栏的窗口。好,我们的目的达到了。但是,这个窗口有一个缺陷,就是没有滚动条。因为在谈出窗口的语句:window.open里并没有关于滚动条的参数,(或是我不知道?欢迎高手来信指出),所以这里打开的网页建议只做成网页的导航页。

  但是,用以上方法取消菜单栏,必须有一个第二方的网页来作弹出的工作。那么,这个用来弹出窗口的网页又成为了一个问题的所在。举例来说:假设,我们用一个index.htm来作弹出窗口的工作。也就是打开index.htm之后,会弹出red.htm的无菜单栏窗口。前面我们也提到了,如果知道了一个网页的地址后,无论这个网页是否隐藏在无菜单栏之下,你都能看到它的源代码。那么,不让这个red.htm的地址暴露也就成了解决这个问题的关键。但是,只要这个index.htm被打开,就可以看到源代码。但是,不妨反过来想想,如果我们把index.htm给关起来呢?只要在浏览者没有来得及查看index.htm之前将它关闭,就能保住它的源代码了。那么,在这个index.htm里就有得做些文章了。

  那就是,添加关闭网页的代码。

  那么,我们就可以用window.close来关闭窗口。代码如下:

〈script〉  
〈!--  
window.close();  
--〉  
〈/script〉
Copy after login

  那么,现在我们把两部分代码合并起来。现在,得到的效果就是——直接有一个无菜单栏的窗口打开了。因为计算机的处理速度很快,如果我们将这两段代码紧接着写在一起,那么我们就只能看到新建的窗口。代码如下:

〈script〉  
〈!--  
window.open("red.htm", "red", "resizable=yes,width=500,height=300");  
window.close();  
--〉  
〈/script〉
Copy after login

  而原来的窗口,已在我们无察觉的情况下关闭了。这样,就别说查看该网页的源代码了。这里,加入上面源代码的网页起了一个跳板的作用。但是,在这里,我们要注意几点。第一,用来做跳板的网页不应该命名为index.htm。将它换一个名字,然后把默认首页的名字改为更改过的名字。这样,是浏览者能在输入网之后便自动访问该页。而又不致让对方知道该页的名称。如果不这样做,就会导致对方猜测出该页的位置。如:172.0.0.0/index.htm。这样,就可以通过在浏览器中提交:View-Source:http://www.php.cn/就可以看到该页的源代码了。

  在屏蔽掉了菜单栏和工具栏之后,我们想,如果没有了最上方的窗口条该多好呢?下面我们要做的事情,有前提,就是在上面所说的在利用跳板页面打开一个无菜单栏的窗口之后。我们要做什么呢?就是让我们显示网站内容的窗口只显示内容,(是啊,网站不就是给别人浏览的吗?要浏览器和windows的那么多功能做什么呀……)只要内容,其余一律去掉。我们就可以通过一段Javascript来完成。下面这段代码就是用来定义无任何窗口特征的代码:

〈script〉  
function open1(url){  
newwin=window.open(url,'newwindow','fullscreen=1')  
newwin.resizeTo(800,600)  
newwin.moveTo(screen.width/0-800,screen.height/0-600)  
}  
〈/script〉
Copy after login

  其中,function open1(url)定义了超链接的写法。所以,我们在写链接的地址时,应该这样写:javascript:open1(url)。比如我要打开一个无窗口特征的新浪首页就应该在文字或图片的超链接里这样写:javascript:open1(‘http:www.sina.com.cn')。当然,括号内也支持相对路径。最后写出来的格式应该是:

〈script〉  
function open1(url){  
newwin=window.open(url,'newwindow','fullscreen=1')  
newwin.resizeTo(800,600)  
newwin.moveTo(screen.width/0-800,screen.height/0-600)  
}  
〈/script〉  
〈body oncontextmenu=self.event.returnValue=false onselectstart="return false"〉  
〈td width="100%"〉〈a href="javascript:open1('main.htm'),window.close()"〉〈img border="0" src="pic/blank1.gif" style="position: absolute; left: 556; top: 142" width="169" height="57"〉〈/a〉〈/td〉  
〈/body〉
Copy after login

  这样,我们就达到了打开无窗口边的网页了。并且,在这个网页中,会自动加入滚动条,这样,就不会像前面那样看不到下面的内容啦。

  最后我们要做的工作,就是把每一页,或者你认为重要的关键的页面进行加密,就OK啦。怎样对网页的源代码进行加密就不用我多说了吧?网上到处都有,可以用工具,也可以自己写一个htm文件来转换。加密软件,我推荐“Batch HTML Encryptor”,去google找吧。还有转换加密网页的代码如下:

〈HTML〉〈HEAD〉〈TITLE〉网页加密解密〈/TITLE〉  
〈META http-equiv=Content-Type content="text/html; charset=gb2312"〉  
〈META content="MSHTML 6.00.2600.0" name=GENERATOR〉〈!-- 大地软件工作室--〉〈LINK  
href="/style.css" rel=stylesheet〉  
〈META content="Microsoft FrontPage 4.0" name=GENERATOR〉  
〈/HEAD〉  
〈BODY bgColor=#ffffff leftMargin=0 topMargin=0 onload=initStyleElements()〉  
〈p  
style="LEFT: 139px; WIDTH: 106px; POSITION: absolute; TOP: 52px; HEIGHT: 36px"〉  
〈TABLE cellSpacing=0 cellPadding=0 width=760 align=center border=0〉〈!--DWLayoutTable--〉  
〈TBODY〉  
〈TR〉  
〈TD vAlign=top align=middle width=760 height=310〉  
〈p align=center〉  
〈H2〉  
〈SCRIPT language=JavaScript〉  
〈!--  
var i=0;  
var ie=(document.all)?1:0;  
var ns=(document.layers)?1:0;  
function initStyleElements() /* Styles for Buttons Init */  
{  
var c = document.pad;  
if (ie)  
{  
//c.text.style.backgroundColor="#DDDDDD";  
c.compileIt.style.backgroundColor="#C0C0A8";  
c.compileIt.style.cursor="hand";  
c.select.style.backgroundColor="#C0C0A8";  
c.select.style.cursor="hand";  
c.view.style.backgroundColor="#C0C0A8";  
c.view.style.cursor="hand";  
c.retur.style.backgroundColor="#C0C0A8";  
c.retur.style.cursor="hand";  
c.clear.style.backgroundColor="#C0C0A8";  
c.clear.style.cursor="hand";  
}  
else return;  
}  
/* Buttons Enlightment of "Compilation" panel */  
function LightOn(what)  
{  
if (ie) what.style.backgroundColor = '#E0E0D0';  
else return;  
}  
function FocusOn(what)  
{  
if (ie) what.style.backgroundColor = '#EBEBEB';  
else return;  
}  
function LightOut(what)  
{  
if (ie) what.style.backgroundColor = '#C0C0A8';  
else return;  
}  
function FocusOff(what)  
{  
if (ie) what.style.backgroundColor = '#DDDDDD';  
else return;  
}  
/* Buttons Enlightment of "Compilation" panel */  
function generate() /* Generation of "Compilation" */  
{  
code = document.pad.text.value;  
if (code)  
{  
document.pad.text.value='Compiling...Please wait!';  
setTimeout("compile()",1000);  
}  
else alert('First enter something to compile and then press CompileIt')  
}  
function compile() /* The "Compilation" */  
{  
document.pad.text.value='';  
compilation=escape(code);  
document.pad.text.value="/〈script〉\n〈!--\ndocument.write(unescape(\""+compilation+"\"));\n//--〉\n〈\/script〉";  
i++;  
if (i=1) alert("Page compiled 1 time!");  
else alert("Page compiled "+i+" times!");  
}  
function selectCode() /* Selecting "Compilation" for Copying */  
{  
if(document.pad.text.value.length〉0)  
{  
document.pad.text.focus();  
document.pad.text.select();  
}  
else alert('Nothing for be selected!')  
}  
function preview() /* Preview for the "Compilation" */  
{  
if(document.pad.text.value.length〉0)  
{  
pr=window.open("","Preview","scrollbars=1,menubar=1,status=1,width=700, 
height=320,left=50,top=110");  
pr.document.write(document.pad.text.value);  
}  
else alert('Nothing for be previewed!')  
}  
function uncompile() /* Decompiling a "Compilation" */  
{  
if (document.pad.text.value.length〉0)  
{  
source=unescape(document.pad.text.value);  
document.pad.text.value=""+source+"";  
}  
else alert('You need compiled code to uncompile it!')  
}  
// --〉  
〈/SCRIPT〉  
〈BR〉〈B〉〈FONT color=#333333〉网页HTML源代码加密解密器〈/FONT〉〈/B〉〈/H2〉〈/p〉  
〈TABLE cellSpacing=0 borderColorDark=#000000 cellPadding=10 width=750  
align=center borderColorLight=#ffffff border=2〉  
〈TBODY〉  
〈TR〉  
〈TD〉  
〈p align=center〉〈BR〉将你的源代码贴到编辑区域即可〈BR〉〈BR〉  
〈TABLE cellSpacing=0 cellPadding=0 width="100%" border=0〉  
〈TBODY〉  
〈TR〉  
〈TD width="100%"〉〈!-- Compilation Panel --〉  
〈FORM name=pad method=post align="center"〉  
〈p align=center〉〈TEXTAREA style="WIDTH: 95%; BACKGROUND-COLOR: #ebebeb" name=text rows=11 cols=58〉〈/TEXTAREA〉  
〈BR〉〈BR〉〈BR〉〈INPUT onmouseover=LightOn(this) onclick=generate() onmouseout=LightOut(this) type=button value=加密 name=compileIt〉  
〈INPUT onmouseover=LightOn(this) onclick=selectCode() onmouseout=LightOut(this) type=button value=全选 name=select〉  
〈INPUT onmouseover=LightOn(this) onclick=preview() onmouseout=LightOut(this) type=button value=预览 name=view〉  
〈INPUT onmouseover=LightOn(this) onclick=uncompile() onmouseout=LightOut(this) type=button value=解密 name=retur〉  
〈INPUT onmouseover=LightOn(this) onmouseout=LightOut(this) type=reset value=清除 name=clear〉  
〈/p〉〈/FORM〉〈!-- Compilation Panel --〉〈/TD〉〈/TR〉〈/TBODY〉〈/TABLE〉〈/p〉〈/TD〉〈/TR〉〈/TBODY〉〈/TABLE〉  
〈p align=center〉〈BR〉〈/p〉  
〈p align=center〉〈/p〉 〈/TD〉〈/TR〉〈/TBODY〉〈/TABLE〉  
〈/p〉  
〈p〉〈/p〉〈/BODY〉〈/HTML〉
Copy after login

  总结一下……按我的思路,屏蔽网页源代码主要分为以下几个步骤: 

  1. 做一个网页跳板,弹出要保护的广告条状页面,并将自身关闭,以避免泄露需保护网页的地址。

  2. 由于上述条件屏蔽了广告条内网页的源代码,所以可以用这个网页作为欢迎页。

  3. 在欢迎页中,利用Javascript以超连接的形式来打开无窗口边的新窗口显示网站内容。

  4. 对每一个页面或者对重要的关键的页面进行源代码加密,为源代码加一把锁。(有些人说对源代码进行加密没有用,但是我觉得要使用另类点的加密方法就可以了,比如软件的加密方法就很普通。但是用我自己写的htm文件加密的源代码,一般软件是不能进行解密的。大家有兴趣的话可以试试。) 

  5. 最后不得不提的就是windows网页临时文件夹了,那里面会把源代码纪录的。但是不用怕,加入一种代码,就可以使windows不下载网页的源代码,直接浏览。可以去找找。 

  有些东西要注意的: 

  1. 在文中所说的自动关闭网页的语句:window.close()有一个弊病。就是会在关闭窗口之前询问是否关闭窗口,如果选择否的话目的还是达不到。 

  2. 以上一切都只对IE浏览器有效用,如果用别的浏览器来浏览,就有可能出现屏蔽不成功的现象。

  3. 关于网页源代码屏蔽,一直以来是可望而不可及的。我只是把思路写下来,具体实现,还是要靠大家自己研究的啦。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve win7 driver code 28 How to solve win7 driver code 28 Dec 30, 2023 pm 11:55 PM

Some users encountered errors when installing the device, prompting error code 28. In fact, this is mainly due to the driver. We only need to solve the problem of win7 driver code 28. Let’s take a look at what should be done. Do it. What to do with win7 driver code 28: First, we need to click on the start menu in the lower left corner of the screen. Then, find and click the "Control Panel" option in the pop-up menu. This option is usually located at or near the bottom of the menu. After clicking, the system will automatically open the control panel interface. In the control panel, we can perform various system settings and management operations. This is the first step in the nostalgia cleaning level, I hope it helps. Then we need to proceed and enter the system and

What to do if the blue screen code 0x0000001 occurs What to do if the blue screen code 0x0000001 occurs Feb 23, 2024 am 08:09 AM

What to do with blue screen code 0x0000001? The blue screen error is a warning mechanism when there is a problem with the computer system or hardware. Code 0x0000001 usually indicates a hardware or driver failure. When users suddenly encounter a blue screen error while using their computer, they may feel panicked and at a loss. Fortunately, most blue screen errors can be troubleshooted and dealt with with a few simple steps. This article will introduce readers to some methods to solve the blue screen error code 0x0000001. First, when encountering a blue screen error, we can try to restart

Solve the 'error: expected initializer before 'datatype'' problem in C++ code Solve the 'error: expected initializer before 'datatype'' problem in C++ code Aug 25, 2023 pm 01:24 PM

Solve the "error:expectedinitializerbefore'datatype'" problem in C++ code. In C++ programming, sometimes we encounter some compilation errors when writing code. One of the common errors is "error:expectedinitializerbefore'datatype'". This error usually occurs in a variable declaration or function definition and may cause the program to fail to compile correctly or

The computer frequently blue screens and the code is different every time The computer frequently blue screens and the code is different every time Jan 06, 2024 pm 10:53 PM

The win10 system is a very excellent high-intelligence system. Its powerful intelligence can bring the best user experience to users. Under normal circumstances, users’ win10 system computers will not have any problems! However, it is inevitable that various faults will occur in excellent computers. Recently, friends have been reporting that their win10 systems have encountered frequent blue screens! Today, the editor will bring you solutions to different codes that cause frequent blue screens in Windows 10 computers. Let’s take a look. Solutions to frequent computer blue screens with different codes each time: causes of various fault codes and solution suggestions 1. Cause of 0×000000116 fault: It should be that the graphics card driver is incompatible. Solution: It is recommended to replace the original manufacturer's driver. 2,

GE universal remote codes program on any device GE universal remote codes program on any device Mar 02, 2024 pm 01:58 PM

If you need to program any device remotely, this article will help you. We will share the top GE universal remote codes for programming any device. What is a GE remote control? GEUniversalRemote is a remote control that can be used to control multiple devices such as smart TVs, LG, Vizio, Sony, Blu-ray, DVD, DVR, Roku, AppleTV, streaming media players and more. GEUniversal remote controls come in various models with different features and functions. GEUniversalRemote can control up to four devices. Top Universal Remote Codes to Program on Any Device GE remotes come with a set of codes that allow them to work with different devices. you may

Resolve code 0xc000007b error Resolve code 0xc000007b error Feb 18, 2024 pm 07:34 PM

Termination Code 0xc000007b While using your computer, you sometimes encounter various problems and error codes. Among them, the termination code is the most disturbing, especially the termination code 0xc000007b. This code indicates that an application cannot start properly, causing inconvenience to the user. First, let’s understand the meaning of termination code 0xc000007b. This code is a Windows operating system error code that usually occurs when a 32-bit application tries to run on a 64-bit operating system. It means it should

What does the blue screen code 0x000000d1 represent? What does the blue screen code 0x000000d1 represent? Feb 18, 2024 pm 01:35 PM

What does the 0x000000d1 blue screen code mean? In recent years, with the popularization of computers and the rapid development of the Internet, the stability and security issues of the operating system have become increasingly prominent. A common problem is blue screen errors, code 0x000000d1 is one of them. A blue screen error, or "Blue Screen of Death," is a condition that occurs when a computer experiences a severe system failure. When the system cannot recover from the error, the Windows operating system displays a blue screen with the error code on the screen. These error codes

Detailed explanation of the causes and solutions of 0x0000007f blue screen code Detailed explanation of the causes and solutions of 0x0000007f blue screen code Dec 25, 2023 pm 02:19 PM

Blue screen is a problem we often encounter when using the system. Depending on the error code, there will be many different reasons and solutions. For example, when we encounter the problem of stop: 0x0000007f, it may be a hardware or software error. Let’s follow the editor to find out the solution. 0x000000c5 blue screen code reason: Answer: The memory, CPU, and graphics card are suddenly overclocked, or the software is running incorrectly. Solution 1: 1. Keep pressing F8 to enter when booting, select safe mode, and press Enter to enter. 2. After entering safe mode, press win+r to open the run window, enter cmd, and press Enter. 3. In the command prompt window, enter "chkdsk /f /r", press Enter, and then press the y key. 4.

See all articles