metasploit-framework/modules/auxiliary/scanner/http/jenkins_enum.rb

251 lines
7.0 KiB
Ruby
Raw Normal View History

2013-10-22 14:27:37 +00:00
##
# This module requires Metasploit: http//metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
2013-09-17 14:47:59 +00:00
##
# Some of this code was taken from the "jboss_vulnscan" module by: Tyler Krpata
##
require 'rex/proto/http'
require 'msf/core'
require 'rexml/document'
2013-09-17 14:47:59 +00:00
class Metasploit3 < Msf::Auxiliary
2013-10-22 14:26:44 +00:00
include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::Report
2013-09-17 14:47:59 +00:00
2013-10-22 14:26:44 +00:00
def initialize(info = {})
super(update_info(info,
2013-10-22 14:28:15 +00:00
'Name' => 'Jenkins Vulnerability Scanner',
'Description' => %q{
2013-10-22 14:28:43 +00:00
This module scans a Jenkins installation for a few vulnerabilities.
2013-10-22 14:26:44 +00:00
},
2013-10-22 14:28:15 +00:00
'Author' => 'Jeff McCutchan',
'License' => MSF_LICENSE
2013-10-22 14:26:44 +00:00
))
2013-09-17 14:47:59 +00:00
2013-10-22 14:26:44 +00:00
register_options(
[
OptString.new('TARGETURI', [ true, "Path to Jenkins instance", "/jenkins/"]),
], self.class)
end
2013-09-17 14:47:59 +00:00
2013-10-22 14:26:44 +00:00
def run_host(ip)
res = send_request_cgi(
{
'uri' => target_uri.path,
'method' => 'GET',
'ctype' => 'text/plain',
})
2013-10-22 15:02:32 +00:00
unless res
vprint_error("#{peer} - No response received")
return
end
unless res.headers.include?('X-Jenkins')
vprint_error("#{peer} - responded with #{res.code} but does not seem to be Jenkins")
2013-10-22 14:26:44 +00:00
return
end
2013-10-22 15:02:32 +00:00
2013-10-22 14:26:44 +00:00
version = res.headers['X-Jenkins']
2013-10-22 16:15:16 +00:00
vprint_status("#{peer} - Jenkins Version - #{version}")
report_service(
:host => rhost,
:port => rport,
:name => (ssl ? 'https' : 'http'),
:proto => 'tcp'
)
report_web_site(
:host => rhost,
:port => rport,
:ssl => ssl,
:info => "Jenkins Version - #{version}"
)
2013-10-22 15:02:32 +00:00
2013-10-22 14:26:44 +00:00
# script - exploit module for this
# view/All/newJob - can be exploited manually
# asynchPeople - Jenkins users
# systemInfo - system information
2013-10-22 15:02:32 +00:00
apps = [
'script',
'view/All/newJob',
'asynchPeople/',
'systemInfo'
2013-10-22 14:26:44 +00:00
]
apps.each do |app|
check_app(app)
end
end
2013-09-17 14:47:59 +00:00
2013-10-22 14:26:44 +00:00
def check_app(app)
uri_path = normalize_uri(target_uri.path, app)
res = send_request_cgi({
'uri' => uri_path,
'method' => 'GET',
'ctype' => 'text/plain',
})
2013-10-22 15:02:32 +00:00
unless res
vprint_error("#{peer} - Timeout")
2013-10-22 14:26:44 +00:00
return
end
2013-10-22 15:02:32 +00:00
2013-10-22 14:26:44 +00:00
case res.code
when 200
2013-10-22 15:02:32 +00:00
print_good("#{peer} - #{uri_path} does not require authentication (200)")
2013-10-22 16:15:16 +00:00
report_note({
:type => "jenkins_path",
:host => rhost,
:port => rport,
:proto => 'tcp',
:data => "#{uri_path} does not require authentication (200)",
:update => :unique_data
})
2013-10-22 14:26:44 +00:00
case app
when "systemInfo"
parse_system_info(res.body)
when "script"
report_vuln(
:host => rhost,
:port => rport,
:proto => 'tcp',
:sname => (ssl ? 'https' : 'http'),
2013-10-22 15:02:32 +00:00
:name => "Jenkins Script-Console Java Execution",
2013-10-22 14:26:44 +00:00
:info => "Module #{self.fullname} confirmed access to the Jenkins Script Console with no authentication"
)
end
when 403
2013-10-22 15:02:32 +00:00
vprint_status("#{peer} - #{uri_path} restricted (403)")
2013-10-22 14:26:44 +00:00
when 401
2013-10-22 15:02:32 +00:00
vprint_status("#{peer} - #{uri_path} requires authentication (401): #{res.headers['WWW-Authenticate']}")
2013-10-22 14:26:44 +00:00
when 404
2013-10-22 15:02:32 +00:00
vprint_status("#{peer} - #{uri_path} not found (404)")
2013-10-22 14:26:44 +00:00
when 301
2013-10-22 15:02:32 +00:00
vprint_status("#{peer} - #{uri_path} is redirected (#{res.code}) to #{res.headers['Location']} (not following)")
2013-10-22 14:26:44 +00:00
when 302
2013-10-22 15:02:32 +00:00
vprint_status("#{peer} - #{uri_path} is redirected (#{res.code}) to #{res.headers['Location']} (not following)")
2013-10-22 14:26:44 +00:00
else
2013-10-22 15:02:32 +00:00
vprint_status("#{peer} - #{uri_path} Don't know how to handle response code #{res.code}")
2013-10-22 14:26:44 +00:00
end
end
2013-09-17 14:47:59 +00:00
2013-10-22 14:26:44 +00:00
def parse_system_info(body)
2013-10-22 15:02:32 +00:00
vprint_status("#{peer} - Getting useful information from systemInfo")
2013-10-22 14:26:44 +00:00
infos = {
2013-10-22 15:29:30 +00:00
"os.name" => nil,
"os.version" => nil,
"sun.os.patch.level" => nil,
"os.arch" => nil,
"user.name" => nil,
"USERDOMAIN" => nil,
"user.home" => nil,
"user.language" => nil,
"user.country" => nil,
"user.timezone" => nil,
"COMPUTERNAME" => nil,
"SystemDrive" => nil,
"TEMP" => nil,
"TMP" => nil,
"SHELL" => nil
2013-10-22 14:26:44 +00:00
}
2013-10-22 15:02:32 +00:00
# remove unclosed tags for REXML
2013-10-22 15:29:30 +00:00
body.gsub!('<wbr>', '')
body.gsub!('<br>', '')
2013-10-22 15:02:32 +00:00
doc = REXML::Document.new(body)
tds = doc.get_elements("//td")
2013-10-22 15:29:30 +00:00
tds.each_index do |idx|
td = tds[idx].get_text.to_s.strip
infos[td] = tds[idx+1].get_text.to_s.strip if infos.has_key?(td)
2013-10-22 15:02:32 +00:00
end
2013-10-22 14:26:44 +00:00
# print out the goodies
infos.each do |k, v|
next if v.nil?
case k
when "os.name"
2013-10-22 16:15:16 +00:00
vprint_line(" OS: #{v}")
report_host({:host => rhost, :os_name => v})
2013-10-22 14:26:44 +00:00
when "os.version"
2013-10-22 16:15:16 +00:00
vprint_line(" OS Version: #{v}")
report_host({:host => rhost, :os_flavor => v})
2013-10-22 14:26:44 +00:00
when "sun.os.patch.level"
2013-10-22 16:15:16 +00:00
vprint_line(" Patch Level: #{v}")
2013-10-22 14:26:44 +00:00
when "os.arch"
2013-10-22 16:15:16 +00:00
vprint_line(" Arch: #{v}")
report_note({
:type => "system_arch",
:host => rhost,
:data => "Arch: #{v}",
:update => :unique_data
})
2013-10-22 14:26:44 +00:00
when "user.name"
2013-10-22 16:15:16 +00:00
vprint_line(" User: #{v}")
report_note({
:type => "jenkins_user",
:host => rhost,
:port => rport,
:proto => 'tcp',
:data => "User: #{v}",
:update => :unique_data
})
2013-10-22 14:26:44 +00:00
when "USERDOMAIN"
2013-10-22 16:15:16 +00:00
vprint_line(" Domain: #{v}")
report_note({
:type => "system_domain",
:host => rhost,
:data => "Domain: #{v}",
:update => :unique_data
})
2013-10-22 14:26:44 +00:00
when "COMPUTERNAME"
2013-10-22 16:15:16 +00:00
vprint_line(" Computer Name: #{v}")
report_note({
:type => "system_computer",
:host => rhost,
:data => "Computer Name: #{v}",
:update => :unique_data
})
2013-10-22 14:26:44 +00:00
when "SystemDrive"
vprint_line(" System Drive: #{v}")
when "SHELL"
2013-10-22 16:15:16 +00:00
vprint_line(" Shell: #{v}")
2013-10-22 14:26:44 +00:00
when "TEMP"
2013-10-22 16:15:16 +00:00
vprint_line(" Temp Directory: #{v}")
2013-10-22 14:26:44 +00:00
when "TMP"
2013-10-22 16:15:16 +00:00
vprint_line(" Temp Directory: #{v}")
2013-10-22 14:26:44 +00:00
when "user.home"
vprint_line(" Home Directory: #{v}")
when "user.language"
vprint_line(" Language: #{v}")
2013-10-22 16:15:16 +00:00
report_note({
:type => "system_lang",
:host => rhost,
:data => "Language: #{v}",
:update => :unique_data
})
2013-10-22 14:26:44 +00:00
when "user.country"
vprint_line(" Country: #{v}")
2013-10-22 16:15:16 +00:00
report_note({
:type => "system_country",
:host => rhost,
:data => "Country: #{v}",
:update => :unique_data
})
2013-10-22 14:26:44 +00:00
when "user.timezone"
vprint_line(" Timezone: #{v}")
2013-10-22 16:15:16 +00:00
report_note({
:type => "system_timezone",
:host => rhost,
:data => "Timezone: #{v}",
:update => :unique_data
})
2013-10-22 14:26:44 +00:00
end
end
2013-10-22 16:15:16 +00:00
vprint_line('')
2013-10-22 14:26:44 +00:00
end
2013-09-17 14:47:59 +00:00
end