Skip to content

Commit

Permalink
BeEF::Extension:::Events: Add error handling to event parsing (#2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles authored Mar 28, 2023
1 parent bcd0865 commit a5d08d7
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions extensions/events/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,33 @@ def setup

# push events to logger
logger = BeEF::Core::Logger.instance
events.each do |value|
logger.register('Event', parse(value), zombie.id)
events.each do |event|
unless event.is_a?(Hash)
print_error("[Event Logger] Received event data of type #{event.class}; expected Hash")
next
end

if event['type'].nil?
print_error("[Event Logger] Received event with no type: #{event.inspect}")
next
end

data = event_log_string(event)

next if data.nil?

logger.register('Event', data, zombie.id)
end
end

def parse(event)
case event['type']
def event_log_string(event)
return unless event.is_a?(Hash)

event_type = event['type']

return if event_type.nil?

case event_type
when 'click'
result = "#{event['time']}s - [Mouse Click] x: #{event['x']} y:#{event['y']} > #{event['target']}"
when 'focus'
Expand All @@ -63,18 +83,18 @@ def parse(event)
when 'keys'
print_debug "+++++++++++++++++ Key mods: #{event['mods']}"
print_debug "EventData: #{event['data']}"

result = "#{event['time']}s - [User Typed] #{event['data']}"
if event['mods'].size.positive?
print_debug 'Event has mods'
result = "#{event['time']}s - [User Typed] #{event['data']} - (Mods debug) #{event['mods']}"
else
result = "#{event['time']}s - [User Typed] #{event['data']}"
result += " (modifiers: #{event['mods']})"
end
when 'submit'
result = "#{event['time']}s - [Form Submitted] \"#{event['data']}\" > #{event['target']}"
else
print_debug '[EVENTS] Event handler has received an unknown event'
result = "#{event['time']}s - Unknown event"
print_debug("[Event Logger] Event handler has received event of unknown type '#{event_type}'")
result = "#{event['time']}s - Unknown event '#{event_type}'"
end

result
end
end
Expand Down

0 comments on commit a5d08d7

Please sign in to comment.