From dc9b4d32141d397b646cf6f1b4efb12ae4b9c40d Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Sat, 19 Dec 2015 05:55:36 +0000 Subject: [PATCH] Add method to remove network host --- .../ui/panel/tabs/ZombieTabNetwork.js | 39 ++++++++++++++++++- extensions/network/models/network_host.rb | 10 +++++ extensions/network/rest/network.rb | 21 ++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabNetwork.js b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabNetwork.js index bbd1179d7..3cc54119a 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabNetwork.js +++ b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabNetwork.js @@ -876,7 +876,44 @@ ZombieTab_Network = function(zombie) { } }] } - }] + },{ + xtype: 'menuseparator' + },{ + text: 'Remove', + iconCls: 'zombie-tree-ctxMenu-delete', + handler: function() { + var host_id = record.get('id'); + if (!confirm('Are you sure you want to remove network host [id: '+host_id+', ip: '+ ip +'] ?')) { + commands_statusbar.update_fail('Cancelled'); + return; + } + + commands_statusbar.update_sending('Removing network host [id: '+ host_id +', ip: '+ ip +'] ...'); + $jwterm.ajax({ + contentType: 'application/json', + dataType: 'json', + type: 'DELETE', + url: "/api/network/host/" + host_id + "?token=" + token, + async: false, + processData: false, + success: function(data){ + try { + if (data.success) { + commands_statusbar.update_sent('Removed network host successfully'); + Ext.getCmp('network-host-grid-zombie-'+zombie.session).getStore().reload(); + } else { + commands_statusbar.update_fail('Could not remove network host'); + } + } catch(e) { + commands_statusbar.update_fail('Could not remove network host'); + } + }, + error: function(){ + commands_statusbar.update_fail('Could not remove host'); + } + }); + } + }] }); } grid.rowCtxMenu.showAt(e.getXY()); diff --git a/extensions/network/models/network_host.rb b/extensions/network/models/network_host.rb index b3521ebc0..a975faaa6 100644 --- a/extensions/network/models/network_host.rb +++ b/extensions/network/models/network_host.rb @@ -68,6 +68,16 @@ module BeEF network_host end + # + # Removes a network host from the data store + # + def self.delete(id) + (print_error "Failed to remove network host. Invalid host ID."; return) if id.to_s !~ /\A\d+\z/ + host = BeEF::Core::Models::NetworkHost.get(id.to_i) + (print_error "Failed to remove network host [id: #{id}]. Host does not exist."; return) if host.nil? + host.destroy + end + end end diff --git a/extensions/network/rest/network.rb b/extensions/network/rest/network.rb index c08f6a22b..46638d7ff 100644 --- a/extensions/network/rest/network.rb +++ b/extensions/network/rest/network.rb @@ -119,6 +119,27 @@ module BeEF end end + # Removes a specific host given its id + delete '/host/:id' do + begin + id = params[:id] + raise InvalidParamError, 'id' if id !~ /\A\d+\z/ + + host = @nh.all(:id => id) + halt 404 if host.nil? + + result = {} + result['success'] = @nh.delete(id) + result.to_json + rescue InvalidParamError => e + print_error e.message + halt 400 + rescue StandardError => e + print_error "Internal error while removing network host with id #{id} (#{e.message})" + halt 500 + end + end + # Returns a specific service given its id get '/service/:id' do begin