Class: Arachni::Browser::Javascript::Proxy

Inherits:
BasicObject
Defined in:
lib/arachni/browser/javascript/proxy.rb,
lib/arachni/browser/javascript/proxy/stub.rb

Overview

Note:

Extends ‘BasicObject` because we don’t want any baggage to avoid method-name clashes with the Javascript-side objects.

Provides a proxy to a Javascript object.

Author:

Direct Known Subclasses

DOMMonitor, TaintTracer

Defined Under Namespace

Classes: Stub

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(javascript, object) ⇒ Proxy



33
34
35
36
37
# File 'lib/arachni/browser/javascript/proxy.rb', line 33

def initialize( javascript, object )
    @javascript = javascript
    @object     = object
    @stub       = Stub.new( self )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject



61
62
63
# File 'lib/arachni/browser/javascript/proxy.rb', line 61

def call( function, *arguments )
    @javascript.run_without_elements "return #{stub.write( function, *arguments )}"
end

Instance Attribute Details

#javascriptJavascript (readonly)



27
28
29
# File 'lib/arachni/browser/javascript/proxy.rb', line 27

def javascript
  @javascript
end

#stubStub (readonly)



23
24
25
# File 'lib/arachni/browser/javascript/proxy.rb', line 23

def stub
  @stub
end

Class Method Details

.function?(env, object, name) ⇒ Boolean



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/arachni/browser/javascript/proxy.rb', line 76

def self.function?( env, object, name )
    mutex.synchronize do
        @isFunction ||= {}
        key = "#{object}.#{name}".hash

        return @isFunction[key] if @isFunction.include?( key )

        if name.to_s.end_with? '='
            name = name.to_s
            return @isFunction[key] = env.run(
                "return ('#{name[0...-1]}' in #{object})"
            )
        end

        @isFunction[key] = env.run(
            "return Object.prototype.toString.call( #{object}." <<
                "#{name} ) == '[object Function]'"
        )
    end
end

.mutexObject



96
97
98
# File 'lib/arachni/browser/javascript/proxy.rb', line 96

def self.mutex
    @mutex ||= ::Mutex.new
end

Instance Method Details

#call(function, *arguments) ⇒ Object Also known as: method_missing



58
59
60
# File 'lib/arachni/browser/javascript/proxy.rb', line 58

def call( function, *arguments )
    @javascript.run_without_elements "return #{stub.write( function, *arguments )}"
end

#classObject



72
73
74
# File 'lib/arachni/browser/javascript/proxy.rb', line 72

def class
    Proxy
end

#function?(name) ⇒ Bool



45
46
47
# File 'lib/arachni/browser/javascript/proxy.rb', line 45

def function?( name )
    self.class.function?( @javascript, js_object, name )
end

#js_objectString



51
52
53
# File 'lib/arachni/browser/javascript/proxy.rb', line 51

def js_object
    "_#{@javascript.token}#{@object}"
end

#respond_to?(property) ⇒ Bool



68
69
70
# File 'lib/arachni/browser/javascript/proxy.rb', line 68

def respond_to?( property )
    stub.respond_to?( property )
end