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

PHP中文网
PHP中文网Original
2016-05-16 19:17:49939browse

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〉

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〉

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"〉

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"〉

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〉

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"〉

  这两句的意思就是:在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〉

  这里,在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〉

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

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

  而原来的窗口,已在我们无察觉的情况下关闭了。这样,就别说查看该网页的源代码了。这里,加入上面源代码的网页起了一个跳板的作用。但是,在这里,我们要注意几点。第一,用来做跳板的网页不应该命名为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〉

  其中,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〉

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

  最后我们要做的工作,就是把每一页,或者你认为重要的关键的页面进行加密,就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〉

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

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

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

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

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

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

  有些东西要注意的: 

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

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

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

Statement:
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