当前位置: 移动技术网 > IT编程>脚本编程>VBScript > vbs脚本 加密 几个小细节小结下

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

山东女教师郑媛媛,半岛都市报电话,北平往事片尾曲

复制代码 代码如下:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网