/usr/share/w3af/plugins/grep/hashFind.py is in w3af-console 1.1svn5547-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 76 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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | '''
hashFind.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.baseGrepPlugin import baseGrepPlugin
import core.data.kb.knowledgeBase as kb
import core.data.kb.info as info
from core.data.bloomfilter.bloomfilter import scalable_bloomfilter
import re
class hashFind(baseGrepPlugin):
'''
Identify hashes in HTTP responses.
@author: Andres Riancho ( andres.riancho@gmail.com )
'''
def __init__(self):
baseGrepPlugin.__init__(self)
self._already_reported = scalable_bloomfilter()
# regex to split between words
self._split_re = re.compile('[^\w]')
def grep(self, request, response):
'''
Plugin entry point, identify hashes in the HTTP response.
@parameter request: The HTTP request object.
@parameter response: The HTTP response object
@return: None
'''
# I know that by doing this I loose the chance of finding hashes in PDF files, but...
# This is much faster
if response.is_text_or_html():
body = response.getBody()
splitted_body = self._split_re.split(body)
for possible_hash in splitted_body:
# This is a performance enhancement that cuts the execution
# time of this plugin in half.
if len(possible_hash) > 31:
hash_type = self._get_hash_type( possible_hash )
if hash_type:
possible_hash = possible_hash.lower()
if self._has_hash_distribution( possible_hash ):
if (possible_hash, response.getURL()) not in self._already_reported:
i = info.info()
i.setPluginName(self.getName())
i.setName( hash_type + 'hash in HTML content')
i.setURL( response.getURL() )
i.addToHighlight(possible_hash)
i.setId( response.id )
msg = 'The URL: "'+ response.getURL() + '" returned a response that may'
msg += ' contain a "' + hash_type + '" hash. The hash is: "'+ possible_hash
msg += '". This is uncommon and requires human verification.'
i.setDesc( msg )
kb.kb.append( self, 'hashFind', i )
self._already_reported.add( (possible_hash, response.getURL()) )
def _has_hash_distribution( self, possible_hash ):
'''
@parameter possible_hash: A string that may be a hash.
@return: True if the possible_hash has an equal (aprox.) distribution
of numbers and letters and only has hex characters (0-9, a-f)
>>> p = hashFind()
>>> p._has_hash_distribution( 'cdf13c6f85b216a18665e7bba74cc1a7' )
True
>>> p._has_hash_distribution( 'AB_Halloween_Wallpaper_1920x1080' )
False
# Note the "h" at the beginning
>>> p._has_hash_distribution( 'hdf13c6f85b216a18665e7bba74cc1a7' )
False
'''
numbers = 0
letters = 0
for char in possible_hash:
if char.isdigit():
numbers += 1
elif char in 'abcdef':
letters += 1
else:
return False
if numbers in range( letters - len(possible_hash) / 2 , letters + len(possible_hash) / 2 ):
# Seems to be a hash, let's make a final test to avoid false positives with
# strings like:
# 2222222222222222222aaaaaaaaaaaaa
is_hash = True
for char in possible_hash:
if possible_hash.count(char) > len(possible_hash) / 5:
is_hash = False
break
return is_hash
else:
return False
def _get_hash_type( self, possible_hash ):
'''
@parameter possible_hash: A string that may be a hash.
@return: The hash type if the string seems to be a md5 / sha1 hash.
None otherwise.
'''
# FIXME: Add more here!
if len( possible_hash ) == 32:
return 'MD5'
elif len( possible_hash ) == 40:
return 'SHA1'
else:
return None
def setOptions( self, OptionList ):
pass
def getOptions( self ):
'''
@return: A list of option objects for this plugin.
'''
ol = optionList()
return ol
def end(self):
'''
This method is called when the plugin wont be used anymore.
'''
self.printUniq( kb.kb.getData( 'hashFind', 'hashFind' ), None )
def getPluginDeps( self ):
'''
@return: A list with the names of the plugins that should be run before the
current one.
'''
return []
def getLongDesc( self ):
'''
@return: A DETAILED description of the plugin functions and features.
'''
return '''
This plugin identifies hashes in HTTP responses.
'''
|