Class: ShellStrike

Inherits:
Object
  • Object
show all
Defined in:
lib/shell_strike.rb,
lib/shell_strike/version.rb,
lib/shell_strike/exceptions.rb

Defined Under Namespace

Classes: Host, HostsNotDefined, PasswordsNotDefined, Result, UsernamesNotDefined

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hosts, usernames, passwords, global_actions = []) ⇒ ShellStrike

Initialises a new ShellStrike instance

Raises:


16
17
18
19
20
21
22
23
24
25
# File 'lib/shell_strike.rb', line 16

def initialize(hosts, usernames, passwords, global_actions = [])
  raise HostsNotDefined if hosts.nil? || hosts.empty?
  raise UsernamesNotDefined if usernames.nil? || usernames.empty?
  raise PasswordsNotDefined if passwords.nil? || passwords.empty?

  @hosts = hosts
  @usernames = usernames
  @passwords = passwords
  @global_actions = global_actions
end

Instance Attribute Details

#global_actionsObject (readonly)

Returns the value of attribute global_actions


9
10
11
# File 'lib/shell_strike.rb', line 9

def global_actions
  @global_actions
end

#hostsObject (readonly)

Returns the value of attribute hosts


9
10
11
# File 'lib/shell_strike.rb', line 9

def hosts
  @hosts
end

#passwordsObject (readonly)

Returns the value of attribute passwords


9
10
11
# File 'lib/shell_strike.rb', line 9

def passwords
  @passwords
end

#usernamesObject (readonly)

Returns the value of attribute usernames


9
10
11
# File 'lib/shell_strike.rb', line 9

def usernames
  @usernames
end

Instance Method Details

#failed_hostsObject

An array of hosts for which valid credentials were not able to be identified.


65
66
67
# File 'lib/shell_strike.rb', line 65

def failed_hosts
  @failed_hosts ||= []
end

#identified_credentialsObject


51
52
53
# File 'lib/shell_strike.rb', line 51

def identified_credentials
  @identified_credentials ||= {}
end

#perform_attackObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/shell_strike.rb', line 27

def perform_attack
  combinations = @usernames.product(@passwords)

  @hosts.each do |host|
    host_failure_count = 0
    
    combinations.each do |username, password|
      authentication = host.test_credentials(username, password)

      if authentication.valid?
        identified_credentials[host.to_uri] = [username, password]
      elsif authentication.exception.nil?
        host_failure_count += 1
      else
        unreachable_hosts[host.to_uri] = authentication.message
        break
      end
    end

    failed_hosts << host if host_failure_count == combinations.length

  end
end

#unreachable_hostsObject

A hash of hosts which were unreachable.

Examples:

#<ShellStrike::Host:*> => 'Unable to connect to *. No route to host'

59
60
61
# File 'lib/shell_strike.rb', line 59

def unreachable_hosts
  @unreachable_hosts ||= {}
end