Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/core/auxiliary/web.rb
Views: 11784
# -*- coding: binary -*-12module Msf3###4#5# This module provides methods for brute forcing authentication6#7###89module Auxiliary::Web10module Analysis11end1213include Auxiliary::Report1415attr_reader :target16attr_reader :http17attr_reader :parent18attr_reader :page1920def initialize(info = {})21super22end2324# String id to push to the #checklist25def checked(id)26parent.checklist << "#{shortname}#{id}".hash27end2829# String id to check against the #checklist30def checked?(id)31parent.checklist.include? "#{shortname}#{id}".hash32end3334#35# Called directly before 'run'36#37def setup(opts = {})38@parent = opts[:parent]39@target = opts[:target]40@page = opts[:page]41@http = opts[:http]42end4344# Should be overridden to return the exploits to use for this45# vulnerability type as an Array of Strings.46def self.exploits; end4748# Must return a configuration Hash for the given exploit and vulnerability.49def self.configure_exploit(exploit, vuln); end5051# Should be overridden to return the payloads used for this52# vulnerability type as an Array of Strings.53def payloads; end5455def token56"xssmsfpro"57end5859#60# Should be overridden to return a pattern to be matched against response61# bodies in order to identify a vulnerability.62#63# You can go one deeper and override #find_proof for more complex processing.64#65def signature; end6667#68# Default #run, will audit all elements using taint analysis and log69# results based on #find_proof return values.70#71def run72auditable.each(&:taint_analysis)73end7475# Returns an Array of elements prepared to be audited.76def auditable77target.auditable.map do |element|78element.fuzzer = self79element80end81end8283# Checks whether a resource exists based on a path String.84def resource_exist?(path)85res = http.get(path)86res.code.to_i == 200 && !http.custom_404?(path, res.body)87end88alias file_exist? resource_exist?8990# Checks whether a directory exists based on a path String.91def directory_exist?(path)92dir = path.dup93dir << '/' if !dir.end_with?('/')94resource_exist?(dir)95end9697# Logs the existence of a resource in the path String.98def log_resource_if_exists(path)99log_resource(location: path) if resource_exist?(path)100end101alias log_file_if_exists log_resource_if_exists102103# Logs the existence of the directory in the path String.104def log_directory_if_exists(path)105dir = path.dup106dir << '/' if !dir.end_with?('/')107log_resource_if_exists(dir)108end109110# Matches fingerprint pattern against the current page's body and logs matches111def match_and_log_fingerprint(fingerprint, options = {})112return if (match = page.body.to_s.match(fingerprint).to_s).empty?113log_fingerprint(options.merge(fingerprint: match))114end115116#117# Serves as a default detection method for when performing taint analysis.118#119# Uses the Regexp in #signature against the response body in order to120# identify vulnerabilities and return a String that proves it.121#122# Override it if you need more complex processing, but remember to return123# the proof as a String.124#125# response - Auxiliary::Web::HTTP::Response126# element - the submitted element127#128def find_proof(response, _element)129return if !signature130131m = response.body.match(signature).to_s132return if !m || m.empty?133134m.gsub(/[\r\n]/, ' ')135end136137def increment_request_counter138parent.increment_request_counter139end140141# Should be overridden and return an Integer (0-100) denoting the confidence142# in the accuracy of the logged vuln.143def calculate_confidence(_vuln)144100145end146147def log_fingerprint(opts = {})148mode = name149vhash = [target.to_url, opts[:fingerprint], mode, opts[:location]]150.map(&:to_s).join('|').hash151152parent.vulns[mode] ||= {}153return if parent.vulns[mode].include?(vhash)154155location = opts[:location] ?156page.url.merge(URI(opts[:location].to_s)) : page.url157158info = {159web_site: target.site,160path: location.path,161query: location.query,162method: 'GET',163params: [],164pname: 'path',165proof: opts[:fingerprint],166risk: details[:risk],167name: details[:name],168blame: details[:blame],169category: details[:category],170description: details[:description],171owner: self172}173174info[:confidence] = calculate_confidence(info)175parent.vulns[mode][vhash] = info176177report_web_vuln(info)178179opts[:print_fingerprint] = true if !opts.include?(:print_fingerprint)180181print_good " FOUND(#{mode}) URL(#{location})"182print_good " PROOF(#{opts[:fingerprint]})" if opts[:print_fingerprint]183end184185def log_resource(opts = {})186mode = name187vhash = [target.to_url, mode, opts[:location]]188.map(&:to_s).join('|').hash189190parent.vulns[mode] ||= {}191return if parent.vulns[mode].include?(vhash)192193location = URI(opts[:location].to_s)194info = {195web_site: target.site,196path: location.path,197query: location.query,198method: 'GET',199params: [],200pname: 'path',201proof: opts[:location],202risk: details[:risk],203name: details[:name],204blame: details[:blame],205category: details[:category],206description: details[:description],207owner: self208}209210info[:confidence] = calculate_confidence(info)211parent.vulns[mode][vhash] = info212213report_web_vuln(info)214215print_good " VULNERABLE(#{mode}) URL(#{target.to_url})"216print_good " PROOF(#{opts[:location]})"217end218219def process_vulnerability(element, proof, opts = {})220mode = name221vhash = [target.to_url, mode, element.altered]222.map(&:to_s).join('|').hash223224parent.vulns[mode] ||= {}225return parent.vulns[mode][vhash] if parent.vulns[mode][vhash]226227parent.vulns[mode][vhash] = {228target: target,229method: element.method.to_s.upcase,230params: element.params.to_a,231mode: mode,232pname: element.altered,233proof: proof.to_s,234form: element.model,235risk: details[:risk],236name: details[:name],237blame: details[:blame],238category: details[:category],239description: details[:description]240}241242confidence = calculate_confidence(parent.vulns[mode][vhash])243244parent.vulns[mode][vhash][:confidence] = confidence245246if !(payload = opts[:payload])247if payloads248payload = payloads.select do |p|249element.altered_value.include?(p)250end.max_by(&:size)251end252end253254uri = URI(element.action)255info = {256web_site: element.model.web_site,257path: uri.path,258query: uri.query,259method: element.method.to_s.upcase,260params: element.params.to_a,261pname: element.altered,262proof: proof.to_s,263risk: details[:risk],264name: details[:name],265blame: details[:blame],266category: details[:category],267description: details[:description],268confidence: confidence,269payload: payload,270owner: self271}272273report_web_vuln(info)274275print_good " VULNERABLE(#{mode}) URL(#{target.to_url})" \276" PARAMETER(#{element.altered}) VALUES(#{element.params})"277print_good " PROOF(#{proof})"278end279end280end281282283