穷举破解EXCEL、 WORD文档密码的论文计算机理论论文
摘要本文讨论了如何使用vb编程通过穷举法解除excel文档和word文档的密码。并在破解过程中加入了中断以方便用户随时中断破解过程。
关键字穷举法、解密、 excel文档、 word文档、密码excel和word提供了多种方法限制访问用户文档以免未经授权者的查看和更改。但在信息化的今天用户需要记忆的密码太多一旦密码丢失用户将无法打开或访问该文档给用户造成很大的损失。能否借助计算机的高速运行解开密码呢通过尝试笔者认为在无法弄清excel和word加密算法的情况下利用穷举法尝试解密文档是解密唯一的选择。
1 . 实现原理
本程序选用vb6.0编写并充分利用了off ice组件中的对象库穷举尝试各种口令达到解密文档的目的。
⑴巧用整数的取整及取余产生密码字符串excel和word文档密码可以是字母、数字、空格以及符号的任意组合最长可达15个字符且区分大小写。
本程序的破解过程利用一个两层循环产生选定字符的排列组合尝试密码 其中外层循环控制密码的位数 内层循环生成n位密码的所有排列组合。产生尝试密码的方法是将一个n位字符串密码password作为一个“数值” 该“数值”每个位上的“数字”属于选定字符范围且该“数值”与一个整数x一一对应并满足以下条件 0≤x
≤arraylenn-1 arraylen是选定密码字符范围的总字符数如仅选定数字时arraylen=10仅选定数字和小写字母时 arraylen=10+26=36 对x整除、取余n-1次对每次的余数y做以下操作 password = password + chararray(y) 注 chararray是存放选定字符的一维数组 最后做以下操作 password = chararray(x mod arraylen) +password产生的password就是整数x对应的n位字符串。 WwW. .coM
⑵利用vb的错误处理功能尝试口令破解
当运行程序尝试一个密码时用该密码打开文档 若密码错误则会产生运行错误。为此必须在尝试口令前使用on error语句打开一个错误处理程序 由于本程序是尝试各种口令 当一个口令错误时直接尝试下一个口令即可 因此应使用 “on error resumenext”语句。
那么如何得知找到口令了呢 vb有一个内部错误对象err 它的number属性中的值是用来确定发生错误的原因。在尝试一个口令后检查err. number中的值以确定该口令是否正确。
⑶破解过程中的中断
利用穷举法解密对系统资源的占用是十分惊人的在解密的过程中cpu的利用率几乎是100%若不加入解密过程中的中断计算机系统会处于一种假死机状态。为此在破解过程
的内循环中加入了doevents函数。 doevents函数提供了一种取消任务的简便方法 它将控制切换到操作环境内核。只要此环境中的所有应用程序都有机会响应待处理事件应用程序就又恢复控制。使用该函数的优点是不会使应用程序放弃焦点且后台事件能够得到有效处理。
2. 具体实现过程
编程实现时需要机器安装有vb应用程序及microsoft off ice组件。
⑴新建vb工程并对其初始化
新建一个vb工程取名get_password将启动窗体命名为frmmain。首先选择“工程”菜单中的“引用” 在“引用”对话框中选择“microsoft excel 10.0 object l ibrary”和
“microsoft word10.0 object l ibrary” 注意如果安装的是off ice2000或off ice97应该选择excel对象库和word对象库的9.0版或8.0版 。其次在“工程”菜单中“部件”对话框中选择添加“microsoft windows common controls -2.5(sp2)”和
“microsoft common dialog control 6.0” 以便在窗体设计中使用微调控件和对话框控件。
⑵在frmmain窗体上添加控件
在frmmain窗体上按照下图的位置添加表1中的控件然后根据表1修改每个对象的属性。表1
序号 控件名称 控件属性及其属性值
1 frame name=frame1 caption=选择加密文件*.doc、 *.xls
2 frame name=frame2 caption=选定密码字符范围
3 frame name=frame3 caption=选择密码的长度
4 combobow name=combo1
5 commandbutton name=cmdbrowse caption=浏览
6 commandbutton name=cmdstartcrack=开始破解
7 commandbutton name=cmdquit caption=退出系统
8 checkbox name=chkdigital caption=数字(10)
9 checkbox name=chklowercase caption=小写字母(26)
10 checkbox name=chkuppercase caption=大写字母(26)
1 1 checkbox name=chkspace caption=空格(1)
12 checkbox name=chkbracket caption=括号(6)
13 checkbox name=chkothers caption=其他oem字符(26)
14 textbox name=txtpasswordstartlong text=2
15 textbox name=txtpasswordendlong text=2
16 textbox name=text1
buddycontrol=txtpasswordstartlong max=15 min=
18 updown name=updown2 buddyproperty=text wrap=true increment=1buddycontrol=txtpasswordendlong max=15 min=1
19 commondialog name=dialog dialogtitle=请选择加密的excel或word文档f i lter=excel (*.xls) word(*.doc) |*.xls;*.doc
20 label name=label 1 caption=破解进度
21 label name=label3 caption=从
22 label name=label5 caption=到
⑶为以上对象编写下列代码
为了便于理解程序中增加了适当的注释。option expl icitpr ivate sub cmdbrowse_cl ick()dialog. showopen 'show the dialogcombo1 .text = dialog.f i lename 'set the f i lename text box to the selectedfi lecombo1 . refreshend subpr ivate sub cmdquit_cl ick()endend subpr ivate sub cmdstartcrack_cl ick()static blnprocessing as booleandim wd as new word.appl ication, xls as new excel .appl icationdim openreturndim strpath, pass, strtemp, al l_char (100) as str ingdim j, k, password_start_long, password_end_long, arraylen as integerdim i , temp as longarraylen = 0 '数组初始化if chkdigital .value = 1 thenfor j = arraylen to arraylen + 9al l_char (j) = chr (asc("0") + j - arraylen)next jarraylen = arraylen + 10
end ifif chklowercase.value = 1 thenfor j = arraylen to arraylen + 25al l_char (j) = chr (asc("a") + j - arraylen)next jarraylen = arraylen + 26end ifif chkuppercase.value = 1 thenfor j = arraylen to arraylen + 25al l_char (j) = chr (asc("a") + j - arraylen)next jarraylen = arraylen + 26end ifif chkspace.value = 1 thenal l_char (arraylen) = " "arraylen = arraylen + 1end ifif chkbracket.value = 1 thenal l_char (arraylen) = " ("al l_char (arraylen+1) = ") "al l_char (arraylen+2) = " {"al l_char (arraylen+3) = "} "al l_char (arraylen+4) = " ["al l_char (arraylen+5) = "] "arraylen = arraylen + 6end ifif chkothers.value = 1 thenfor j = arraylen to arraylen + 6 '33 to 39al l_char (j) = chr (33 + j - arraylen)nextarraylen = arraylen + 7for j = arraylen to arraylen + 5 '42 to 47al l_char (j) = chr (42 + j - arraylen)next jarraylen = arraylen + 6
for j = arraylen to arraylen + 6 '58 to 64al l_char (j) = chr (58 + j - arraylen)next jarraylen = arraylen + 7al l_char (arraylen) = chr (92)arraylen = arraylen + 1for j = arraylen to arraylen + 2 '94 to 96al l_char (j) = chr (94 + j - arraylen)next jarraylen = arraylen + 3al l_char (arraylen) = chr (124)al l_char (arraylen+1) = chr (126)arraylen = arraylen + 2end ifif arraylen = 0 thenmsgbox "错误没有选择'密码使用的字符' ", , "请选择密码使用的字符范围. . . "exit subend ifif blnprocessing thenif msgbox("真的要中断解密过程吗 ", vbyesno, "用户中断任务") = vbyesthen blnprocessing = falseelsecmdstartcrack.caption = "中断破解"blnprocessing = truestrpath = combo1 .textif strpath = " " thenmsgbox "错误没有选择'需要解密的文件' ", , "请选择需要解密的文件. . . "exit subend ifstrpath = tr im(strpath)password_start_long = val (txtpasswordstartlong.text)password_end_long = val (txtpasswordendlong.text)if password_start_long > password_end_long thenpassword_start_long = val (txtpasswordendlong.text)password_end_long = val (txtpasswordstartlong.text)
end iflabel 1 .caption = "破解进度 "label 1 . refreshon error resume nextif ucase(r ight(strpath, 3) ) = "xls" thenfor k = password_start_long to password_end_long '破解excel开始for i = 0 to arraylen ^ k - 1pass = ""temp = ifor j = 1 to k - 1temp = temp \ arraylepass = al l_char (temp mod arraylen) + passnext jpass = pass + al l_char (i mod arraylen)set openreturn = xls.workbooks.open(f i lename:=strpath,password:=pass)text1 .text = pass '显示破解进度text1 . refreshif err. number <> 0 then '如果解密成功,打开文档,显示密码,退出过程err.clearelselabel 1 .caption = "文档密码 "text1 .text = passme. refreshxls.visible = truecmdstartcrack.mousepointer = 0cmdstartcrack.caption = "开始破解"blnprocessing = falseset xls = nothingexit subend ifdoeventsif not blnprocessing then exit fornext i
if not blnprocessing then exit fornext kxls.quitset xls = nothingelsefor k = password_start_long to password_end_long '破解word开始for i = 0 to arraylen ^ k - 1pass = ""temp = ifor j = 1 to k -temp = temp \ arraylenpass = al l_char (temp mod arraylen) + passnext jpass = pass + al l_char (i mod arraylen)openreturn = wd.documents.open(f i lename:=strpath,passworddocument:=pass)text1 .text = pass '显示破解进度text1 . refreshif err. number <> 0 then '如果解密成功,打开文档,显示密码,退出过程err.clearelse
'msgbox "word password"label 1 .caption = "文档密码 "text1 .text = passme. refreshwd.visible = truecmdstartcrack.mousepointer = 0cmdstartcrack.caption = "开始破解"blnprocessing = falseset wd = nothingexit subend ifdoeventsif not blnprocessing then exit for
next iif not blnprocessing then exit fornext kwd.quitset wd = nothingend ifcmdstartcrack.caption = "开始破解"if blnprocessing then msgbox "没有找到密码可能是密码位数不对! ", , "提示信息. . . "blnprocessing = falseend sub
3. 时间复杂度分析
一个算法的时间复杂度是指该算法的时间耗费是该算法所求解问题规模n的函数。根据前面讲的实现原理我们知道破解算法的时间耗费主要集中在尝试打开off ice文档上因此 当我们假设破解一个n位字符串密码且选定密码字符范围的总字符数为arraylen时该算法的时间复杂度是o(arraylen^n) 。即 当n确定后该算法的时间复杂度是n次方阶当arraylen确定后该算法的时间复杂度是指数阶。都是高数量级的时间复杂度。
4.说明
穷举法解密对系统资源的占用是十分惊人的在解密的过程中最好不要运行其他应用程序。如果安装有瑞星等杀毒软件应将杀毒软件的“off ice安全助手”去掉以便加快程序的运行速度。
该程序在winxp+off icexp+vb6.0环境下测试通过笔者随便测试了一个5位数字密码在p4机器上 8分钟左右即可解开口令。
参考文献
[1 ]王建华译. visual basic 6开发人员指南. 北京机械工业出版社 1999-全文完-
10gbiz怎么样?10gbiz在本站也多次分享过,是一家成立于2020的国人主机商家,主要销售VPS和独立服务器,机房目前有中国香港和美国洛杉矶、硅谷等地,线路都非常不错,香港为三网直连,电信走CN2,洛杉矶线路为三网回程CN2 GIA,10gbiz商家七月连续推出各种优惠活动,除了延续之前的VPS产品4折优惠,目前增加了美国硅谷独立服务器首月半价的活动,有需要的朋友可以看看。10gbiz优惠码...
HostKvm商家我们也不用多介绍,这个服务商来自国内某商家,旗下也有多个品牌的,每次看到推送信息都是几个服务商品牌一起推送的。当然商家还是比较稳定的,商家品牌比较多,这也是国内商家一贯的做法,这样广撒网。这次看到黑五优惠活动发布了,针对其主打的香港云服务器提供终身6折的优惠,其余机房服务器依然是8折,另还有充值50美元赠送5美元的优惠活动,有需要的可以看看。HostKvm是一个创建于2013年的...
2021年各大云服务商竞争尤为激烈,因为云服务商家的竞争我们可以选择更加便宜的VPS或云服务器,这样成本更低,选择空间更大。但是,如果我们是建站用途或者是稳定项目的,不要太过于追求便宜VPS或便宜云服务器,更需要追求稳定和服务。不同的商家有不同的特点,而且任何商家和线路不可能一直稳定,我们需要做的就是定期观察和数据定期备份。下面,请跟云服务器网(yuntue.com)小编来看一下2021年国内/国...