2007-01-18 15:32:10 +00:00
|
|
|
/* web msfconsole (console.js)
|
2007-01-31 00:08:52 +00:00
|
|
|
* Original version is Copyright (c) 2006 LMH <lmh[at]info-pull.com>
|
|
|
|
* Added to Metasploit under the terms of the Metasploit Framework License v1.2
|
|
|
|
* Additions Copyright (C) 2006-2007 Metasploit LLC
|
|
|
|
*
|
2007-01-18 15:32:10 +00:00
|
|
|
* Inspired by Jesse Ruderman's Javascript Shell.
|
|
|
|
*/
|
|
|
|
|
2007-02-04 07:58:01 +00:00
|
|
|
var console_id;
|
2007-01-18 15:32:10 +00:00
|
|
|
var console_history = new Array(); // Commands history
|
|
|
|
var console_hindex = 0; // Index to current command history
|
|
|
|
var console_input; // Object to console input
|
|
|
|
var console_output; // Object to console output
|
2007-01-19 08:46:06 +00:00
|
|
|
var console_prompt; // Object to console prompt
|
2007-01-22 06:57:07 +00:00
|
|
|
var console_status;
|
|
|
|
var console_cmdbar;
|
2007-01-18 15:32:10 +00:00
|
|
|
|
2007-01-20 22:19:32 +00:00
|
|
|
// Placeholders
|
|
|
|
var con_prompt = "";
|
|
|
|
var con_update = "";
|
|
|
|
var con_tabbed = "";
|
|
|
|
|
|
|
|
|
2007-01-22 06:57:07 +00:00
|
|
|
|
|
|
|
// Internal commands
|
|
|
|
var cmd_internal =
|
|
|
|
{
|
|
|
|
clear:function() {
|
|
|
|
console_output.innerHTML = '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function status_busy() {
|
|
|
|
console_input.style.color = "red";
|
|
|
|
}
|
|
|
|
|
|
|
|
function status_free() {
|
|
|
|
console_input.style.color = "white";
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function is based on the excellent example:
|
|
|
|
// http://tryruby.hobix.com/js/mouseApp.js
|
|
|
|
function keystroke_block(e) {
|
|
|
|
e.cancelBubble=true;
|
|
|
|
e.returnValue = false;
|
|
|
|
if (window.event && !window.opera) e.keyCode=0;
|
|
|
|
if (e.stopPropagation) e.stopPropagation();
|
|
|
|
if (e.preventDefault) e.preventDefault();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-01-18 18:49:44 +00:00
|
|
|
function console_refocus() {
|
|
|
|
console_input.blur();
|
|
|
|
console_input.focus();
|
|
|
|
}
|
|
|
|
|
2007-01-31 00:08:52 +00:00
|
|
|
function console_read() {
|
2007-02-04 07:58:01 +00:00
|
|
|
new Ajax.Updater("console_update", '/_session/cid=' + console_id, {
|
2007-01-31 00:08:52 +00:00
|
|
|
asynchronous:true,
|
|
|
|
evalScripts:true,
|
|
|
|
onComplete:console_read_output
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-18 18:49:44 +00:00
|
|
|
function console_printline(s, type) {
|
|
|
|
if ((s=String(s))) {
|
|
|
|
var n = document.createElement("div");
|
2007-01-22 06:57:07 +00:00
|
|
|
|
|
|
|
// IE has to use innerText
|
|
|
|
if (n.innerText != undefined) {
|
|
|
|
n.innerText = s;
|
|
|
|
// Firefox uses createTextNode
|
|
|
|
} else {
|
|
|
|
n.appendChild(document.createTextNode(s));
|
|
|
|
}
|
|
|
|
|
2007-01-18 18:49:44 +00:00
|
|
|
n.className = type;
|
|
|
|
console_output.appendChild(n);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-31 00:08:52 +00:00
|
|
|
function console_read_output(req) {
|
|
|
|
// Call the console updated
|
|
|
|
console_update_output(req);
|
|
|
|
|
|
|
|
// Reschedule the console reader
|
|
|
|
setTimeout(console_read, 1000);
|
|
|
|
}
|
|
|
|
|
2007-01-20 22:19:32 +00:00
|
|
|
function console_update_output(req) {
|
|
|
|
|
|
|
|
try { eval(req.responseText); } catch(e){ alert(req.responseText); }
|
|
|
|
|
2007-01-22 06:57:07 +00:00
|
|
|
status_free();
|
2007-01-20 22:19:32 +00:00
|
|
|
|
2007-01-31 00:08:52 +00:00
|
|
|
if (con_update.length > 0) {
|
|
|
|
console_printline(con_update, 'output_line');
|
|
|
|
}
|
|
|
|
|
2007-01-20 22:19:32 +00:00
|
|
|
console_prompt.innerHTML = con_prompt;
|
|
|
|
console_refocus();
|
2007-01-31 00:08:52 +00:00
|
|
|
|
2007-01-18 15:32:10 +00:00
|
|
|
|
2007-01-18 18:49:44 +00:00
|
|
|
}
|
2007-01-18 15:32:10 +00:00
|
|
|
|
2007-01-20 22:19:32 +00:00
|
|
|
function console_update_tabs(req) {
|
|
|
|
try { eval(req.responseText); } catch(e){ console_output.innerHTML = req.responseText; }
|
|
|
|
|
2007-01-22 06:57:07 +00:00
|
|
|
status_free();
|
|
|
|
|
|
|
|
console_printline(con_update, 'output_line');
|
2007-01-20 22:19:32 +00:00
|
|
|
console_prompt.innerHTML = con_prompt;
|
|
|
|
console_input.value = con_tabbed;
|
|
|
|
|
|
|
|
console_refocus();
|
2007-01-19 08:46:06 +00:00
|
|
|
}
|
|
|
|
|
2007-01-20 22:19:32 +00:00
|
|
|
function console_keypress(e) {
|
|
|
|
if (e.keyCode == 13) { // enter
|
2007-01-22 06:57:07 +00:00
|
|
|
|
|
|
|
console_input.value = (console_input.value.replace(/^ +/,'')).replace(/ +$/,'');
|
2007-01-20 22:19:32 +00:00
|
|
|
|
2007-01-22 06:57:07 +00:00
|
|
|
// ignore duplicate commands in the history
|
|
|
|
if(console_history[console_history.length-1] != console_input.value) {
|
|
|
|
console_history.push(console_input.value);
|
|
|
|
console_hindex = console_history.length - 1;
|
|
|
|
}
|
2007-01-20 22:19:32 +00:00
|
|
|
|
2007-01-22 06:57:07 +00:00
|
|
|
console_printline("\n" + con_prompt + ' ' + console_input.value, 'output_line')
|
|
|
|
|
|
|
|
if(cmd_internal[console_input.value]) {
|
|
|
|
cmd_internal[console_input.value]();
|
|
|
|
console_input.value = "";
|
|
|
|
console_input.focus();
|
|
|
|
return keystroke_block(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
status_busy();
|
2007-01-19 08:46:06 +00:00
|
|
|
|
|
|
|
new Ajax.Updater("console_update", document.location, {
|
|
|
|
asynchronous:true,
|
|
|
|
evalScripts:true,
|
|
|
|
parameters:"cmd=" + escape(console_input.value),
|
|
|
|
onComplete:console_update_output
|
|
|
|
});
|
2007-01-20 22:19:32 +00:00
|
|
|
|
2007-01-19 08:46:06 +00:00
|
|
|
console_input.value = "";
|
|
|
|
console_input.focus();
|
2007-01-22 06:57:07 +00:00
|
|
|
return keystroke_block(e);
|
2007-01-20 22:19:32 +00:00
|
|
|
}
|
2007-01-19 08:46:06 +00:00
|
|
|
|
2007-01-20 22:19:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function console_keydown(e) {
|
2007-01-22 06:57:07 +00:00
|
|
|
|
2007-01-20 22:19:32 +00:00
|
|
|
if (e.keyCode == 38) { // up
|
2007-01-18 15:32:10 +00:00
|
|
|
// TODO: place upper cmd in history on console_input.value
|
2007-01-22 06:57:07 +00:00
|
|
|
|
|
|
|
console_input.value = console_history[console_hindex];
|
|
|
|
if (console_hindex > 0) {
|
|
|
|
console_hindex--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return keystroke_block(e);
|
|
|
|
|
2007-01-18 15:32:10 +00:00
|
|
|
} else if (e.keyCode == 40) { // down
|
2007-01-22 06:57:07 +00:00
|
|
|
|
|
|
|
if (console_hindex < console_history.length - 1) {
|
|
|
|
console_hindex++;
|
|
|
|
}
|
|
|
|
console_input.value = console_history[console_hindex];
|
|
|
|
|
|
|
|
return keystroke_block(e);
|
|
|
|
|
2007-01-18 15:32:10 +00:00
|
|
|
} else if (e.keyCode == 9) { // tab
|
2007-01-22 06:57:07 +00:00
|
|
|
|
|
|
|
status_busy();
|
|
|
|
|
2007-01-20 22:19:32 +00:00
|
|
|
new Ajax.Updater("console_update", document.location, {
|
|
|
|
asynchronous:true,
|
|
|
|
evalScripts:true,
|
|
|
|
parameters:"tab=" + escape(console_input.value),
|
|
|
|
onComplete:console_update_tabs
|
|
|
|
});
|
2007-01-22 06:57:07 +00:00
|
|
|
return keystroke_block(e);
|
2007-01-18 15:32:10 +00:00
|
|
|
}
|
2007-01-18 23:28:12 +00:00
|
|
|
|
2007-01-18 15:32:10 +00:00
|
|
|
}
|
|
|
|
|
2007-02-04 07:58:01 +00:00
|
|
|
function console_init(cid) {
|
2007-01-18 15:32:10 +00:00
|
|
|
|
2007-02-04 07:58:01 +00:00
|
|
|
console_id = cid;
|
2007-01-18 15:32:10 +00:00
|
|
|
console_input = document.getElementById("console_input");
|
|
|
|
console_output = document.getElementById("console_output");
|
2007-01-19 08:46:06 +00:00
|
|
|
console_prompt = document.getElementById("console_prompt");
|
2007-01-22 06:57:07 +00:00
|
|
|
console_status = document.getElementById("console_status");
|
|
|
|
console_cmdbar = document.getElementById("console_command_bar");
|
2007-01-19 08:46:06 +00:00
|
|
|
|
2007-01-20 22:19:32 +00:00
|
|
|
console_refocus();
|
2007-01-22 06:57:07 +00:00
|
|
|
status_free();
|
2007-01-20 22:19:32 +00:00
|
|
|
|
2007-02-04 07:58:01 +00:00
|
|
|
console_read();
|
2007-01-31 00:08:52 +00:00
|
|
|
|
2007-01-18 15:32:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|