Path: blob/master/sslstrip-work-2019/sslstrip/URLMonitor.py
1306 views
# Copyright (c) 2004-2009 Moxie Marlinspike1#2# This program is free software; you can redistribute it and/or3# modify it under the terms of the GNU General Public License as4# published by the Free Software Foundation; either version 3 of the5# License, or (at your option) any later version.6#7# This program is distributed in the hope that it will be useful, but8# WITHOUT ANY WARRANTY; without even the implied warranty of9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU10# General Public License for more details.11#12# You should have received a copy of the GNU General Public License13# along with this program; if not, write to the Free Software14# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-130715# USA16#1718import re1920class URLMonitor:2122'''23The URL monitor maintains a set of (client, url) tuples that correspond to requests which the24server is expecting over SSL. It also keeps track of secure favicon urls.25'''2627# Start the arms race, and end up here...28javascriptTrickery = [re.compile("http://.+\.etrade\.com/javascript/omntr/tc_targeting\.html")]29_instance = None3031def __init__(self):32self.strippedURLs = set()33self.strippedURLPorts = {}34self.faviconReplacement = False3536def isSecureLink(self, client, url):37for expression in URLMonitor.javascriptTrickery:38if (re.match(expression, url)):39return True4041return (client,url) in self.strippedURLs4243def getSecurePort(self, client, url):44if (client,url) in self.strippedURLs:45return self.strippedURLPorts[(client,url)]46else:47return 4434849def addSecureLink(self, client, url):50methodIndex = url.find("//") + 251method = url[0:methodIndex]5253pathIndex = url.find("/", methodIndex)54host = url[methodIndex:pathIndex]55path = url[pathIndex:]5657port = 44358portIndex = host.find(":")5960if (portIndex != -1):61host = host[0:portIndex]62port = host[portIndex+1:]63if len(port) == 0:64port = 4436566url = method + host + path6768self.strippedURLs.add((client, url))69self.strippedURLPorts[(client, url)] = int(port)7071def setFaviconSpoofing(self, faviconSpoofing):72self.faviconSpoofing = faviconSpoofing7374def isFaviconSpoofing(self):75return self.faviconSpoofing7677def isSecureFavicon(self, client, url):78return ((self.faviconSpoofing == True) and (url.find("favicon-x-favicon-x.ico") != -1))7980def getInstance():81if URLMonitor._instance == None:82URLMonitor._instance = URLMonitor()8384return URLMonitor._instance8586getInstance = staticmethod(getInstance)878889