Module: Arachni::Module::Utilities

Overview

Utilities class

Includes some useful methods for the system, the modules etc…

@author: Tasos “Zapotek” Laskos

<[email protected]>
<[email protected]>

@version: 0.1.1

Instance Method Summary collapse

Instance Method Details

#exception_jail(&block) ⇒ Object

Wraps the “block” in exception handling code and runs it.

Parameters:

  • (Block)


95
96
97
98
99
100
101
102
103
# File 'lib/module/utilities.rb', line 95

def exception_jail( &block )
    begin
        block.call
    rescue Exception => e
        print_error( e.to_s )
        print_debug_backtrace( e )
        raise e
    end
end

#get_path(url) ⇒ String

Gets path from URL

Parameters:

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/module/utilities.rb', line 34

def get_path( url )

    uri  = URI( URI.escape( url ) )
    path = uri.path

    if !File.extname( path ).empty?
        path = File.dirname( path )
    end

    path << '/' if path[-1] != '/'
    return uri.scheme + "://" + uri.host + path
end

#normalize_url(url) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/module/utilities.rb', line 51

def normalize_url( url )
    begin
        return URI.encode( URI.decode( url.to_s ) ).to_s.gsub( '[', '%5B' ).gsub( ']', '%5D' )
    rescue
        begin
            return URI.encode( URI.decode( url.to_s ) ).to_s
        rescue
            return url
        end
    end
end

#read_file(filename, &block) ⇒ Object

Gets module data files from ‘modules//[modname]/

Parameters:

  • filename (String)

    filename, without the path

  • the (Block)

    block to be passed each line as it’s read



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/module/utilities.rb', line 69

def read_file( filename, &block )

    # the path of the module that called us
    mod_path = block.source_location[0]

    # the name of the module that called us
    mod_name = File.basename( mod_path, ".rb")

    # the path to the module's data file directory
    path    = File.expand_path( File.dirname( mod_path ) ) +
        '/' + mod_name + '/'

    file = File.open( path + '/' + filename ).each {
        |line|
        yield line.strip
    }

    file.close

end

#seedObject



47
48
49
# File 'lib/module/utilities.rb', line 47

def seed
    @@seed ||= Digest::SHA2.hexdigest( srand( 1000 ).to_s )
end