当前位置: 首页 > 图文教程 > 脚本技术 > VBScript > vbs脚本 加密 几个小细节小结下

VBScript
用vbscript得到注册表中是否存在某个值
用vbscript实现修改屏幕保护的等待时间长度
用vbscript实现在消息框中显示一个超链接
用vbscript实现将脚本的输出复制到剪贴板
视频转换大师WinMPG Video Convert 6.63
用vbs实现取消隐藏文件夹中的所有文件
用vbscript实现从文本文件中删除所有重复行的代码
用vbscript实现在文本文件中搜索两个项
用vbscript实现启用 Caps Lock (大写)键
vbscript和javascript版的15位, 18位的身份证号码的验证函数.以及根据身份证取省份,生日,性别
发老兵及海洋VBS解包工具代码
把vbscript发挥到它的极限应用之一(数组)!!!
VBScript:Join 函数一个不太常用,却很有用的函数
最新恶意复制型病毒autorun.inf,stNP.VBS,NP.VBS代码简单解析和解决方法
用vbscript脚本实现返回 IP 配置数据的代码
用vbs实现配置静态 IP 地址
用vbs得到计算机的 IP 地址
用vbs实现枚举网络连接的代码
IIS管理脚本之adsutil.vbs的使用说明
用VBS修改IIS Metabase的代码

VBScript 中的 vbs脚本 加密 几个小细节小结下


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-11   浏览: 71 ::
收藏到网摘: n/a

复制代码 代码如下:

dxy:
你好!
我学vbs也有一小段时间了,最近看到一本书上讲vbs脚本的加密,就自己试了试,可是有一点问题,低级的语法错误我都自己修正了,可脚本运行后不起作用.所以想请教你一下.脚本的原理是这样的:它把代码转换成16进制,然后再写个解密代码,通过这个解密来执行加密的代码,将字符串成16进制的代码如下:
Function str2hex (Byval strHex)
For i=1 to Len(strHex)
sHex = sHex & Hex(Asc(mid(strHex,i,1)))
next
str2Hex = sHex
end Function
解密的代码如下:
Function hextostr(data)
Hextostr = "Execute"""""
C= "&Chr(&H"
N= ")"
Do while Len(data)>1
if IsNumeric (Left(data,1)) then
Hextostr=Hextostr&c&Left(data,2)&N
data=mid(data,3)
else
Hextostr=HextoStr&C&Left(data,4)&N
data=mid(data,5)
end if
loop
end Function
解密代码好象有点问题,请帮忙指正,我实在找不出
整个成品就是:
on error resume next
set arg=wscript.arguement '声明外部参数
if arg.count=0 Then wscript.quit '若无参数则退出脚本
set fso=creatobject("Scripting.Filesystem Object") '声明fso组件
when fso.opentextfile(arg(0),1,flase)
data = readall:.close'读取文本内容
if err.number<>0 then wscript.quit '如果发生错误,则退出
with fso.opentextfile(arg(0)&"*.vbs",2,true) '将转换好的写到一个新的vbs中
if err.number<>0 then wscript.quit '如果发生错误,则退出
.writeline "Execute(Hextostr("""&str2hex(data)&"""))" '执行解密并执行解密后的代码
.writeline "Function hextostr(data)"
.writeline "Hextostr=""Execute"""""""""""
.writeline "C=""&CHR(&H"""
.writeline "N= )"
.writeline "Do while Len(data)>1"
.writeline "if IsNumeric (Left(data,1)) then"
.writeline "Hextostr=Hextostr&c&Left(data,2)&N"
.writeline "data = (data,3)"
.writeline "else"
.writeline "Hextostr=Hex to str&c&Left(data,4)&N"
.writeline "data=mid(data,5)"
.writeline "end if"
.writeline "loop"
.writeline "end function"
'把解密函数写进去
.close '关闭文本
set fso=Nothing'注销fso组件
end with
msgbox "OK"
'以下是加密函数
Function str2hex (Byval strHex)
For i=1 to Len(strHex)
sHex = sHex & Hex(Asc(mid(strHex,i,1)))
next
str2Hex = sHex
end function
'全部代码就到这了,好长~
书上说,把要加密的vbs脚本拖到这个脚本上就行了,不过我没有成功,不知道那里有问题,请帮帮我,谢谢~

上面的代码注意的几个情况:
1、set arg=wscript.arguements
后门有个s
2、set fso=creatobject("Scripting.Filesystem Object") '声明fso组件
应该是filesystemboject
3、.writeline "N= )"
对于需要输出N=")"用vbs输入"(双引号)的方法就是用两个""
.writeline "N="")"""
4、.writeline "data = (data,3)"这里少个mid
基本上就这些了
do.vbs保存为do.vbs ,将要加密的js文件拖到这个文件上就可以
复制代码 代码如下:

'on error resume next
set arg=wscript.arguments '声明外部参数
if arg.count=0 Then wscript.quit '若无参数则退出脚本
set fso=createobject("Scripting.FilesystemObject") '声明fso组件
filename=wscript.arguments(0)
set readline=fso.opentextfile(filename,1,flase)
data=readline.readall:
readline.close '读取文本内容
if err.number<>0 then wscript.quit '如果发生错误,则退出
with fso.opentextfile(filename&"_out.vbs",2,true) '将转换好的写到一个新的vbs中
if err.number<>0 then wscript.quit '如果发生错误,则退出
.writeline "Execute(Hextostr("""&str2hex(data)&"""))" '执行解密并执行解密后的代码
.writeline "Function hextostr(data)"
.writeline "Hextostr=""Execute"""""""""""
.writeline "C=""&CHR(&H"""
.writeline "N= "")"""
.writeline "Do while Len(data)>1"
.writeline "if IsNumeric (Left(data,1)) then"
.writeline "Hextostr=Hextostr&c&Left(data,2)&N"
.writeline "data = mid(data,3)"
.writeline "else"
.writeline "Hextostr=Hextostr&c&Left(data,4)&N"
.writeline "data=mid(data,5)"
.writeline "end if"
.writeline "loop"
.writeline "end function"
'把解密函数写进去
.close '关闭文本
end with
set fso=Nothing'注销fso组件
msgbox "OK"
'以下是加密函数
Function str2hex (Byval strHex)
For i=1 to Len(strHex)
sHex = sHex & Hex(Asc(mid(strHex,i,1)))
next
str2Hex = sHex
end function