Class: Pentest::SqlProxy

Inherits:
Arproxy::Base
  • Object
show all
Defined in:
lib/pentest/sql_proxy.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSqlProxy

Returns a new instance of SqlProxy.



39
40
41
# File 'lib/pentest/sql_proxy.rb', line 39

def initialize
  @handler = nil
end

Class Method Details

.disable!(handler) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/pentest/sql_proxy.rb', line 29

def self.disable!(handler)
  Arproxy.configure do |config|
    config.adapter_class.class_eval do
      alias_method :exec_query, :exec_query_original
    end
  end
  Arproxy.proxy_chain.head.unregister_handler(handler)
  Arproxy.disable!
end

.enable!(handler) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pentest/sql_proxy.rb', line 8

def self.enable!(handler)
  Arproxy.configure do |config|
    config.use self
    config.adapter_class.class_eval do
      attr_accessor :handler
      @@handler = handler
      def exec_query_proxy(*args)
        sql, = args
        unless @@handler.nil?
          @@handler.call(sql)
        end
        self.exec_query_original(*args)
      end
      alias_method :exec_query_original, :exec_query
      alias_method :exec_query, :exec_query_proxy
    end
  end
  Arproxy.enable!
  Arproxy.proxy_chain.head.register_handler(handler)
end

Instance Method Details

#execute(*args) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/pentest/sql_proxy.rb', line 51

def execute(*args)
  sql, = args
  unless @handler.nil?
    @handler.call(sql)
  end
  super(*args)
end

#register_handler(handler) ⇒ Object



43
44
45
# File 'lib/pentest/sql_proxy.rb', line 43

def register_handler(handler)
  @handler = handler
end

#unregister_handler(handler) ⇒ Object



47
48
49
# File 'lib/pentest/sql_proxy.rb', line 47

def unregister_handler(handler)
  @handler = nil
end