幾種ASP源代碼保護(hù)方法:
1,“腳本最小化”即ASP文件中只編寫盡可能少的源代碼,實(shí)現(xiàn)
商業(yè)邏輯的腳本部分被封裝到一個(gè)COM/DCOM組件,并在ASP腳
本中創(chuàng)建該組件,進(jìn)而調(diào)用相應(yīng)的方法(methed)即可。應(yīng)用開發(fā)者
動(dòng)手開發(fā)ASP腳本應(yīng)用之前就可按此思路來開發(fā),或者直接用ASP
腳本快速開發(fā)出原型系統(tǒng)后,針對(duì)需要保護(hù)、加密的重要腳本用
COM/DCOM組件來重新開發(fā)、實(shí)現(xiàn)并替換。
2,“腳本加密”即ASP腳本仍直接按源代碼方式進(jìn)行開發(fā),但在發(fā)布到運(yùn)行環(huán)境之前將腳本進(jìn)行加密處理,只要把加密后的密文腳本發(fā)布出去。即在ASP.DLL讀取腳本這個(gè)環(huán)節(jié)加入密文還原的處理。實(shí)現(xiàn)這種思路的方法有兩種:一是自行開發(fā)一個(gè)ISAPI的IIS過濾(filter)塊,在ASP.DLL之前勾連(hook)對(duì)ASP腳本文件的讀取,以便把文件系統(tǒng)讀出的密文還原成ASP.DLL可以解釋的明文;
方法二是直接由ASP.DLL提供對(duì)ASP腳本加密處理的支持。微軟在新版本的Vbscript.dll jscript.dll中提供這種成為MS script encode技術(shù)的支持。這樣,無論是客戶端的Vbscript jscript(包括WSH腳本等),還是服務(wù)器端的Vbscript jscript (即ASP腳本)都可以支持加密處理。
MS script encode 技術(shù)具體的實(shí)現(xiàn)思路包括以下兩個(gè)方面:一是加密過程,通過提供一個(gè)實(shí)用程序?qū)Π珹SP腳本源代碼的文本文件 進(jìn)行掃描,找出其標(biāo)記為<script language = "vbscript.encode">或<script language = "Jscript.encode">;二是還原過程,IE或ASP.DLL等執(zhí)行 腳本時(shí)是統(tǒng)一通過Vbscript.dll jscript.dll來解釋執(zhí)行的,所以它們都能同時(shí)地、透明地支持明文和密文的腳本。
總之,如果采用第一種思路,要么就自行在開發(fā)過程中遵照進(jìn)行,
要么可以考慮選擇自動(dòng)轉(zhuǎn)換成visual basic 編譯代碼的通用的、實(shí)用工具;采取第二種思路的化,要么就自行開發(fā)IIS ISAPI過濾模塊,要么可以考慮直接采用MS script encode軟件。
下面來看看一種ASP可以使用的簡(jiǎn)單字符加密算法,而不是那些受限制的加密算法。其實(shí),這里介紹的加密算法對(duì)于一般的運(yùn)用來說已經(jīng)足夠解密人麻煩一陣子的了。它的加密基礎(chǔ)是最簡(jiǎn)單的Vernum密碼方法,
它的基本原理是,需要有一個(gè)需要加密的明文和一個(gè)隨機(jī)生成的解密鑰匙文件。然后
使用這兩個(gè)文件組合起來生成密文。
(明文) 組合 (密鑰) = 加密后的密文
所以這里介紹的是生成密鑰的代碼。我們假設(shè)我們生成的密鑰為512位長(zhǎng)的密鑰,
它已經(jīng)足夠來加密一個(gè)文本字符了。代碼如下:
KeyGeN.asp文件
<%
'******************************
' KeyGeN.asp
'******************************
Const g_KeyLocation = "C:\key.txt"
Const g_KeyLen = 512
On Error Resume Next
Call WriteKeyToFile(KeyGeN(g_KeyLen),g_KeyLocation)
if Err <> 0 Then
Response.Write "ERROR GENERATING KEY." & "
"
Response.Write Err.Number & "
"
Response.Write Err.Description & "
"
Else
Response.Write "KEY SUCCESSFULLY GENERATED."
End If
Sub WriteKeyToFile(MyKeyString,strFileName)
Dim keyFile, fso
set fso = Server.CreateObject("scripting.FileSystemObject")
set keyFile = fso.CreateTextFile(strFileName, true)
keyFile.WriteLine(MyKeyString)
keyFile.Close
End Sub
Function KeyGeN(iKeyLength)
Dim k, iCount, strMyKey
lowerbound = 35
upperbound = 96
Randomize ' Initialize random-number generator.
for i = 1 to iKeyLength
s = 255
k = Int(((upperbound - lowerbound) + 1) * Rnd + lowerbound)
strMyKey = strMyKey & Chr(k) & ""
next
KeyGeN = strMyKey
End Function
%>
在IIS下運(yùn)行上面的KeyGeN.asp頁(yè)面。你只需要如此做一次,他將把密鑰寫入文件
c:\key.txt中 (如果你愿意的話,你也可以把這個(gè)文件放到另外一個(gè)更加安全的地方).
然后你可以打開這個(gè)key.txt文件,它將包含512個(gè)ASCII碼在35到96之間的字符.
并且由于是隨機(jī)生成的,所以每個(gè)人的私人密鑰文件key.txt將是不一樣的,下面是
一個(gè)例子密鑰文件:
IY/;$>=3)?^-+7M32#Q]VOII.Q=OFMC`:P7_B;#,+.AW_/+')DIB;2DTIA57TT&-]O'/*F'M>H.XH5W^0Y*=71+5*^`^PKJ(=E/X#7A:?,S>R&T;+B#<:-*\@)X9F`_`%QA3Z95.?_T#1,$2#FWW5PBH^*<))A(S0@AVD8C^Q0R^T1D?(1+,YE71X+.*+U$:3XO^Q).KG&0N0);[LJ
下面再仔細(xì)分析一下上面的程序,我們發(fā)現(xiàn)其中的lowerbound和upperbound的數(shù)值
其實(shí)就是你想使用來加密的ASCII字符范圍。
下面的代碼將介紹如何使用這個(gè)密鑰來加密和解密一個(gè)字符串
Crypt.asp文件
<%
Dim g_Key
Const g_CryptThis = "Now is the time for all good men to come to the aid of their country."
Const g_KeyLocation = "c:\key.txt"
g_Key = mid(ReadKeyFromFile(g_KeyLocation),1,Len(g_CryptThis))
Response.Write "ORIGINAL STRING: " & g_CryptThis & "
"
Response.Write "
KEY VALUE: " & g_Key & "
"
Response.Write "
ENCRYPTED CYPHERTEXT: " & EnCrypt(g_CryptThis) & "
"
Response.Write "
DECRYPTED CYPHERTEXT: " & DeCrypt(EnCrypt(g_CryptThis)) & "
"
Function EnCrypt(strCryptThis)
Dim strChar, iKeyChar, iStringChar, i
for i = 1 to Len(strCryptThis)
iKeyChar = Asc(mid(g_Key,i,1))
iStringChar = Asc(mid(strCryptThis,i,1))
' *** uncomment below to encrypt with addition,
' iCryptChar = iStringChar + iKeyChar
iCryptChar = iKeyChar Xor iStringChar
strEncrypted = strEncrypted & Chr(iCryptChar)
next
EnCrypt = strEncrypted
End Function
Function DeCrypt(strEncrypted)
Dim strChar, iKeyChar, iStringChar, i
for i = 1 to Len(strEncrypted)
iKeyChar = (Asc(mid(g_Key,i,1)))
iStringChar = Asc(mid(strEncrypted,i,1))
' *** uncomment below to decrypt with subtraction
' iDeCryptChar = iStringChar - iKeyChar
iDeCryptChar = iKeyChar Xor iStringChar
strDecrypted = strDecrypted & Chr(iDeCryptChar)
next
DeCrypt = strDecrypted
End Function
Function ReadKeyFromFile(strFileName)
Dim keyFile, fso, f
set fso = Server.CreateObject("Scripting.FileSystemObject")
set f = fso.GetFile(strFileName)
set ts = f.OpenAsTextStream(1, -2)
Do While not ts.AtEndOfStream
keyFile = keyFile & ts.ReadLine
Loop
ReadKeyFromFile = keyFile
End Function
%>
在Crypt.asp中我們首先從密鑰文件中得到密鑰值,然后從這段密鑰中
截取和我們需要加密的明文同樣長(zhǎng)度的密鑰。然后使用一個(gè)簡(jiǎn)單的異或操作
將明文和密鑰進(jìn)行運(yùn)算,那么得到的結(jié)果就是加密后的密文了。過程很簡(jiǎn)單的。
由于是使用了異或操作,所以解密將非常簡(jiǎn)單,只要使用同樣的密鑰對(duì)密文
再次進(jìn)行異或操作就能夠解密了。
在上面介紹的基礎(chǔ)上,你可以少加改動(dòng),就可以使用同樣的方法加密一個(gè)文件。
唯一需要注意的是,對(duì)于一個(gè)二進(jìn)制文件,你需要做一些完整性檢查以保證轉(zhuǎn)換回來
的字符不要越界。
現(xiàn)在你需要做的就是把密鑰保存在服務(wù)器上的一個(gè)安全的地方(不能夠被外部訪問)
15 SQL SERVER的安全性
目前用ASP編寫的WEB應(yīng)用中,后臺(tái)數(shù)據(jù)庫(kù)大部分SQL SERVER。SQL SERVER相對(duì)來說比較安全。但是也要小心地配置SQL Server.
1安裝遠(yuǎn)程數(shù)據(jù)庫(kù)管理有風(fēng)險(xiǎn)
SQL Server支持從遠(yuǎn)程進(jìn)行數(shù)據(jù)庫(kù)的維護(hù)。在安裝時(shí)你可以選擇不安裝,安裝完成以后,你還可以通過“SQL Server Network Utility”來刪除遠(yuǎn)程管理。如果你要使用遠(yuǎn)程管理,請(qǐng)使用TCP/IP,并將缺省的端口1433改變?yōu)槠渌臄?shù)值。使用遠(yuǎn)程對(duì)你可能比較方便,便是請(qǐng)注意一個(gè)hacker只要知道你的SQL server密碼,就可以進(jìn)入你的數(shù)據(jù)庫(kù)。
2 改變sa的密碼。
缺省安裝時(shí),SQL SERVER的sa賬號(hào)的密碼為空,建議你在Enterprise SERVER中,改變sa的密碼。
3 數(shù)據(jù)庫(kù)登錄賬號(hào)不要寫入ASP頁(yè)面中。
16 使用最新的掃描器掃描ASP漏洞
目前可以掃描IIS漏洞的掃描器有很多,比較有名的有ISS,CIS和gnit等。下面我們以GNIT為例子。
GNIT是個(gè)功能很強(qiáng)的漏洞掃描器,能掃描NT的用戶名和相關(guān)信息列表,掃描IIS的漏洞。
在WINNT的DOS模式下打下:
gnit <對(duì)方IP>
比如:gnit 172.1.1.1
GNIT開始掃描端口,從上圖可知目標(biāo)主機(jī)提供了HTTP,F(xiàn)TP,SMTP等服務(wù),掃描完后。會(huì)在GNIT目錄下生成一個(gè)HTML文件,其文件名是目標(biāo)主機(jī)的IP。打開這個(gè)HTML文件,會(huì)看到對(duì)方主機(jī)的一些信息和漏洞。這些信息和漏洞包括:用戶名和組的相關(guān)詳細(xì)信息,開放的服務(wù)和WEB掃描的漏洞等。我們比較關(guān)心的是WEB掃描的漏洞信息:
下圖是GNIT的WEB掃描一些信息,其中加粗部分是漏洞,當(dāng)然有些漏洞并不準(zhǔn)確,但不妨試試。(有必要說明下,以下我是在一臺(tái)NT4。01,IIS4。0,Option PACK6.0,并且缺省安裝)
要測(cè)試這些漏洞很簡(jiǎn)單。比如:可在URL輸入:
http://someurl/iisadmpwd/aexp3.htr
―――可遠(yuǎn)程管理IIS。
http://someurl/scripts/iisadmin/bdir.htr
――――目標(biāo)主機(jī)的硬盤全部目錄都一覽無余,并且有創(chuàng)建新目錄的功能(不過我在測(cè)試中,并不能創(chuàng)建遠(yuǎn)程目錄,但是能使目標(biāo)主機(jī)的WEB當(dāng)機(jī))
http://someurl/scripts/tools/getdrvrs.exe
----可在遠(yuǎn)程主機(jī)上創(chuàng)建ODBC數(shù)據(jù)庫(kù),不管數(shù)據(jù)庫(kù)路徑和數(shù)據(jù)庫(kù)是否存在。
此外還有其它的漏洞,請(qǐng)網(wǎng)友自己測(cè)試。其解決方法請(qǐng)看上面的漏洞分析。
如果用CIS掃描器,還有比較詳細(xì)的漏洞分析和解決方法。請(qǐng)讀者自己分析。
七、總結(jié)
目前WEB數(shù)據(jù)庫(kù)訪問的多種技術(shù)中,比如CGI(通用網(wǎng)關(guān)接口)、JDBC、PHP、ASP,ASP以其開發(fā)周期短,存取方式數(shù)據(jù)庫(kù)簡(jiǎn)單,運(yùn)行速度快而成為眾多網(wǎng)站程序員的首選開發(fā)技術(shù)。
但是其網(wǎng)絡(luò)安全性也是不容忽視的。做為一個(gè)ASP開發(fā)者,你必須關(guān)注NT和IIS的安全漏洞,從上面的討論我們可以看到ASP的很多漏洞都是由IIS所引起的。同時(shí)ASP程序員在開發(fā)自己的網(wǎng)站時(shí),要注意來自ASP程序設(shè)計(jì)不當(dāng)所引發(fā)的安全問題。
八、聲明
本文中某些例子是從其它網(wǎng)站上整理的,因時(shí)間緊迫,未來得及通知作者,請(qǐng)見諒!
【責(zé)任編輯 李旭?!?/span>
|
<script language="JavaScript">
var elady_step=3; //1:small, 3:middle, 5:big
var elady_speed=50; //20:fast, 50:middle, 80:slow
var e_tp=new Array();
var e_tplink=new Array();
var adNum_elady1=0;
e_tplink[0]="http://www.yumaovr.com/article/2005/0627/A20050627428510.shtml";
e_tp[0]="http://images.enet.com.cn/eschool/gdtup/tu1/865656.gif";
e_tplink[1]="http://www.yumaovr.com/eschool/zhuanti/upps/";
e_tp[1]="http://images.enet.com.cn/eschool/gdtup/tu1/psdfij145x110.jpg";
e_tplink[2]="http://www.yumaovr.com/article/2007/0213/A20070213441982.shtml";
e_tp[2]="http://images.enet.com.cn/eschool/gdtup/tu1/bbef145x110.jpg";
e_tplink[3]="http://www.yumaovr.com/article/2005/0217/A20050217390910.shtml";
e_tp[3]="http://images.enet.com.cn/eschool/gdtup/tu1/Photoshopdazhangia.gif";
var currentimage=new Array();
for (i=0;i<=3;i++){currentimage[i]=new Image();
currentimage[i].src=e_tp[i];
}
function elady1_set(){ if (document.all)
{ e_tprotator.filters.revealTrans.Transition=Math.floor(Math.random()*23);
e_tprotator.filters.revealTrans.apply(); }
}
function elady1_playCo()
{ if (document.all) e_tprotator.filters.revealTrans.play()
}function elady1_nextAd(){ if(adNum_elady1");
document.write('');
document.write('');
document.write("");
</script>
|
|
<script type="text/javascript">
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
|
<script type="text/javascript">
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
|
<iframe SRC="/eschool/includes/movelist.html" frameborder=no MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=no align=center width=100% noResize height=130px></iframe> |
<iframe SRC="/eschool/includes/public/end.html" frameborder="no" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" width="100%" noResize height="164"></iframe>
|
|
<script defer id="_comment_script_">
_comment_script_.src="http://comment.enet.com.cn/list.jsp?articleid=20040216286717&site=eschool";
</script>
<iframe SRC='http://comment.enet.com.cn/commentform.jsp?articleid=20040216286717&site=eschool&url=http://www.yumaovr.com/article/2004/0216/A20040216286717.shtml&title=ASP漏洞及安全建議' width=570 height=186 frameborder=no border=0 MARGINWIDTH=0 MARGINHEIGHT=0 align=center scrolling=no></iframe>
|
<script type="text/javascript">
cpro_client='enet_1_cpr';
cpro_cbd='#trans';
cpro_cbg='#trans';
cpro_ctitle='#515151';
cpro_cdesc='#444444';
cpro_curl='#008000';
cpro_clink='#000000';
cpro_flush=2;
cpro_w=580;
cpro_h=90;
cpro_template='text_noframe_580_90';
</script>
<script language="JavaScript" type="text/javascript" src="http://cpro.baidu.com/cpro/ui/cp.js"></script>
|
<script defer id="_comment_script_"> _comment_script_.src="http://comment.enet.com.cn/list.jsp?articleid=" + a_id +"&site=" + a_channel;
</script>
<script>
document.write ("<iframe SRC='http://comment.enet.com.cn/commentform.jsp?articleid="+ a_id + "&site=" + a_channel +"&url="+a_path+"&title=" + a_title +"' width=615 height=186 frameborder=no border=0 MARGINWIDTH=0 MARGINHEIGHT=0 align=center scrolling=no></iframe>");
</script>
|
<iframe width=750 height=120 frameborder=no border=0 MARGINWIDTH=0 MARGINHEIGHT=0 align=center scrolling=no src="/eschool/includes/public/endhtml.html"></iframe>
<iframe id=eshooltongdinei width=750 height=90 noresize scrolling=No frameborder=0 marginheight=0 marginwidth=0></iframe>
|
|
<iframe id="eschoolskynei1" width="160" height="240" noresize="noresize" scrolling="No" frameborder="0" marginheight="0" marginwidth="0"></iframe>
|
|
<iframe id="eschoolskynei2" width="160" height="240" noresize="noresize" scrolling="No" frameborder="0" marginheight="0" marginwidth="0"></iframe>
|
|
|
<script language=javascript>
var m=3;
var n=Math.floor(Math.random()*m+1)
switch(n)
{
case 1:
document.write('<iframe SRC=/eschool/includes/gdtup/tu6/title1.html frameborder=no border=0 MARGINWIDTH=0 MARGINHEIGHT=0 align=center width=170 height=140 scrolling=no noResize></iframe>');
break;
case 2:
document.write('<iframe SRC=/eschool/includes/gdtup/tu6/title2.html frameborder=no border=0 MARGINWIDTH=0 MARGINHEIGHT=0 align=center width=170 height=140 scrolling=no noResize></iframe>');
break;
case 3:
document.write('<iframe SRC=/eschool/includes/gdtup/tu6/title3.html frameborder=no border=0 MARGINWIDTH=0 MARGINHEIGHT=0 align=center width=170 height=140 scrolling=no noResize></iframe>');
break;
}
//add by lixuhai
</script>
|
<iframe width=210 height=240 noresize scrolling=No frameborder=0 marginheight=0 marginwidth=0 src="http://www.yumaovr.com/elady/includes/v1/d_school.shtml"></iframe>
|
<script language="javascript">
function _submitProblem(){
if(problemForm.problemcontent.value==null||problemForm.problemcontent.value==""){
alert("問題內(nèi)容不可以為空!");
return;
}
problemForm.submit();
}
</script>
<script language="javascript" src="/includes/js/bottomsm.js"></script>
<script>
//通欄0--adv/tonglan1.htm
if(document.getElementById("tonglan0")) document.getElementById("tonglan0").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschool";
if(document.getElementById("eschoollin")) document.getElementById("eschoollin").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschoollin";
//通欄1--sub_top.htm
if(document.getElementById("tonglan1")) document.getElementById("tonglan1").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschoolunder";
//通欄2--adv/tonglan2.htm
if(document.getElementById("tonglan2")) document.getElementById("tonglan2").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschool2";
//通欄3--adv/tonglan3.htm
if(document.getElementById("tonglan3")) document.getElementById("tonglan3").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschool3";
//通欄4--botton_home.htm
if(document.getElementById("eschool3")) document.getElementById("eschool3").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschool3";
//首屏左側(cè)BUTTON1--button11.htm
if(document.getElementById("button1")) document.getElementById("button1").src="http://www.yumaovr.com/enetshow.shtml?Pool=etechposter";
//首屏右側(cè)BUTTON2--button5.htm
if(document.getElementById("eshoolbutton")) document.getElementById("eshoolbutton").src="http://www.yumaovr.com/enetshow.shtml?Pool=eshoolbutton";
if(document.getElementById("eschoolskynei1")) document.getElementById("eschoolskynei1").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschoolskynei1";
if(document.getElementById("eschoolskynei2")) document.getElementById("eschoolskynei2").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschoolskynei2";
if(document.getElementById("button3")) document.getElementById("button3").src="http://www.yumaovr.com/enetshow.shtml?Pool=eshoolbutton2";
if(document.getElementById("button4")) document.getElementById("button4").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschoolbutton120";
if(document.getElementById("eschoolsky")) document.getElementById("eschoolsky").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschoolsky";
if(document.getElementById("flash1")) document.getElementById("flash1").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschoolflash";
if(document.getElementById("eschoolflashlin")) document.getElementById("eschoolflashlin").src="http://www.yumaovr.com/enetshow.shtml?Pool=eschoolflashlin";
//文章頁(yè)banner
if(document.all.eschoolbanner)document.all.eschoolbanner.src="http://www.yumaovr.com/enetshow.shtml?Pool=eschoolbanner";
//if(document.all.eschoolbanner) document.all.eschoolbanner.src="/enews/includes/adv/banner2.html";
if(document.all.eshooltongdinei) document.all.eshooltongdinei.src="http://www.yumaovr.com/enetshow.shtml?Pool=eschool3";
//曝光加這
dTable="<iframe src='/eschool/includes/public/imglist.html' width='580 height='132' noresize scrolling='No' frameborder='0' marginheight='0' marginwidth='0'></iframe>";
//if(document.all.adv_under_cont) document.all.adv_under_cont.insertAdjacentHTML("AfterBegin",dTable);
</script>
<script language="JavaScript1.2">
publisher_id = 6235007045041206;
link_color = "#FF3366";
layer_background_color = "#FFFFFF";
_frame = 1;
layer_hover_color = "#FBF6FF";
title_text_color = "#9933FF";
ad_text_color = "#333333";
link_text_color = "#9933FF";
</script>
<script src="http://code.vogate.com/script/release/vogateADs2-enet.js"></script>