Class: Arachni::Modules::Recon::BackupFiles

Inherits:
Arachni::Module::Base show all
Includes:
Arachni::Module::Registrar, Arachni::UI::Output
Defined in:
modules/recon/backup_files.rb

Overview

Backup file discovery module.

Appends common backup extesions to the filename of the page under audit
and checks for its existence.

@author: Anastasios “Zapotek” Laskos

                                     <tasos.laskos@gmail.com>
                                     <zapotek@segfault.gr>

@version: $Rev: 385 $

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Arachni::Module::Registrar

#add_storage, #get_storage, #get_store, included, #register_results

Methods included from Arachni::UI::Output

#debug!, #debug?, #only_positives!, #only_positives?, #print_debug, #print_debug_backtrace, #print_debug_pp, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #verbose!, #verbose?

Methods inherited from Arachni::Module::Base

#clean_up, deps, #get_cookie_simple, #get_cookies, #get_cookies_simple, #get_data_file, #get_form_simple, #get_forms, #get_forms_simple, #get_links, #get_links_simple, #get_request_headers, #get_response_headers, #prepare

Methods included from Arachni::Module::Auditor

#audit_cookies, #audit_forms, #audit_headers, #audit_links, #get_matches, #inject_each_var

Methods included from Arachni::Module::Trainer

#train

Methods included from Arachni::Module::ElementDB

#init_cookies, #init_forms, #init_links, #update_cookies, #update_forms, #update_links, #work_on_cookies, #work_on_forms, #work_on_links

Constructor Details

- (BackupFiles) initialize(page)

A new instance of BackupFiles



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'modules/recon/backup_files.rb', line 38

def initialize( page )
    super( page )

    @__backup_ext = [
        '%s.old',
        '%s.OLD',
        '%s.bak',
        '%s.BAK',
        '%s.zip',
        '%s.ZIP',
        '%s.gz',
        '%s.tar.gz',
        '%s.temp',
        '%s.save',
        '%s.orig',
        '%s.backup',
        '%s.000',
        '%s~',
        '%s~1',
        '%s.cs',
        '%s.pas',
        '%s.vb',
        '%s.java',
        '%s.class',
        '%s.sav',
        '%s.saved',
        '%s.rar',
        '%s.src',
        '%s.tmp',
        '%s.inc',
        '%s.copy',
        '%s1',
        'Copy%%20of%%20%s'
    ]
    
    # our results hash
    @results = []
end

Class Method Details

+ (Object) info



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'modules/recon/backup_files.rb', line 121

def self.info
    {
        'Name'           => 'BackupFiles',
        'Description'    => %q{Tries to find sensitive backup files.},
        'Elements'       => [ ],
        'Author'         => 'zapotek',
        'Version'        => '$Rev: 385 $',
        'References'     => {},
        'Targets'        => { 'Generic' => 'all' },
            
        'Vulnerability'   => {
            'Name'        => %q{A backup file exists on the server.},
            'Description' => %q{},
            'CWE'         => '530',
            'Severity'    => Vulnerability::Severity::HIGH,
            'CVSSV2'       => '',
            'Remedy_Guidance'    => '',
            'Remedy_Code' => '',
        }

    }
end

Instance Method Details

- (Object) __get_path(url)



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'modules/recon/backup_files.rb', line 144

def __get_path( url )
  
    splits = []
    tmp = ''
    
    url.each_char {
        |c|
        if( c != '/' )
            tmp += c
        else
            splits << tmp
            tmp = ''
        end
    }
    
    if( !tmp =~ /\./ )
      splits << tmp
    end
    
    return splits.join( "/" ) + '/'
end

- (Object) __log_results(res, filename, url)



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'modules/recon/backup_files.rb', line 166

def __log_results( res, filename, url )
    
    # append the result to the results hash
    @results << Vulnerability.new( {
        'var'          => 'n/a',
        'url'          => url,
        'injected'     => filename,
        'id'           => filename,
        'regexp'       => 'n/a',
        'regexp_match' => 'n/a',
        'elem'         => Vulnerability::Element::LINK,
        'response'     => res.body,
        'headers'      => {
            'request'    => 'n/a',
            'response'   => 'n/a',    
        }
    }.merge( self.class.info ) )
            
    # inform the user that we have a match
    print_ok( self.class.info['Name'] +
        " named #{filename} at\t" + url )
end

- (Object) run



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'modules/recon/backup_files.rb', line 77

def run( )

    # ugly crap but it works, as far as I can tell...
    path     = __get_path( @page.url )
    regex    = path + '(.*)'
    
    filename = @page.url.match( Regexp.new( regex ) )
    filename = filename[1].gsub( /\?(.*)/, '' ) 
    
    if( filename.empty? )
        print_debug( self.class.info['Name'] + ' is backing out. ' + 
          'Can\'t extract filename from url: ' + @page.url )
        return
    end
    
    @__backup_ext.each {
        |ext|
        
        #
        # Test for the existance of the file + extension.
        #
        # We're not worrying about its contents, the Trainer will
        # analyze it and if it's HTML it'll extract any new attack vectors.
        #
        
        file = ext % filename # Example: index.php.bak
        url  = path + file
        res  = @http.get( url )

        __log_results( res, file, url ) if( res.code == "200" )
        
        file = ext % filename.gsub( /\.(.*)/, '' ) # Example: index.bak
        url  = path + file
        res  = @http.get( url )
        
        __log_results( res, file, url ) if( res.code == "200" )
    }

    
    # register our results with the system
    register_results( @results )
end