Akyra

Excel Cracking

Jun 1st, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. Sub Macro1()
  2. '
  3. ' Breaks worksheet and workbook structure passwords. Jason S
  4.  
  5. ' probably originator of base code algorithm modified for coverage
  6.  
  7. ' of workbook structure / windows passwords and for multiple passwords
  8.  
  9. ' Jason S http://jsbi.blogspot.com
  10.  
  11. ' Reveals hashed passwords NOT original passwords
  12.  
  13. Const DBLSPACE As String = vbNewLine & vbNewLine
  14.  
  15. Const AUTHORS As String = DBLSPACE & vbNewLine & "Adapted from Bob McCormick base code by" & "Jason S http://jsbi.blogspot.com"
  16.  
  17. Const HEADER As String = "AllInternalPasswords User Message"
  18.  
  19. Const VERSION As String = DBLSPACE & "Version 1.0 8 Sep 2008"
  20.  
  21. Const REPBACK As String = DBLSPACE & "Please report failure to [email protected] "
  22.  
  23. Const ALLCLEAR As String = DBLSPACE & "The workbook should be cleared"
  24.  
  25. Const MSGNOPWORDS1 As String = "There were no passwords on " & AUTHORS & VERSION
  26.  
  27. Const MSGNOPWORDS2 As String = "There was no protection to " & "workbook structure or windows." & DBLSPACE
  28.  
  29.  
  30. Const MSGTAKETIME As String = "After pressing OK button this " & "will take some time." & DBLSPACE & "Amount of time " & "depends on how many different passwords, the "
  31.  
  32.  
  33.  
  34. Const MSGPWORDFOUND1 As String = "You had a Worksheet " & "Structure or Windows Password set." & DBLSPACE & "The password found was: " & DBLSPACE & "$$" & DBLSPACE & "Note it down for potential future use in other workbooks by " & "the same person who set this password." & DBLSPACE & "Now to check and clear other passwords." & AUTHORS & VERSION
  35.  
  36. Const MSGPWORDFOUND2 As String = "You had a Worksheet " & "password set." & DBLSPACE & "The password found was: " & DBLSPACE & "$$" & DBLSPACE & "Note it down for potential " & "future use in other workbooks by same person who " & "set this password." & DBLSPACE & "Now to check and clear " & "other passwords." & AUTHORS & VERSION
  37.  
  38. Const MSGONLYONE As String = "Only structure / windows " & "protected with the password that was just found." & ALLCLEAR & AUTHORS & VERSION & REPBACK
  39.  
  40. Dim w1 As Worksheet, w2 As Worksheet
  41.  
  42. Dim i As Integer, j As Integer, k As Integer, l As Integer
  43.  
  44. Dim m As Integer, n As Integer, i1 As Integer, i2 As Integer
  45.  
  46. Dim i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer
  47.  
  48. Dim PWord1 As String
  49.  
  50. Dim ShTag As Boolean, WinTag As Boolean
  51.  
  52. Application.ScreenUpdating = False
  53.  
  54. With ActiveWorkbook
  55.  
  56. WinTag = .ProtectStructure Or .ProtectWindows
  57.  
  58. End With
  59.  
  60. ShTag = False
  61.  
  62. For Each w1 In Worksheets
  63.  
  64. ShTag = ShTag Or w1.ProtectContents
  65.  
  66. Next w1
  67.  
  68. If Not ShTag And Not WinTag Then
  69.  
  70. MsgBox MSGNOPWORDS1, vbInformation, HEADER
  71.  
  72. Exit Sub
  73.  
  74. End If
  75.  
  76. MsgBox MSGTAKETIME, vbInformation, HEADER
  77.  
  78. If Not WinTag Then
  79.  
  80. MsgBox MSGNOPWORDS2, vbInformation, HEADER
  81.  
  82. Else
  83.  
  84. On Error Resume Next
  85.  
  86. Do 'dummy do loop
  87.  
  88. For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
  89.  
  90. For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
  91.  
  92. For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
  93.  
  94. For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
  95.  
  96. With ActiveWorkbook
  97.  
  98. .Unprotect Chr(i) & Chr(j) & Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
  99.  
  100. If .ProtectStructure = False And .ProtectWindows = False Then
  101.  
  102. PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
  103.  
  104. MsgBox Application.Substitute(MSGPWORDFOUND1, "$$", PWord1), vbInformation, HEADER
  105.  
  106. Exit Do 'Bypass all for...nexts
  107.  
  108. End If
  109.  
  110. End With
  111.  
  112. Next: Next: Next: Next: Next: Next
  113.  
  114. Next: Next: Next: Next: Next: Next
  115.  
  116. Loop Until True
  117.  
  118. On Error GoTo 0
  119.  
  120. End If
  121.  
  122. If WinTag And Not ShTag Then
  123.  
  124. MsgBox MSGONLYONE, vbInformation, HEADER
  125.  
  126. Exit Sub
  127.  
  128. End If
  129.  
  130. On Error Resume Next
  131.  
  132. For Each w1 In Worksheets
  133.  
  134. 'Attempt clearance with PWord1
  135.  
  136. w1.Unprotect PWord1
  137.  
  138. Next w1
  139.  
  140. On Error GoTo 0
  141.  
  142. ShTag = False
  143.  
  144. For Each w1 In Worksheets
  145.  
  146. 'Checks for all clear ShTag triggered to 1 if not.
  147.  
  148. ShTag = ShTag Or w1.ProtectContents
  149.  
  150. Next w1
  151.  
  152. If ShTag Then
  153.  
  154. For Each w1 In Worksheets
  155.  
  156. With w1
  157.  
  158. If .ProtectContents Then
  159.  
  160. On Error Resume Next
  161.  
  162. Do 'Dummy do loop
  163.  
  164. For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
  165.  
  166. For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
  167.  
  168. For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
  169.  
  170. For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
  171.  
  172. .Unprotect Chr(i) & Chr(j) & Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
  173.  
  174. If Not .ProtectContents Then
  175.  
  176. PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
  177.  
  178. MsgBox Application.Substitute(MSGPWORDFOUND2, "$$", PWord1), vbInformation, HEADER
  179.  
  180. 'leverage finding Pword by trying on other sheets
  181.  
  182. For Each w2 In Worksheets
  183.  
  184. w2.Unprotect PWord1
  185.  
  186. Next w2
  187.  
  188. Exit Do 'Bypass all for...nexts
  189.  
  190. End If
  191.  
  192. Next: Next: Next: Next: Next: Next
  193.  
  194. Next: Next: Next: Next: Next: Next
  195.  
  196. Loop Until True
  197.  
  198. On Error GoTo 0
  199.  
  200. End If
  201.  
  202. End With
  203.  
  204. Next w1
  205.  
  206. End If
  207.  
  208. MsgBox ALLCLEAR & AUTHORS & VERSION & REPBACK, vbInformation, HEADER
  209. '
  210. End Sub
Add Comment
Please, Sign In to add comment