Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Brutus
- @version 1.0, 2014-11-07
- @author Mr.L0lZ
- Flags:
- -t : Plaintext
- -h : Hash
- -f : File
- -r : Rednet mode
- Example usage:
- brute -h 5 abcdefghijklmnopqrstuvwxyz -r 4
- brute -h 5 abcdefghijklmnopqrstuvwxyz -f password.data
- --]]
- local id, file
- local int = 0
- local flags = {
- ["-t"] = false;
- ["-h"] = false;
- ["-r"] = false;
- ["-f"] = false;
- }
- local valid = {
- ["-t"] = true;
- ["-h"] = true;
- }
- local args = {...}
- if #args < 3 then
- print( "Usage: <flag> <length> <characters> <...>" )
- error()
- end
- if args[1] == "-h" then
- local path = fs.getDir( shell.getRunningProgram() )
- assert( fs.exists( path .. "/hash" ), "Couldn't find the API: 'hash'" )
- os.loadAPI( path .. "/hash" )
- flags["-h"] = true
- elseif args[1] == "-t" then
- flags["-t"] = true
- end
- if args[4] == "-r" then
- flags["-r"] = true
- id = type( tonumber( args[5] ) ) == "number" and tonumber( args[5] ) or error( "invalid id, expected number, got " .. type( args[5] ), 0 )
- elseif args[4] == "-f" then
- flags["-f"] = true
- file = type( args[5] ) == "string" and fs.exists( args[5] ) and args[5] or error( "Invalid file", 0 )
- end
- if not valid[args[1]] then
- error( "Invalid flag: " .. args[1], 0 )
- end
- local path, length, _chars = args[1], tonumber( args[2] ), args[3] or "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz 0123456789"
- --# Convert the string into a table
- local chars = {}
- for i = 1, #_chars do
- chars[i] = _chars:sub( i, i )
- end
- --local chars_advanced = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz ,./;'[]-=<>?:{}\\\"_+^~@å82¥A3$åA2?0š¥AC&!*"
- --local chars = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz "
- function cyclechar( current )
- --# Initialize the table
- local tChars={}
- for i = 1, #current do
- tChars[#tChars+1] = current:sub( i, i )
- end
- local at=#tChars+1
- local returned=nil
- local looping=1
- --# Actual bruteforce loop
- while looping==1 do
- at=at-1
- if at==0 then
- returned=chars[1]
- int = 0
- break
- end
- for k, v in pairs( chars ) do
- if tChars[at]==v and k~=#chars then
- tChars[at]=chars[k+1]
- looping=0
- break
- elseif tChars[at]==v and k==#chars then
- tChars[at]=chars[1]
- end
- end
- end
- --# Return the table as a string
- local returned=returned or ''
- for k,v in pairs(tChars) do
- returned=returned..v
- end
- return returned
- end
- local function yield()
- os.queueEvent( "sleep" )
- coroutine.yield( "sleep" )
- end
- --# Initialize the pass
- local pass = ""
- for i = 1, length do
- pass = pass .. chars[1]
- end
- local counter = 0
- local function w( x, y, text, cl )
- term.setCursorPos( x, y )
- if cl then
- write( string.rep( " ", #text + 1 ) )
- term.setCursorPos( x, y )
- end
- write( text )
- end
- local function test( _hash )
- if flags["-r"] then
- rednet.send( id, _hash and hash.sha256( pass ) or pass )
- local _id, message
- repeat
- _id, message = rednet.receive()
- until _id == id
- if messsage == "success" then
- return true
- end
- return false
- else
- error( "invalid usage of plaintext mode: no rednet flag", 0 )
- end
- end
- if flags["-f"] then
- local f = fs.open( file, "r" )
- password = f.readAll()
- f.close()
- end
- if flags["-r"] then
- local modem
- for _, name in ipairs( peripheral.getNames() ) do
- if peripheral.getType( name ) == "modem" then
- modem = peripheral.wrap( name )
- if modem.isWireless() then
- rednet.open( name )
- break
- else
- modem = nil
- end
- end
- end
- if modem == nil then
- error( "No modem attached!", 0 )
- end
- end
- if not flags["-r"] and not flags["-f"] then
- error( "One of these flags needed:\n -f: file\n -r: rednet", 0)
- end
- term.clear()
- while true do
- local function redraw( done )
- local a, b = #args[3], #pass
- local progress = (int/(a^b))*100
- term.setCursorPos(1,1)
- w( 1, 1, "Brutus - The Password Cracker 1.0" )
- w( 1, 3, "Password: " .. pass )
- w( 1, 5, "Tried: " .. int .. "/" .. a^b .. " ")
- w( 1, 6, "Progress: " .. math.ceil( progress ) .. "% ")
- if done then
- w( 1, 8, "Password cracked!" )
- term.setTextColor( colors.lime )
- w( 1 + string.len( "Password: " ), 3, pass )
- term.setTextColor( colors.white )
- end
- end
- redraw()
- if flags["-h"] then
- if not flags["-r"] then
- if hash.sha256( pass ) == password then
- redraw( true )
- os.pullEvent( "key" )
- break
- end
- else
- test( true )
- end
- elseif flags["-t"] then
- test( false )
- end
- pass = cyclechar( pass )
- int = int + 1
- yield()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement