Excel spreadsheet password cracking using VBA

前端 未结 4 815
Happy的楠姐
Happy的楠姐 2021-02-10 01:45

I tried writing a vba password cracker code similar to the code I used to crack Excel sheet\'s password But I am not sure if I am doing correctly or not - when i tried this code

4条回答
  •  迷失自我
    2021-02-10 02:18

    Maybe of some help?

    Option Explicit
    
    Const PWDMaxLength = 9
    Const MaxTimeInSeconds = 600    ' 10 Minutes
    Const PWDWindowName = "Password"
    Const TargetFile = "D:\Dropbox\Excel stuff\crack\test.xls"
    Const LowerCase = "abcdefghijklmnopqrstuvwxyzæøå"
    Const UpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ"
    Const SpesChars = "+-*@#%=?!_;./"
    Const Digits = "0123456789"
    Dim CrackAttempt As Long
    Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    
    
    Sub BFOpen()
    On Error Resume Next
    Application.DisplayAlerts = False
    Workbooks.Open Filename:=TargetFile
    Application.DisplayAlerts = True
    On Error GoTo 0
    End Sub
    
    
    Sub BFCrack()
    'On Error Resume Next
    Dim lSta, lCur As Long, test, str, PWD As String
    lSta = GetTickCount()
    PWD = LowerCase & UpperCase & SpesChars & Digits
    CrackAttempt = 1
    test = InputBox("Insert test string for brutforce if wanted" & vbCrLf & "not more than 5 characters...", "input")
    SendKeys "%{TAB}", 100
    Do While str <> test Or FindWindow(vbNullString, PWDWindowName) And (Len(str) < PWDMaxLength <> 0 And (lCur / 1000) < MaxTimeInSeconds)
      lCur = (GetTickCount() - lSta)
      If lCur Mod 250 = 0 Then Application.StatusBar = str & " " & CrackAttempt & " " & lCur
      str = GBFS(PWD, CrackAttempt)
      If test = "" Then SendKeys str & "{ENTER}", 1000
      CrackAttempt = CrackAttempt + 1
    Loop
    Application.StatusBar = False
    If str <> "" Then MsgBox str & " found in " & CStr((GetTickCount() - lSta) / 1000) & " seconds after " & CrackAttempt & " attempts", vbOKOnly + vbInformation, "Result"
    On Error GoTo 0
    End Sub
    
    
    Function GBFS(ByVal inp As String, ByVal att As Long) As String
      Dim Base, cal As Integer, rmi, res As Long
      Base = Len(inp)
      If Base < 2 Then Exit Function
      rmi = att
      Do While rmi > 0
        res = Int(rmi / Base)
        cal = rmi - (res * Base)
        If cal = 0 Then
          cal = Base
          res = res - 1
        End If
        GBFS = Mid(inp, cal, 1) & GBFS
        rmi = res
      Loop
    End Function
    

提交回复
热议问题