Add method to remove network host

This commit is contained in:
Brendan Coles
2015-12-19 05:55:36 +00:00
parent d9cb64e1cb
commit dc9b4d3214
3 changed files with 69 additions and 1 deletions

View File

@@ -876,6 +876,43 @@ 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');
}
});
}
}]
});
}

View File

@@ -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

View File

@@ -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