Path: blob/master/sslstrip-work-2019/sslstrip/ServerConnectionFactory.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 logging19from twisted.internet.protocol import ClientFactory2021class ServerConnectionFactory(ClientFactory):2223def __init__(self, command, uri, postData, headers, client):24self.command = command25self.uri = uri26self.postData = postData27self.headers = headers28self.client = client2930def buildProtocol(self, addr):31return self.protocol(self.command, self.uri, self.postData, self.headers, self.client)3233def clientConnectionFailed(self, connector, reason):34logging.debug("Server connection failed.")3536destination = connector.getDestination()3738if (destination.port != 443):39logging.debug("Retrying via SSL")40self.client.proxyViaSSL(self.headers['host'], self.command, self.uri, self.postData, self.headers, 443)41else:42self.client.finish()43444546