Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/lib/msf/core/exploit/pgadmin.rb
Views: 18091
# -*- coding: binary -*-12#3# This mixin provides helpers to interact with pgAdmin. It provides methods to:4# - authenticate5# - obtain the CSRF token,6# - check the version of pgAdmin.7#8module Msf9module Exploit::PgAdmin10include Msf::Exploit::Remote::HttpClient1112def get_version13res = send_request_cgi('uri' => normalize_uri(target_uri.path, 'login'), 'keep_cookies' => true)14return unless res&.code == 2001516html_document = res.get_html_document17return unless html_document.xpath('//title').text == 'pgAdmin 4'1819versioned_link = html_document.xpath('//link').find { |link| link['href'] =~ /\?ver=(\d?\d)(\d\d)(\d\d)/ }20return unless versioned_link2122set_csrf_token_from_login_page(res)23Rex::Version.new("#{Regexp.last_match(1).to_i}.#{Regexp.last_match(2).to_i}.#{Regexp.last_match(3).to_i}")24end2526def check_version(patched_version, low_bound = 0)27version = get_version28return Msf::Exploit::CheckCode::Unknown('Unable to determine the target version') unless version29return Msf::Exploit::CheckCode::Safe("pgAdmin version #{version} is not affected") if version >= Rex::Version.new(patched_version) || version < Rex::Version.new(low_bound)3031Msf::Exploit::CheckCode::Appears("pgAdmin version #{version} is affected")32end3334def csrf_token35return @csrf_token if @csrf_token3637res = send_request_cgi('uri' => normalize_uri(target_uri.path, 'login'), 'keep_cookies' => true)38set_csrf_token_from_login_page(res)39fail_with(Msf::Exploit::Failure::UnexpectedReply, 'Failed to obtain the CSRF token') unless @csrf_token40@csrf_token41end4243def set_csrf_token_from_login_page(res)44if res&.code == 200 && res.body =~ /csrfToken": "([\w+.-]+)"/45@csrf_token = Regexp.last_match(1)46elsif (element = res.get_html_document.xpath("//input[@id='csrf_token']")&.first)47@csrf_token = element['value']48end49end5051def authenticate(username, password)52res = send_request_cgi({53'uri' => normalize_uri(target_uri.path, 'authenticate/login'),54'method' => 'POST',55'keep_cookies' => true,56'vars_post' => {57'csrf_token' => csrf_token,58'email' => username,59'password' => password,60'language' => 'en',61'internal_button' => 'Login'62}63})6465unless res&.code == 302 && res&.headers&.[]('Location') != normalize_uri(target_uri.path, 'login')66fail_with(Msf::Exploit::Failure::NoAccess, 'Failed to authenticate to pgAdmin')67end6869print_good('Successfully authenticated to pgAdmin')70res71end72end73end747576