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:

  • Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com>

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

Returns a new instance of Proxy.

Parameters:



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

Parameters:

  • function (Symbol)

    Javascript property/function.

  • arguments (Array)


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)

Returns Active Arachni::Browser::Javascript interface.

Returns:



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

def javascript
  @javascript
end

#stubStub (readonly)

Returns Stub interface for JS code.

Returns:

  • (Stub)

    Stub interface for JS code.



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

def stub
  @stub
end

Class Method Details

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

Returns:

  • (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

Parameters:

  • function (Symbol)

    Javascript property/function.

  • arguments (Array)


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

Returns `true` if the `name` property of the current object points to a function, `false` otherwise.

Parameters:

  • name (#to_sym)

    Function name to check.

Returns:

  • (Bool)

    `true` if the `name` property of the current object points to a function, `false` otherwise.



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

Returns Active JS-side object name – prefixed with the relevant `_token`.

Returns:

  • (String)

    Active JS-side object name – prefixed with the relevant `_token`.



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

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

#respond_to?(property) ⇒ Bool

Returns `true` if `self` of the JS object responds to `property`, `false` otherwise.

Parameters:

  • property (Symbol)

Returns:

  • (Bool)

    `true` if `self` of the JS object responds to `property`, `false` otherwise.



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

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