Replace /ui/logs controller with REST API - #1389

This commit is contained in:
Brendan Coles
2019-02-16 14:31:18 +00:00
parent 1b173e4b98
commit f594c6c217
5 changed files with 13 additions and 88 deletions

View File

@@ -62,7 +62,8 @@ module BeEF
'id' => log.id.to_i,
'date' => log.date.to_s,
'event' => log.event.to_s,
'type' => log.type.to_s
'type' => log.type.to_s,
'hooked_browser_id' => log.hooked_browser_id.to_s
}
end

View File

@@ -1,83 +0,0 @@
#
# Copyright (c) 2006-2019 Wade Alcorn - wade@bindshell.net
# Browser Exploitation Framework (BeEF) - http://beefproject.com
# See the file 'doc/COPYING' for copying permission
#
module BeEF
module Extension
module AdminUI
module Controllers
class Logs < BeEF::Extension::AdminUI::HttpController
def initialize
super({
'paths' => {
'/all.json' => method(:select_all_logs),
'/zombie.json' => method(:select_zombie_logs)
}
})
end
# Selects logs in the database and returns them in a JSON format.
def select_all_logs
log = BeEF::Core::Models::Log.all()
(print_error "log is nil";return) if log.nil?
# format log
@body = logs2json(log)
end
# Selects the logs for a zombie
def select_zombie_logs
# get params
session = @params['session'] || nil
(print_error "session is nil";return) if session.nil?
zombie = BeEF::Core::Models::HookedBrowser.first(:session => session)
(print_error "zombie is nil";return) if zombie.nil?
(print_error "zombie.id is nil";return) if zombie.id.nil?
zombie_id = zombie.id
# get log
log = BeEF::Core::Models::Log.all(:hooked_browser_id => zombie_id)
(print_error "log is nil";return) if log.nil?
# format log
@body = logs2json(log)
end
private
# Returns a list of logs in JSON format.
def logs2json(logs)
logs_json = []
count = logs.length
output = '{success: false}'
logs.each do |log|
print_debug "UI(log/.zombie.json) call: #{log.event.to_s}"
logs_json << {
'id' => log.id.to_i,
'date' => log.date.to_s,
'event' => log.event.to_s,
'type' => log.type.to_s,
'hooked_browser_id' => log.hooked_browser_id.to_i
}
end
# format output
output = {'success' => 'true', 'count' => count, 'logs' => logs_json}.to_json if not logs_json.empty?
output
end
end
end
end
end
end

View File

@@ -10,11 +10,18 @@ LogsDataGrid = function(url, page, base) {
this.url = url;
this.base = typeof(base) != 'undefined' ? base : {};
// RESTful API token
var token = BeefWUI.get_rest_token();
this.store = new Ext.ux.data.PagingJsonStore({
root: 'logs',
autoDestroy: true,
autoLoad: false,
url: this.url,
autoLoad: false,
proxy: new Ext.data.HttpProxy({
method: 'GET',
url: url + '?token=' + token
}),
storeId: 'myStore',
baseParams: this.base,
idProperty: 'id',

View File

@@ -30,7 +30,7 @@ MainPanel = function(){
});
this.logs_grid = new LogsDataGrid('<%= @base_path %>/logs/all.json',30);
this.logs_grid = new LogsDataGrid('/api/logs',30);
this.logs_grid.border = false;
this.zombies_grid = new ZombieDataGrid('/api/hooks/all', 30);

View File

@@ -9,7 +9,7 @@
*/
ZombieTab_LogTab = function(zombie) {
var zombieLog = new LogsDataGrid('<%= @base_path %>/logs/zombie.json',30,{session:zombie.session});
var zombieLog = new LogsDataGrid('/api/logs/' + zombie.session ,30);
zombieLog.border = false;
ZombieTab_LogTab.superclass.constructor.call(this, {