Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bka authored and bka committed Dec 1, 2011
1 parent e4fa85b commit 722e3fe
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 52 deletions.
Expand Up @@ -4,10 +4,6 @@ module PreludeDB
class DetectTime < FIDIUS::PreludeDB::Connection class DetectTime < FIDIUS::PreludeDB::Connection
set_primary_key :_message_ident set_primary_key :_message_ident
set_table_name "Prelude_DetectTime" set_table_name "Prelude_DetectTime"
#def self.table_name
# puts "HALLO"
# "Prelude_DetectTime"
#end
end end
end end
end end
Expand Up @@ -12,8 +12,6 @@ def config(conf)
end end


def begin_record def begin_record
#a = FIDIUS::PreludeDB::Alert.find(:first,:joins => [:detect_time],:order=>"time DESC")
#last_event = FIDIUS::PreludeDB::PreludeEvent.new(a)
t = FIDIUS::PreludeDB::DetectTime.find(:first,:order=>"time DESC") t = FIDIUS::PreludeDB::DetectTime.find(:first,:order=>"time DESC")
@start_time = t.time @start_time = t.time
end end
Expand All @@ -24,9 +22,6 @@ def get_events
sleep 3 sleep 3
$logger.debug "alert.find(:all,:joins=>[:detect_time],time > #{@start_time})" $logger.debug "alert.find(:all,:joins=>[:detect_time],time > #{@start_time})"



#events = FIDIUS::PreludeDB::Alert.find(:all,:joins => [:detect_time],:order=>"time DESC",:conditions=>["time > :d",{:d => @start_time}])

detect_times = FIDIUS::PreludeDB::DetectTime.find(:all,:order=>"time DESC",:conditions=>["time > :d",{:d => @start_time}]) detect_times = FIDIUS::PreludeDB::DetectTime.find(:all,:order=>"time DESC",:conditions=>["time > :d",{:d => @start_time}])
events = [] events = []
detect_times.each do |dt| detect_times.each do |dt|
Expand All @@ -41,7 +36,7 @@ def get_events
if @local_ip if @local_ip
if (ev.source_ip == @local_ip || ev.dest_ip == @local_ip) if (ev.source_ip == @local_ip || ev.dest_ip == @local_ip)
$logger.debug "adding #{ev.inspect} to events " $logger.debug "adding #{ev.inspect} to events "
res << ev res << ev
end end
else else
$logger.debug "adding #{ev.inspect} to events " $logger.debug "adding #{ev.inspect} to events "
Expand Down Expand Up @@ -75,4 +70,3 @@ def fetch_events(module_instance=nil)
$logger.debug "loading #{rb}" $logger.debug "loading #{rb}"
require rb require rb
end end

7 changes: 0 additions & 7 deletions lib/evasion-db/knowledge/ids_rule.rb
Expand Up @@ -27,13 +27,6 @@ def self.create_if_not_exists(text,sort=0)
rescue rescue
puts $!.message puts $!.message
end end
# try again without ignore maybe our database does not support ignore
#SQLite3::SQLException: near "IGNORE"
#h = Digest::MD5.hexdigest(text)
#rule = self.find_or_create_by_rule_hash(h)
#rule.rule_text=text
#rule.sort = sort
#rule.save
end end
end end
end end
Expand Down
3 changes: 0 additions & 3 deletions lib/evasion-db/postgres_patch.rb
Expand Up @@ -10,8 +10,6 @@
# ORDER BY a.attnum # ORDER BY a.attnum
# provided @http://s3.amazonaws.com/activereload-lighthouse/assets/a3d9b3646f58246ef6ffe027001dd643cca7aade/postgresql-support-capitalized-table-names.diff?AWSAccessKeyId=1AJ9W2TX1B2Z7C2KYB82&Expires=1290010522&Signature=ignfCi9%2Bm37oHijccGBsbJj298w%3D # provided @http://s3.amazonaws.com/activereload-lighthouse/assets/a3d9b3646f58246ef6ffe027001dd643cca7aade/postgresql-support-capitalized-table-names.diff?AWSAccessKeyId=1AJ9W2TX1B2Z7C2KYB82&Expires=1290010522&Signature=ignfCi9%2Bm37oHijccGBsbJj298w%3D


puts ">> Loading Postgres patch"

module ActiveRecord module ActiveRecord
module ConnectionAdapters module ConnectionAdapters
class PostgreSQLAdapter < AbstractAdapter class PostgreSQLAdapter < AbstractAdapter
Expand All @@ -21,4 +19,3 @@ def quote_table_name(name)
end end
end end
end end

23 changes: 7 additions & 16 deletions lib/evasion-db/recorders/msf-recorder/lib/msf-recorder.rb
@@ -1,20 +1,13 @@
module FIDIUS module FIDIUS
module EvasionDB module EvasionDB
# This recorder provides an interface for the metasploit console # This recorder provides an interface for the metasploit console
# it is used to have callbacks when modules are executed. # it is used to have callbacks when modules are executed.
# #
# @see {file:msf-plugins/evasiondb.rb} # @see {file:msf-plugins/evasiondb.rb}
module MsfRecorder module MsfRecorder
def module_started(module_instance) def module_started(module_instance)
# use rule_fetcher if the module starts # use rule_fetcher if the module starts
@@current_exploit = FIDIUS::EvasionDB::Knowledge::AttackModule.find_or_create_by_name_and_options(module_instance.fullname,module_instance.datastore) @@current_exploit = FIDIUS::EvasionDB::Knowledge::AttackModule.find_or_create_by_name_and_options(module_instance.fullname,module_instance.datastore)
#begin
# if FIDIUS::EvasionDB.current_rule_fetcher
# FIDIUS::EvasionDB.current_rule_fetcher.fetch_rules(@@current_exploit)
# end
#rescue
# puts $!.message+":"+$!.backtrace.to_s
#end
FIDIUS::EvasionDB.current_fetcher.begin_record FIDIUS::EvasionDB.current_fetcher.begin_record
end end


Expand All @@ -35,7 +28,7 @@ def module_completed(module_instance)
if module_instance && module_instance.respond_to?("fullname") if module_instance && module_instance.respond_to?("fullname")
$logger.debug "idmef_events << #{idmef_event}" $logger.debug "idmef_events << #{idmef_event}"
@@current_exploit.idmef_events << idmef_event @@current_exploit.idmef_events << idmef_event
# meterpreter is not a module and does not respond to fullname # meterpreter is not a module and does not respond to fullname
# we handle this seperatly # we handle this seperatly
elsif module_instance == "Meterpreter" elsif module_instance == "Meterpreter"
$logger.debug "attack_payload.idmef_events << #{idmef_event}" $logger.debug "attack_payload.idmef_events << #{idmef_event}"
Expand All @@ -56,17 +49,15 @@ def module_error(module_instance,exception)


def log_packet(module_instance,data,socket) def log_packet(module_instance,data,socket)
begin begin
# set local ip, if there is no
#FIDIUS::EvasionDB.current_fetcher.local_ip = FIDIUS::Common.get_my_ip(socket.peerhost)
$logger.debug "logged module_instance: #{module_instance} with #{data.size} bytes payload" $logger.debug "logged module_instance: #{module_instance} with #{data.size} bytes payload"
# TODO: what shall we do with meterpreter? # TODO: what shall we do with meterpreter?
# it has not options and no fullname, logger assigns only the string "meterpreter" # it has not options and no fullname, logger assigns only the string "meterpreter"
if module_instance.respond_to?("fullname") if module_instance.respond_to?("fullname")
unless @@current_exploit.finished unless @@current_exploit.finished
@@current_exploit.packets << FIDIUS::EvasionDB::Knowledge::Packet.create(:payload=>data,:src_addr=>socket.localhost,:src_port=>socket.localport,:dest_addr=>socket.peerhost,:dest_port=>socket.peerport) @@current_exploit.packets << FIDIUS::EvasionDB::Knowledge::Packet.create(:payload=>data,:src_addr=>socket.localhost,:src_port=>socket.localport,:dest_addr=>socket.peerhost,:dest_port=>socket.peerport)
@@current_exploit.save @@current_exploit.save
end end
# meterpreter is not a module and does not respond to fullname # meterpreter is not a module and does not respond to fullname
# we handle this seperatly # we handle this seperatly
elsif module_instance == "Meterpreter" elsif module_instance == "Meterpreter"
$logger.debug "module_instance is meterpreter" $logger.debug "module_instance is meterpreter"
Expand All @@ -77,8 +68,8 @@ def log_packet(module_instance,data,socket)
$logger.debug "LOG: #{module_instance} #{data.size} Bytes on #{socket}" $logger.debug "LOG: #{module_instance} #{data.size} Bytes on #{socket}"
rescue ActiveRecord::StatementInvalid rescue ActiveRecord::StatementInvalid
$logger.error "StatementInvalid" $logger.error "StatementInvalid"
rescue rescue
$logger.error "error:" # "#{$!.message}" ##{$!.inspect}:#{$!.backtrace}" $logger.error "error:"
end end
end end
end end
Expand Down
9 changes: 2 additions & 7 deletions lib/evasion-db/rule_fetchers/snort/lib/snort.rb
Expand Up @@ -3,7 +3,7 @@
rescue rescue
raise "can not find snortor gem. Please gem install snortor" raise "can not find snortor gem. Please gem install snortor"
end end
#require 'evasion-db/vendor/bitfield'
require File.join(FIDIUS::EvasionDB::GEM_BASE, 'evasion-db', 'vendor', 'bitfield') require File.join(FIDIUS::EvasionDB::GEM_BASE, 'evasion-db', 'vendor', 'bitfield')


module FIDIUS module FIDIUS
Expand Down Expand Up @@ -52,15 +52,12 @@ def fetch_rules(attack_module)
ruleset.save ruleset.save
end end


# fetches rules with snortor # fetches rules with snortor
# and stores them all into db # and stores them all into db
def import_rules def import_rules
raise "rules imported already" if FIDIUS::EvasionDB::Knowledge::IdsRule.all.size > 0 raise "rules imported already" if FIDIUS::EvasionDB::Knowledge::IdsRule.all.size > 0
import_rules_to_snortor import_rules_to_snortor


start_time = Time.now
puts "rules exported save to db now"

i = 0 i = 0
insert_query = [] insert_query = []
Snortor.rules.each do |rule| Snortor.rules.each do |rule|
Expand All @@ -79,8 +76,6 @@ def import_rules
puts $!.message+":"+$!.backtrace.to_s puts $!.message+":"+$!.backtrace.to_s
end end
end end
end_time = Time.now
puts "Import needed #{end_time-start_time} seconds"
end end


def config(conf) def config(conf)
Expand Down
1 change: 0 additions & 1 deletion lib/evasion-db/rule_fetchers/snort/rule_fetcher.rb
@@ -1,4 +1,3 @@
puts "loading snort_fetcher"
FIDIUS::EvasionDB.rule_fetcher "Snortrule-Fetcher" do FIDIUS::EvasionDB.rule_fetcher "Snortrule-Fetcher" do
install do install do
require (File.join File.dirname(__FILE__), 'lib', 'snort.rb') require (File.join File.dirname(__FILE__), 'lib', 'snort.rb')
Expand Down
13 changes: 6 additions & 7 deletions lib/msf-plugins/evasiondb.rb
Expand Up @@ -52,7 +52,7 @@ def to_hex_dump(str, from=-1, to=-1)
snl = false snl = false
lst = 0 lst = 0
rclosed = true rclosed = true
while (idx < str.length) while (idx < str.length)
chunk = str[idx, width] chunk = str[idx, width]
line = chunk.unpack("H*")[0].scan(/../).join(" ") line = chunk.unpack("H*")[0].scan(/../).join(" ")
if from >= idx && from < idx+width if from >= idx && from < idx+width
Expand Down Expand Up @@ -184,7 +184,7 @@ def cmd_config_exploit(*args)
def cmd_show_packet(*args) def cmd_show_packet(*args)
raise "please provide packet_id" if args.size != 1 raise "please provide packet_id" if args.size != 1
packet = FIDIUS::EvasionDB::Knowledge::Packet.find(args[0].to_i) packet = FIDIUS::EvasionDB::Knowledge::Packet.find(args[0].to_i)

hex = to_hex_dump(packet.payload) hex = to_hex_dump(packet.payload)
print_line hex print_line hex
end end
Expand All @@ -203,7 +203,7 @@ def cmd_show_event(*args)
print_line "#{packet[:packet].payload.size} bytes" print_line "#{packet[:packet].payload.size} bytes"
print_line "match #{packet[:index]} - #{packet[:index]+packet[:length]-1}" print_line "match #{packet[:index]} - #{packet[:index]+packet[:length]-1}"
hex = to_hex_dump(packet[:packet].payload,packet[:index],packet[:index]+packet[:length]-1) hex = to_hex_dump(packet[:packet].payload,packet[:index],packet[:index]+packet[:length]-1)
print_line hex print_line hex
else else
print_line "no packets available" print_line "no packets available"
end end
Expand All @@ -213,7 +213,6 @@ def cmd_show_event(*args)
end end


def cmd_fetch_events(*args) def cmd_fetch_events(*args)
#events = FIDIUS::EvasionDB::Knowledge.fetch_events
FIDIUS::EvasionDB.current_fetcher.local_ip = nil FIDIUS::EvasionDB.current_fetcher.local_ip = nil
events = FIDIUS::EvasionDB.current_fetcher.fetch_events events = FIDIUS::EvasionDB.current_fetcher.fetch_events
if events if events
Expand Down Expand Up @@ -286,7 +285,7 @@ def self.log_packet(socket,data,module_instance=nil)
end end


def self.inspect_socket(socket) def self.inspect_socket(socket)
"#{socket.localhost}:#{socket.localport} -> #{socket.peerhost}:#{socket.peerport}" "#{socket.localhost}:#{socket.localport} -> #{socket.peerhost}:#{socket.peerport}"
end end


class MySocketEventHandler class MySocketEventHandler
Expand Down Expand Up @@ -339,7 +338,7 @@ def on_module_error(instance, exception)
end #FIDIUS end #FIDIUS


# This extends the PacketDispatcher from Rex # This extends the PacketDispatcher from Rex
# with Logging # with Logging
# Original Source is: lib/rex/post/meterpreter/packet_dispatcher.rb # Original Source is: lib/rex/post/meterpreter/packet_dispatcher.rb
module Rex::Post::Meterpreter::PacketDispatcher module Rex::Post::Meterpreter::PacketDispatcher
def send_packet(packet, completion_routine = nil, completion_param = nil) def send_packet(packet, completion_routine = nil, completion_param = nil)
Expand All @@ -362,7 +361,7 @@ def send_packet(packet, completion_routine = nil, completion_param = nil)
@finish = true @finish = true


# Reraise the error to the top-level caller # Reraise the error to the top-level caller
raise e raise e
end end
end end


Expand Down

0 comments on commit 722e3fe

Please sign in to comment.