Dear experts,
I am writting Session Fixation Audit Plugin,
but there is a problem I don't understand..

I copied 2 func : _isLoginForm( self, freq ), _getLoginFieldNames( self,
freq )
But,
  if data_container.getType( key ).lower() == 'password' <<  ERROR, because
data_container is now queryString ?????.. I don't under stand..

I've attached the files, and discribed what I've done..
Please have a look at line 188 ..
thank you very much


-- 
Best Regards,
Summer Nguyen .
'''
xss.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
from core.data.dc.form import form as form
# options
from core.data.options.option import option
from core.data.options.optionList import optionList

from core.controllers.basePlugin.baseAuditPlugin import baseAuditPlugin
from core.data.fuzzer.fuzzer import createMutants, createRandAlNum
from core.controllers.w3afException import w3afException

import core.data.kb.knowledgeBase as kb
import core.data.kb.vuln as vuln
import core.data.constants.severity as severity

import string



import re



class sessionfixation(baseAuditPlugin):
    '''
    Find cross site scripting vulnerabilities.
    @author: Summer Nguyen (summer0ngu...@gmail.com)
    Steps:
    1. Attacker get SSID
    2. Victim login use valid username and password ,
        If server provide new SSID => NO VULN
        otherwise => VULN
    
    '''

    def __init__(self):
        baseAuditPlugin.__init__(self)
        self._fuzzableRequests = []
        self._hasID = False       
        
        self._username = 'username'  ## Webmaster provide valid username and password to test the website
        self._password = 'password'
        self._SSID=''
        

        
        
    def audit(self, freq ):
        '''
        Tests an URL for XSS vulnerabilities.
        
        @param freq: A fuzzableRequest
        '''
        om.out.debug( 'Xss plugin is testing: ' + freq.getURL() )
        

        
        # Save it here, so I can check this URL after geting the SSID
        self._fuzzableRequests.append(freq)
        
       
        
        if self._hasID:  ## I have SSID of anomunous user ( Attacker)
            if self._isLoginForm(freq): ## Find Login form to login
                if self._hasSSID(freq, True):  ## True, it means I use password, I am a victim
                    print "NO VULN"             ## I login successfully, but the server provice a new SSID => No VULN
                else:
                    print "VULN"                ## The server don't provide another SSID
        else: ## I am an attacker, I am trying to get SSID of anonymous user
            if self._hasSSID(freq, False): ## False, it means I dont have password, I am an anonymous user
                self._hasID=True        ## WOW.. I have SSID now
                
                if self._isLoginForm(freq):     ## Check if this URL is a login form
                    if self._hasSSID(freq, True):
                        print "NO VULN"
                    else:
                        print "VULN"
                
                for freq in self._fuzzableRequests:  ## Check the URL that are saved above
                    if self._isLoginForm(freq):
                        if self._hasSSID(freq, True):
                            print "NO VULN"
                        else:
                            print "VULN"
                self._fuzzableRequests = [] 
            
                
    def _hasSSID( self, freq ,password):
        '''
        Generate TWO different response bodies that are the result of failed logins.
        
        The first result is for logins with filled user and password fields; the second
        one is for a filled user and a blank passwd.
        '''
        data_container = freq.getDc()
        user_field, passwd_field = self._getLoginFieldNames( freq )       
        

        if password: # I am victim, I login with my username, password
            data_container[ user_field ] = self._username   ## Valid Username, Password
            data_container[ passwd_field ] = self._password
                       
        freq.setDc( data_container )
        
        response = self._sendMutant( freq , analyze=False, grepResult=False )
        
        
        params=self._getSSIDparam()
        res2string=str(response.getHeaders()) ## convert to String
        
        if 'Set-Cookie' in res2string: ## There is Cookie param
            SSID=''            
            for param in params:
                num=string.find(res2string,param) 
                
                if num!= -1:
                    char =''
                    i=1
                    end=False
                    while not end:   ## Get the SSID value
                        char=res2string[num+len(param)+i]
                        if char!=';':
                            SSID+=char
                        else:
                            end=True
                        i=i+1
            
            if password:
                if SSID=='' or SSID==self._SSID:    ## Server don't provide new SSID => VULN
                    return False
                else:
                    return True                     
            else:
                if SSID=='':     
                    return False
                else:
                    self._SSID=SSID  
                    return True
                  
        
        return False
    
    
    def _isLoginForm( self, freq ):
        '''
        @return: True if this fuzzableRequest is a loginForm.
        '''
        passwd = 0
        text = 0
        other = 0
        
        data_container = freq.getDc()
        
        
        if   isinstance(data_container ,form ):  ## PROBLEM 1
            
            for key in data_container.keys():                    
                '''
                Please have a look these lines,
                Ithe problem is : 
                in the line PROBLEM 1 :  data_container is an instance of FORM..
                in the line PROBLEM 2: data_container is not an instance of FORM,
                                        so, I can't getType().   
                
                              
                
                NOTE : I copied these line from formAuthBrute.py 
                                 
                
                
                '''
                
                if data_container.getType( key ).lower() == 'password': ## PROBLEM 2
                    passwd += 1
                
                elif data_container.getType( key ).lower() == 'text':
                    text += 1
                
                else:
                    other += 1
                    
            if text == 1 and passwd == 1:
                return True

        return False
    
    def _getLoginFieldNames( self, freq ):
        '''
        @return: The names of the form fields where to input the user and the password.
        '''
        data_container = freq.getDc()
        user = passwd = ''
        
        for key in data_container.keys():              
            
            if data_container.getType( key ).lower() == 'password':
                passwd = key
            
            elif data_container.getType( key ).lower() == 'text':
                user = key
                
            
        return user, passwd
                
    
        
      
           
    
        
    def _analyzeResult( self, mutant, response ):
        '''
        Do we have a reflected XSS?
        
        @return: None, record all the results in the kb.
        '''
        pass
    
    
    
    def _getSSIDparam(self ):
        
        '''
        SSID parameters, Please add more parameters
        '''
        
        param=[]
        
        param.append('JSESSIONID')
        param.append('wordpress_test_cookie')
        
        
        
        return param 
  
        
    

    def getOptions( self ):
        '''
        @return: A list of option objects for this plugin.
        '''

        ol = optionList()

        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 OptionList: A dictionary with the options for the plugin.
        @return: No value is returned.
        '''
        pass
        
    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 finds Cross Site Scripting (XSS) vulnerabilities.
        
        Two configurable parameters exist:
            - checkStored
            - numberOfChecks
            
        To find XSS bugs the plugin will send a set of javascript strings to every parameter, and search for that input in
        the response. The parameter "checkStored" configures the plugin to store all data sent to the web application 
        and at the end, request all pages again searching for that input; the numberOfChecks determines how many
        javascript strings are sent to every injection point.
        '''
------------------------------------------------------------------------------
_______________________________________________
W3af-develop mailing list
W3af-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/w3af-develop

Reply via email to