/usr/share/w3af/plugins/discovery/phishtank.py is in w3af-console 1.0-rc3svn3489-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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | '''
phishtank.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.controllers.w3afException import w3afRunOnce, w3afException
import core.data.kb.knowledgeBase as kb
import core.data.kb.vuln as vuln
import core.data.constants.severity as severity
import core.data.parsers.urlParser as urlParser
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
import os.path
import socket
class phishtank(baseDiscoveryPlugin):
'''
Search the phishtank.com database to determine if your server is (or was) being used in phishing scams.
@author: Andres Riancho ( andres.riancho@gmail.com ) ; special thanks to http://www.phishtank.com/ !
'''
def __init__(self):
baseDiscoveryPlugin.__init__(self)
self._run = True
# Internal variables
self._fuzzable_requests = []
# User defines variable
self._phishtank_DB = 'plugins' + os.path.sep + 'discovery'
self._phishtank_DB += os.path.sep + 'phishtank' + os.path.sep + 'index.xml'
self._update_DB = False
def discover(self, fuzzableRequest ):
'''
Plugin entry point, perform all the work.
'''
if not self._run:
# This will remove the plugin from the discovery plugins to be runned.
raise w3afRunOnce()
else:
# Run one time
self._run = False
if self._update_DB:
self._do_update()
domain = urlParser.getDomain( fuzzableRequest.getURL() )
to_check_list = self._get_to_check( domain )
# I found some URLs, create fuzzable requests
phishtank_matches = self._is_in_phishtank( to_check_list )
for ptm in phishtank_matches:
response = self._urlOpener.GET( ptm.url )
self._fuzzable_requests.extend( self._createFuzzableRequests( response ) )
# Only create the vuln object once
if phishtank_matches:
v = vuln.vuln()
v.setURL( ptm.url )
v.setId( response.id )
v.setName( 'Phishing scam' )
v.setSeverity(severity.LOW)
desc = 'The URL: "' + ptm.url + '" seems to be involved in a phishing scam. Please see "'
desc += ptm.more_info_URL + '" for more info.'
v.setDesc( desc )
kb.kb.append( self, 'phishtank', v )
om.out.vulnerability( v.getDesc(), severity=v.getSeverity() )
return self._fuzzable_requests
def _get_to_check( self, domain ):
'''
@return: From the domain, get a list of FQDN, rootDomain and IP address.
'''
res = []
addrinfo = None
try:
addrinfo = socket.getaddrinfo( domain, 0)
except:
pass
else:
res.extend( [info[4][0] for info in addrinfo] )
fqdn = ''
try:
fqdn = socket.getfqdn( domain )
except:
pass
else:
res.append( fqdn )
rootDomain = ''
try:
rootDomain = urlParser.getRootDomain( domain )
except Exception, e:
om.out.debug( str(e) )
else:
res.append( rootDomain )
res = list( set( res ) )
return res
def _is_in_phishtank( self, to_check_list ):
'''
Reads the phishtank db and tries to match the entries on that db with the to_check_list
@return: A list with the sites to match against the phishtank db
'''
class phishTankMatch:
'''
Represents a phish tank match between the site I'm scanning and
something in the index.xml file.
'''
def __init__( self, url, more_info_URL ):
self.url = url
self.more_info_URL = more_info_URL
class phishtankHandler(ContentHandler):
'''
<entry>
<url><![CDATA[http://cbisis.be/.,/www.paypal.com/login/user-information/paypal.support/]]></url>
<phish_id>118884</phish_id>
<phish_detail_url><![CDATA[http://www.phishtank.com/phish_detail.php?phish_id=118884]]></phish_detail_url>
<submission>
<submission_time>2007-03-03T21:01:19+00:00</submission_time>
</submission>
<verification>
<verified>yes</verified>
<verification_time>2007-03-04T01:58:05+00:00</verification_time>
</verification>
<status>
<online>yes</online>
</status>
</entry>
'''
def __init__ (self, to_check_list):
self._to_check_list = to_check_list
self.inside_entry = False
self.inside_URL = False
self.inside_detail = False
self.matches = []
def startElement(self, name, attrs):
if name == 'entry':
self.inside_entry = True
elif name == 'url':
self.inside_URL = True
self.url = ""
elif name == 'phish_detail_url':
self.inside_detail = True
self.phish_detail_url = ""
return
def characters (self, ch):
if self.inside_URL:
self.url += ch
if self.inside_detail:
self.phish_detail_url += ch
def endElement(self, name):
if name == 'phish_detail_url':
self.inside_detail = False
if name == 'url':
self.inside_URL = False
if name == 'entry':
self.inside_entry = False
#
# Now I try to match the entry with an element in the to_check_list
#
phish_domain = urlParser.getDomain( self.url )
for url in self._to_check_list:
if url == phish_domain or phish_domain.endswith('.' + url ):
ptm = phishTankMatch( self.url, self.phish_detail_url )
self.matches.append( ptm )
file_handler = None
try:
file_handler = file( self._phishtank_DB )
except Exception, e:
raise w3afException('Failed to open phishtank database file: ' + self._phishtank_DB )
parser = make_parser()
curHandler = phishtankHandler( to_check_list )
parser.setContentHandler( curHandler )
om.out.debug( 'Starting the phishtank xml parsing. ' )
try:
parser.parse( file_handler )
except Exception, e:
om.out.debug( 'XML parsing error: ' + str(e) )
raise w3afException('phishtank database file is not a valid XML file.' )
om.out.debug( 'Finished xml parsing. ' )
return curHandler.matches
def setOptions( self, OptionList ):
self._phishtank_DB = OptionList['dbFile'].getValue()
self._update_DB = OptionList['updateDB'].getValue()
def getOptions( self ):
'''
@return: A list of option objects for this plugin.
'''
d1 = 'The path to the phishtank database file.'
o1 = option('dbFile', self._phishtank_DB, d1, 'string')
d2 = 'Update the local phishtank database.'
h2 = 'If True, the plugin will download the phishtank database'
h2 += ' from http://www.phishtank.com/ .'
o2 = option('updateDB', self._update_DB, d2, 'boolean', help=h2)
ol = optionList()
ol.add(o1)
ol.add(o2)
return ol
def _do_update(self):
'''
This method is called to update the database.
'''
file_handler = None
try:
file_handler = open( self._phishtank_DB, 'w' )
except:
raise w3afException('Failed to open file: ' + self._phishtank_DB )
msg = 'Updating the phishtank database, this will take some minutes'
msg += ' ( almost 7MB to download ).'
om.out.information( msg )
res = self._urlOpener.GET('http://data.phishtank.com/data/online-valid/')
om.out.information('Download complete, writing to the database file.')
try:
file_handler.write( res.getBody() )
file_handler.close()
except:
raise w3afException('Failed to write to file: ' + self._phishtank_DB )
else:
return True
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 searches the domain being tested in the phishtank database.
If your site is in this database the chances are that you were hacked and your server is now being
used in phishing attacks.
Two configurable parameters exist:
- dbFile
- updateDB
'''
|