initial commit of notifications extension

This commit is contained in:
Marc Wickenden
2012-07-19 22:51:39 +01:00
parent bfa2e6dbf7
commit 6ade1469bb
10 changed files with 287 additions and 2 deletions

View File

@@ -39,6 +39,9 @@ gem "erubis"
gem "dm-migrations"
gem "msfrpc-client"
# notifications
gem "twitter"
if ENV['BEEF_TEST']
# for running unit tests
gem "test-unit"

76
Gemfile.lock Normal file
View File

@@ -0,0 +1,76 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.2.8)
ansi (1.4.2)
daemons (1.1.8)
data_objects (0.10.8)
addressable (~> 2.1)
dm-core (1.2.0)
addressable (~> 2.2.6)
dm-do-adapter (1.2.0)
data_objects (~> 0.10.6)
dm-core (~> 1.2.0)
dm-migrations (1.2.0)
dm-core (~> 1.2.0)
dm-sqlite-adapter (1.2.0)
dm-do-adapter (~> 1.2.0)
do_sqlite3 (~> 0.10.6)
do_sqlite3 (0.10.8)
data_objects (= 0.10.8)
em-websocket (0.3.6)
addressable (>= 2.1.1)
eventmachine (>= 0.12.9)
erubis (2.7.0)
eventmachine (0.12.10)
faraday (0.8.1)
multipart-post (~> 1.1)
jsmin (1.0.1)
json (1.7.3)
librex (0.0.65)
msfrpc-client (1.0.1)
librex (>= 0.0.32)
msgpack (>= 0.4.5)
msgpack (0.4.7)
multi_json (1.3.6)
multipart-post (1.1.5)
parseconfig (1.0.2)
rack (1.4.1)
rack-protection (1.2.0)
rack
simple_oauth (0.1.8)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
term-ansicolor (1.0.7)
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
rack (>= 1.0.0)
tilt (1.3.3)
twitter (3.3.1)
faraday (~> 0.8)
multi_json (~> 1.3)
simple_oauth (~> 0.1.6)
PLATFORMS
ruby
DEPENDENCIES
ansi
data_objects
dm-core
dm-migrations
dm-sqlite-adapter
em-websocket (~> 0.3.6)
erubis
eventmachine (= 0.12.10)
jsmin (~> 1.0.1)
json
msfrpc-client
parseconfig
sinatra (= 1.3.2)
term-ansicolor
thin
twitter

View File

@@ -17,7 +17,7 @@
beef:
version: '0.4.3.6-alpha'
debug: false
debug: true
restrictions:
# subnet of browser ip addresses that can hook to the framework

View File

@@ -24,6 +24,7 @@ module Core
# Constructor
def initialize
@logs = BeEF::Core::Models::Log
@notifications = BeEF::Extensions::Notifications
end
# Registers a new event in the logs
@@ -34,6 +35,9 @@ module Core
def register(from, event, hb = 0)
# type conversion to enforce standards
hb = hb.to_i
# get time now
time_now = Time.now
# arguments type checking
raise Exception::TypeError, '"from" needs to be a string' if not from.string?
@@ -41,7 +45,10 @@ module Core
raise Exception::TypeError, '"Hooked Browser ID" needs to be an integer' if not hb.integer?
# logging the new event into the database
@logs.new(:type => "#{from}", :event => "#{event}", :date => Time.now, :hooked_browser_id => hb).save
@logs.new(:type => "#{from}", :event => "#{event}", :date => time_now, :hooked_browser_id => hb).save
# if notifications are enabled send the info there too
@notifications.new(from, event, time_now, hb)
# return
true

View File

@@ -0,0 +1,55 @@
#
# Copyright 2012 Wade Alcorn wade@bindshell.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module BeEF
module Core
class Notifications
include Singleton
# Constructor
def initialize
@notifications = BeEF::Core::Models::Notifications
end
# Registers a new event in the logs
# @param [String] from The origin of the event (i.e. Authentication, Hooked Browser)
# @param [String] event The event description
# @param [Integer] hb The id of the hooked browser affected (default = 0 if no HB)
# @return [Boolean] True if the register was successful
def register(from, event, hb = 0)
# type conversion to enforce standards
hb = hb.to_i
# arguments type checking
raise Exception::TypeError, '"from" needs to be a string' if not from.string?
raise Exception::TypeError, '"event" needs to be a string' if not event.string?
raise Exception::TypeError, '"Hooked Browser ID" needs to be an integer' if not hb.integer?
# logging the new event into the database
@logs.new(:type => "#{from}", :event => "#{event}", :date => Time.now, :hooked_browser_id => hb).save
# return
true
end
private
@logs
end
end
end

Binary file not shown.

View File

@@ -0,0 +1,28 @@
#
# Copyright 2012 Wade Alcorn wade@bindshell.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
beef:
extension:
notifications:
enable: true
name: Notifications
twitter:
enable: true
consumer_token: consumer_token
consumer_secret: consumer_secret
email:
enable: false
address: nobody@nobody.com

View File

@@ -0,0 +1,30 @@
#
# Copyright 2012 Wade Alcorn wade@bindshell.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module BeEF
module Extension
module Notifications
extend BeEF::API::Extension
@short_name = 'notifications'
@full_name = 'Notifications'
@description = 'Generates external notifications for events in BeEF'
end
end
end
require 'extensions/notifications/handler'

View File

@@ -0,0 +1,43 @@
#
# Copyright 2012 Wade Alcorn wade@bindshell.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module BeEF
module Extension
module Notifications
#
# The handler for notifications
#
class Handler
def initialize
@config = BeEF::Core::Configuration.instance.get('beef.extension.notifications')
@config.inspect
if @config.enable = false
# notifications are not enabled
return nil
end
end
def new(from, event, time_now, hb)
print_info "#{from}:#{event}:#{time_now}:#{hb}"
end
end
end
end
end

View File

@@ -0,0 +1,43 @@
#
# Copyright 2012 Wade Alcorn wade@bindshell.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Generic Http Handler that extensions can use to register http
# controllers into the framework.
#
module BeEF
module Extension
module Notifications
module Handlers
class Twitter
#
# Constructor
#
def initialize
# configure the Twitter client
Twitter.configure do |config|
config.consumer_key = ''
config.consumer_secret = ''
end
end
end
end
end
end
end