Added api_token for RESTful api authentication

This commit is contained in:
antisnatchor
2012-03-12 10:27:03 +01:00
parent 7dab21ff7f
commit 872272645e
3 changed files with 22 additions and 0 deletions

3
beef
View File

@@ -109,6 +109,9 @@ BeEF::Core::Console::Banners.print_loaded_modules
BeEF::Core::Console::Banners.print_network_interfaces_count
BeEF::Core::Console::Banners.print_network_interfaces_routes
#@note Prints the API key needed to use the RESTful API
print_info "RESTful API key: #{BeEF::Core::Crypto::api_token}"
# @note Call the API method 'pre_http_start'
BeEF::API::Registrar.instance.fire(BeEF::API::Server, 'pre_http_start', http_hook_server)

View File

@@ -36,6 +36,19 @@ module Core
# return random hex string
return OpenSSL::Random.random_bytes(token_length).unpack("H*")[0]
end
# Generate a secure random token, 20 chars, used as an auth token for the RESTful API.
# After creation it's stored in the BeEF configuration object => conf.get('beef.api_token')
# @return [String] Security token
def self.api_token
config = BeEF::Core::Configuration.instance
token_length = 20
# return random hex string
token = OpenSSL::Random.random_bytes(token_length).unpack("H*")[0]
config.set('beef.api_token', token)
token
end
end
end

View File

@@ -19,6 +19,12 @@ module BeEF
module Rest
class Rest < Sinatra::Base
config = BeEF::Core::Configuration.instance
before do
error 401 unless params[:token] == config.get('beef.api_token')
end
get '/sinatra' do
"Sinatra! v.#{Sinatra::VERSION}"
end