自己动手破解rar密码-ruby脚本实现

破解密码,上策是社工的方式,下策则是暴力破解了。这里使用暴力破解,字典文件放在txt中;通过调用winrar的相关参数进行操作。经过测试,当字典中密码为100个时,破解耗时8秒(个人配置:i5-3210 2.5GHz, 4GB).不足之处是rar的对话框会一直闪烁,cpu消耗到50%,等高手指导

##################################################################
#    description:    rar暴力破解程序
#    language:        ruby实现
#    author:        ChrisZZ(zchrissirhcz@gmail.com)
##################################################################
def decode(filedir,rarname,password)
    Dir.chdir(filedir)            #Nice ruby!
    fullname=rarname+".rar"
    command="winrar e -p"+password+" -inul "+fullname+" "+rarname+"\\"
    system command
end

File.open("D:\\0.txt") do |file|   #打开的是字典文件,请自行更改
    file.each_line do |line|
        password=line.chomp
        filedir="D:\\workspace\\decode"   #.rar文件所在的路径
        rarname="yellow"   #.rar文件名的前面部分,不含.rar
        res=decode(filedir,rarname,password)
        if res==true
            puts "破解成功!密码是"+password
            break
        end
    end
    file.close()
end

 

winrar参数请看:http://www.cnblogs.com/pclook/archive/2009/05/06/1450539.html

posted @ 2013-07-03 00:17  ChrisZZ  阅读(888)  评论(0编辑  收藏  举报