Hey,

I've extended the importResult plugin to parse burp logs for input since I often use burp when reviewing applications. I've also added the ability to supply a cookie value for the requests. Right now the code is real simple, but take a look and let me know what you think.

- Jon

'''
importResults.py

Copyright 2006 Andres Riancho

This file is part of w3af, w3af.sourceforge.net .

w3af is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.

w3af is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with w3af; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

'''

import core.controllers.outputManager as om

# options
from core.data.options.option import option
from core.data.options.optionList import optionList

from core.controllers.basePlugin.baseDiscoveryPlugin import baseDiscoveryPlugin
from core.data.request.frFactory import createFuzzableRequestRaw
from core.controllers.w3afException import w3afRunOnce
import re


class importResults(baseDiscoveryPlugin):
    '''
    Import URLs found by other tools.
    @author: Andres Riancho ( andres.rian...@gmail.com )
    '''
    def __init__(self):
        baseDiscoveryPlugin.__init__(self)

        # Internal variables
        self._exec = True
        
        # User configured parameters
        self._input_file = ''
        self._burp_log = ''
        self._host = ''
        self._cookie = ''
       
    def discover(self, fuzzableRequest ):
        '''
        Read the input file, and create the fuzzableRequests based on that information.
        
        @parameter fuzzableRequest: A fuzzableRequest instance that contains
                                    (among other things) the URL to test. It ain't used.
        '''
        if not self._exec:
            # This will remove the plugin from the discovery plugins to be runned.
            raise w3afRunOnce()

        else:
            self._exec = False
            res = []

            if self._input_file != '':
                try:
                    file_handler = file( self._input_file )
                except Exception, e:
                    msg = 'An error was found while trying to read the input file: "'
                    msg += str(e) + '".'
                    om.out.error( msg )
                else:
                    for line in file_handler:
                        obj = self._obj_from_file( line.strip() )
                        if obj:
                            res.append( obj )
               
                           
            elif self._burp_log != '':
                try:
                    file_handler = file( self._burp_log )
                except Exception, e:
                    msg = 'An error was found while trying to read the burp log: "'
                    msg += str(e) + '".'
                    om.out.error( msg )
                else:
                    obj = self._obj_from_burp( file_handler )
                    if obj:
                        res = obj
            
        return res
    
    def _obj_from_file( self, csv_line ):
        '''
        @return: A fuzzableRequest based on the csv_line.
        '''
        try:
            method, uri, postdata = csv_line.split(',',2)
        except ValueError, value_error:
            msg = 'The file format is incorrect, an error was found while parsing: "'
            msg += csv_line + '". Exception: "' + str(value_error) + '".'
            om.out.error( msg )
        else:
            # Create the obj based on the information
            headers = {}
            if self._cookie != '':
                headers['cookie'] = self._cookie
            return createFuzzableRequestRaw( method, uri, postdata, headers)
            

    def _obj_from_burp( self, burpfile ):
        inpost = 0
        inpostdata = 0
        url = ''
        postdata = ''
        obj = []
        headers = {}
        if self._cookie != '':
            headers['cookie'] = self._cookie
        
        for line in burpfile:
            if(line.startswith("GET")):
                p = re.compile( ' HTTP/[0-9]+.[0-9]+')
                res = p.sub( '', line)
                res = res.replace('GET ','')
                #no images
                if not (re.search('(.gif|.png|.jpg|.bmp)',res)):
                    url = res.strip()
                    #print "GET," + url + ","
                    obj.append(createFuzzableRequestRaw( 'GET', self._host + url, '', headers ))
            if(line.startswith("POST")):
                 inpost = 1
                 p = re.compile( ' HTTP/[0-9]+.[0-9]+')
                 res = p.sub( '', line)
                 res = res.replace('POST ','')
                 url = res.strip()
            if (inpostdata == 1):
                 inpostdata = 0;
                 inpost = 0;
                 #print "POST," + url + "," + line.strip()
                 obj.append(createFuzzableRequestRaw( 'POST', self._host + url, line.strip(), headers ))
            if (inpost == 1 and line == '\r\n'):
                 inpostdata = 1
        return obj
    
    def getOptions( self ):
        '''
        @return: A list of option objects for this plugin.
        '''
        d1 = 'Define the input file from which to create the fuzzable requests'
        h1 = 'The input file is comma separated and holds the following data:'
        h1 += ' HTTP-METHOD,URI,POSTDATA'
        o1 = option('input_file', self._input_file, d1, 'string', help=h1)
        
        d2 = 'Define the burp log from which to create the fuzzable requests'
        h2 = 'Standard burp proxy log file'
        o2 = option('burp_log', self._burp_log, d2, 'string', help=h2)
        
        d3 = 'Host'
        h3 = 'Host'
        o3 = option('host', self._host, d3, 'string', help=h3)
        
        d4 = 'Cookie'
        h4 = 'Cookies to use'
        o4 = option('cookie', self._cookie, d4, 'string', help=h4)
        
        ol = optionList()
        ol.add(o1)
        ol.add(o2)
        ol.add(o3)
        ol.add(o4)
        return ol
        
    def setOptions( self, optionsMap ):
        '''
        This method sets all the options that are configured using the user interface 
        generated by the framework using the result of getOptions().
        
        @parameter optionsMap: A dictionary with the options for the plugin.
        @return: No value is returned.
        ''' 
        self._input_file = optionsMap['input_file'].getValue()
        self._burp_log = optionsMap['burp_log'].getValue()
        self._host = optionsMap['host'].getValue()
        self._cookie = optionsMap['cookie'].getValue()
        
    def getPluginDeps( self ):
        '''
        @return: A list with the names of the plugins that should be runned before the
        current one.
        '''
        return []
    
    def getLongDesc( self ):
        '''
        @return: A DETAILED description of the plugin functions and features.
        '''
        return '''
        This plugin serves as an entry point for the results of other tools that search for URLs.
        The plugin reads an input file that is comma separated and holds the following data:
        HTTP-METHOD,URI,POSTDATA.
        
        Two configurable parameter exists:
            - input_file
            - burp input
        '''

------------------------------------------------------------------------------
_______________________________________________
W3af-develop mailing list
W3af-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/w3af-develop

Reply via email to