Advertisement
Guest User

brute

a guest
Nov 28th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.78 KB | None | 0 0
  1. --[[
  2.     Brutus
  3.     @version 1.0, 2014-11-07
  4.     @author Mr.L0lZ
  5.    
  6.     Flags:
  7.         -t : Plaintext
  8.         -h : Hash
  9.         -f : File
  10.         -r : Rednet mode
  11.        
  12.    
  13.     Example usage:
  14.         brute -h 5 abcdefghijklmnopqrstuvwxyz -r 4
  15.         brute -h 5 abcdefghijklmnopqrstuvwxyz -f password.data
  16. --]]
  17.  
  18.  
  19.  
  20. local id, file
  21. local int = 0
  22.  
  23. local flags = {
  24.     ["-t"] = false;
  25.     ["-h"] = false;
  26.     ["-r"] = false;
  27.     ["-f"] = false;
  28. }
  29.  
  30. local valid = {
  31.     ["-t"] = true;
  32.     ["-h"] = true;
  33. }
  34.  
  35. local args = {...}
  36. if #args < 3 then
  37.     print( "Usage: <flag> <length> <characters> <...>" )
  38.     error()
  39. end
  40.  
  41. if args[1] == "-h" then
  42.     local path = fs.getDir( shell.getRunningProgram() )
  43.     assert( fs.exists( path .. "/hash" ), "Couldn't find the API: 'hash'" )
  44.     os.loadAPI( path .. "/hash" )
  45.     flags["-h"] = true
  46.    
  47. elseif args[1] == "-t" then
  48.     flags["-t"] = true
  49. end
  50.  
  51.  
  52. if args[4] == "-r" then
  53.     flags["-r"] = true
  54.     id = type( tonumber( args[5] ) ) == "number" and tonumber( args[5] ) or error( "invalid id, expected number, got " .. type( args[5] ), 0 )
  55.  
  56. elseif args[4] == "-f" then
  57.     flags["-f"] = true
  58.     file = type( args[5] ) == "string" and fs.exists( args[5] ) and args[5] or error( "Invalid file", 0 )
  59. end
  60.  
  61.  
  62. if not valid[args[1]] then
  63.     error( "Invalid flag: " .. args[1], 0 )
  64. end
  65.  
  66.  
  67. local path, length, _chars = args[1], tonumber( args[2] ), args[3] or "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz 0123456789"
  68.  
  69. --# Convert the string into a table
  70. local chars = {}
  71. for i = 1, #_chars do
  72.     chars[i] = _chars:sub( i, i )
  73. end
  74.  
  75. --local chars_advanced = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ,./;'[]-=<>?:{}\\\"_+^~@å82¥A3$åA2?0š¥AC&!*"
  76. --local chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz "
  77. function cyclechar( current )
  78.    
  79.     --# Initialize the table
  80.     local tChars={}
  81.     for i = 1, #current do
  82.         tChars[#tChars+1] = current:sub( i, i )
  83.     end
  84.    
  85.     local at=#tChars+1
  86.     local returned=nil
  87.     local looping=1
  88.    
  89.     --# Actual bruteforce loop
  90.     while looping==1 do
  91.         at=at-1
  92.         if at==0 then
  93.             returned=chars[1]
  94.             int = 0
  95.             break
  96.         end
  97.         for k, v in pairs( chars ) do
  98.             if tChars[at]==v and k~=#chars then
  99.                 tChars[at]=chars[k+1]
  100.                 looping=0
  101.                 break
  102.             elseif tChars[at]==v and k==#chars then
  103.                 tChars[at]=chars[1]
  104.             end
  105.         end
  106.     end
  107.    
  108.     --# Return the table as a string
  109.     local returned=returned or ''
  110.     for k,v in pairs(tChars) do
  111.         returned=returned..v
  112.     end
  113.     return returned
  114. end
  115.  
  116.  
  117. local function yield()
  118.     os.queueEvent( "sleep" )
  119.     coroutine.yield( "sleep" )
  120. end
  121.  
  122.  
  123.  
  124. --# Initialize the pass
  125. local pass = ""
  126. for i = 1, length do
  127.     pass = pass .. chars[1]
  128. end
  129.  
  130.  
  131. local counter = 0
  132.  
  133.  
  134.  
  135. local function w( x, y, text, cl )
  136.     term.setCursorPos( x, y )
  137.     if cl then
  138.         write( string.rep( " ", #text + 1 ) )
  139.         term.setCursorPos( x, y )
  140.     end
  141.     write( text )
  142. end
  143.  
  144.  
  145. local function test( _hash )
  146.     if flags["-r"] then
  147.         rednet.send( id, _hash and  hash.sha256( pass ) or pass )
  148.         local _id, message
  149.         repeat
  150.             _id, message = rednet.receive()
  151.         until _id == id
  152.         if messsage == "success" then
  153.             return true
  154.         end
  155.         return false
  156.     else
  157.         error( "invalid usage of plaintext mode: no rednet flag", 0 )
  158.     end
  159. end
  160.  
  161.  
  162. if flags["-f"] then
  163.     local f = fs.open( file, "r" )
  164.     password = f.readAll()
  165.     f.close()
  166. end
  167.  
  168. if flags["-r"] then
  169.     local modem
  170.     for _, name in ipairs( peripheral.getNames() ) do
  171.         if peripheral.getType( name ) == "modem" then
  172.             modem = peripheral.wrap( name )
  173.             if modem.isWireless() then
  174.                 rednet.open( name )
  175.                 break
  176.             else
  177.                 modem = nil
  178.             end
  179.         end
  180.     end
  181.     if modem == nil then
  182.         error( "No modem attached!", 0 )
  183.     end
  184. end
  185.  
  186.  
  187. if not flags["-r"] and not flags["-f"] then
  188.     error( "One of these flags needed:\n -f: file\n -r: rednet", 0)
  189. end
  190.  
  191.  
  192.  
  193. term.clear()
  194. while true do
  195.     local function redraw( done )
  196.         local a, b     = #args[3], #pass
  197.         local progress = (int/(a^b))*100
  198.         term.setCursorPos(1,1)
  199.         w( 1, 1, "Brutus - The Password Cracker 1.0" )
  200.         w( 1, 3, "Password: " .. pass )
  201.         w( 1, 5, "Tried: " .. int ..  "/" .. a^b .. "  ")
  202.         w( 1, 6, "Progress: " .. math.ceil( progress ) .. "%  ")
  203.         if done then
  204.             w( 1, 8, "Password cracked!" )
  205.             term.setTextColor( colors.lime  )
  206.             w( 1 + string.len( "Password: " ), 3, pass )
  207.             term.setTextColor( colors.white )
  208.         end
  209.     end
  210.     redraw()
  211.     if flags["-h"] then
  212.         if not flags["-r"] then
  213.             if hash.sha256( pass ) == password then
  214.                 redraw( true )
  215.                 os.pullEvent( "key" )
  216.                 break
  217.             end
  218.         else
  219.             test( true )
  220.         end
  221.    
  222.     elseif flags["-t"] then
  223.         test( false )
  224.     end
  225.     pass = cyclechar( pass )
  226.     int = int + 1
  227.     yield()
  228. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement