Advertisement
Guest User

Bitcoin Somewhat-Bruteforce Recovery

a guest
Apr 10th, 2013
2,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Bitcoin encrypted wallet somewhat-brute-force-recovery.
  2. # Also works for litecoins probably (untested).
  3. # By Rahazan
  4. #
  5. # Originally created for veryveryinteresting (VVI)
  6. # https://bitcointalk.org/index.php?topic=85495.120
  7. # My first ever powershell script, by the way.
  8. # Pardon any convention I broke in this language (for I did not study any conventions of this language).
  9.  
  10. ################################################################
  11. # Recovered your coin     using this? Consider a donation to   #
  12. # the AI student who scripted this :)                          #
  13. # Donations BTC:    1FkXY2WVG9X4WqVuKdrSrX64ZTj9HgG34U         #
  14. # Donations LTC:    LKdLS4seKpE2MNmt4t618oZV7v7tNkD6zL         #
  15. ################################################################
  16.  
  17.  
  18. ######################################################
  19. # How does it work?
  20. ######################################################
  21.  
  22. # This script creates every possible combination in a depth-first order.
  23. # After this it tries all of these. On my crappy laptop it achieved ~ 5 attempts per second.
  24.  
  25. ######################################################
  26. # How do I use this?
  27. ######################################################
  28.  
  29. # - Edit the values in the next block of this script to your likings, make sure you set your RPC password & username.
  30. # - Run the daemon service found in Bitcoin\daemon  (bitcoind.exe)
  31. # - Run this script (save as SOMENAME.ps1 and right click -> run with PowerShell.
  32. # (To run it you might have to change some settings regarding allowing PowerShell scripts to run.. Google this.)
  33. # (Press CTRL+C to cancel if you wish to stop it.)
  34. # - Grab a cup of coffee as it tries a gazillion combinations.
  35. # - Get your coin back.
  36. # - Maybe donate a portion? ;)
  37. # - DELETE THIS SCRIPT (Shred it!). It holds way too valuable information about your password!
  38.  
  39.  
  40. ######################################################
  41. #Values you will probably want to set!
  42. #Please note that the more free you make these variables, computation time will increase by A LOT.
  43. ######################################################
  44.  
  45. # Min/Max length of your password (included! so min:1 max: 3 would allow password length 1 but also length 3)
  46. # So if you know the length, these should both be the same number.
  47. [int] $global:minLength = 10
  48. [int] $global:maxLength = 16
  49.  
  50. #Word list
  51. $wordsList = @("abcd","efgh")
  52. [int] $numWords = 2 #Amount of times one of these word blocks can exist in your pass
  53.  
  54. #Symbol list
  55. $symbolList = @("&")
  56. [int] $numSymbols = 1 #Amount of times one of these symbol blocks can exist in your pass
  57.  
  58. #Number list
  59. $numberList = @("0","1","2","3","4","5","6","7","8","9") #Possible numbers, do not have to be single numbers. For instance it could be just "22" if you know you have that in your pass somewhere with numNumbers 1
  60. [int] $numNumbers = 2 #Amount of times one of these number blocks can exist in your pass
  61.  
  62. #Option to print when adding a possibility to the list of possibilities.
  63. #Consider making this false, it might make it somewhat faster (especially for very long passwords with small "blocks" in the lists.
  64. $verbose = $TRUE
  65.  
  66.  
  67. # Please put the correct RPC username/password below
  68. $h = new-object Net.WebClient
  69. $h.Credentials = new-object Net.NetworkCredential("RPCUSERNAME","RPCPASSWORD")
  70. $h.Encoding = [Text.Encoding]::Default
  71. # Above "Default" works for original encryption from the command line
  72. # Change to "UTF8" when the GUI was used to encrypt (Was not necessary when tested -Rahazan)
  73.  
  74. [string[]]  $global:allPossibilities = @() #Empty array, you can manually add possibilities if you want (that you think will not be generated by the algorithm).
  75.  
  76. ######################################################
  77. # Time to create an array of all the possibilities! No need to change anything past this point.
  78. ######################################################
  79.  
  80.  
  81.  
  82. # Algorithm is next, it recursively builds the array of all possibilities.
  83.  
  84. Function generateAllPossibilities([string]$wordSoFar, $wordsList, $symbolList, $numberList, [int]$numWords, [int]$numSymbols, [int]$numNumbers)
  85. {
  86.     #Base case: Length of the created pass is too big, no need to further explore this node, go up one step in the tree.
  87.     if ($wordSoFar.length -gt $global:maxLength) {
  88.         #Too long! Done with this branch!
  89.         return
  90.     }
  91.    
  92.    #Add the word to the possibilities if the right length
  93.     if ($wordSoFar.length -gt $global:minLength) {
  94.         $global:allPossibilities += $wordSoFar
  95.     }
  96.    
  97.     if ($numWords -gt 0) {#Have not added max amount of words to this possibility yet.
  98.         for ($i=0;$i -lt $wordsList.length; $i++) {
  99.           generateAllPossibilities ($wordSoFar+$wordsList[$i]) $wordsList $symbolList $numberList ($numWords-1) $numSymbols $numNumbers
  100.         }
  101.     }
  102.    
  103.     if ($numSymbols -gt 0) {#Have not added max amount of symbols to this branch yet.
  104.         for ($i=0;$i -lt $symbolList.length; $i++) {
  105.           generateAllPossibilities ($wordSoFar + $symbolList[$i]) $wordsList $symbolList $numberList ($numSymbols-1) $numNumbers
  106.         }
  107.     }
  108.    
  109.     if ($numNumbers -gt 0) {#Have not added max amount of nums to this branch yet.
  110.         for ($i=0;$i -lt $numberList.length; $i++) {
  111.           generateAllPossibilities ($wordSoFar + $numberList[$i] ) $wordsList $symbolList $numberList $numWords $numSymbols ($numNumbers-1)
  112.         }
  113.     }
  114.  
  115. }
  116.  
  117. [string]$wordsofar = ""
  118.  
  119. Write-Host "Generating all possibilities, may take a long time depending on the amount + size of the \"blocks\" you have given !"
  120.  
  121. #Calling the algorithm (function) above to fill the list!
  122. generateAllPossibilities $wordSoFar $wordsList $symbolList $numberList $numWords $numSymbols $numNumbers
  123.  
  124. Write-Host "DONE Generating!"
  125. Write-Host "Note: There seems to be a slight bug, about 1 in 100 of these strings break the rules (for instance 2 symbols where numSymbols was 1).. don't know why."
  126. Write-Host "Will be printing all possibilities now:"
  127.  
  128.  
  129. Write-Host $global:allPossibilities
  130.  
  131. Write-Host "===================="
  132. Write-Host "Amount to be tested:"  $global:allPossibilities.length
  133. Write-Host "Starting bruteforce!"
  134. Write-Host "===================="
  135. ######################################################
  136. # Time to start trying them one by one!
  137. ######################################################
  138.  
  139. $i = 0
  140.  
  141. # Somewhat altered code by 2112 -> from https://bitcointalk.org/index.php?topic=85495.msg1756901#msg1756901
  142. $global:allPossibilities | foreach {
  143.     $i++
  144.     try {
  145.         $p = $_
  146.        
  147.         if ($i%4 -eq 0) {
  148.             Write-Host "   '$p' " $i "/" $global:allPossibilities.length
  149.         }
  150.         else {
  151.          Write-Host "   '$p'" -nonewline
  152.         }
  153.        
  154.         $r = $h.UploadString('http://localhost:8332/','{"method":"walletpassphrase","params":["'+$p+'",1]}')
  155.         # Write-Output $r
  156.         Write-Output "Correct password found!"
  157.         Write-Output "'$p'"
  158.         break
  159.     }
  160.     catch [Net.WebException] {
  161.         $e = $_
  162.         switch -wildcard ($e.Exception.Message) {
  163.              "*(401) Unauthorized*" {
  164.                   Write-Output "Fix the user/pass!"
  165.                   Exit-PSSession
  166.              }
  167.              "*(500) Internal Server Error*" {
  168.                   continue
  169.              }
  170.              default {
  171.                   $e | Format-List -Force
  172.                   Exit-PSSession
  173.             }
  174.         }
  175.     }
  176. }
  177. #
  178. # Exiting without success!
  179. #
  180. Write-Output "===================="
  181.  
  182. Write-Output "Exiting!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement