Skip to content

Readability improvements #4

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

Merged
merged 1 commit into from
Jan 6, 2014
Merged
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
64 changes: 21 additions & 43 deletions xssless.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env python

import sys
from bs4 import BeautifulSoup
import base64
import json

import os
import sys
import json
import base64
import binascii
import mimetypes

# Import burp export and return a list of decoded data
Expand All @@ -13,33 +15,32 @@ def get_burp_list(filename):
return []

with open(filename) as f:
filecontents = f.read()
filecontents = f.read()

archive = BeautifulSoup(filecontents, "xml")

requestList = []
item = archive.find_all('item')

for item in archive.find_all('item'):
tmpDict = {}
tmpDict['request'] = base64.b64decode(item.request.string)
tmpDict['response'] = base64.b64decode(item.response.string)
tmpDict['url'] = item.url.string
requestList.append(tmpDict)
del tmpDict

return requestList

# Return hex encoded string output of binary input
def payload_encode_file(input_file):
filecontents = open(input_file).read()
hue = filecontents.encode("hex")
with open(input_file) as f:
filecontents = f.read()
hue = binascii.hexlify(filecontents)
filecontents = '\\x' + '\\x'.join(hue[i:i+2] for i in xrange(0, len(hue), 2)) # Stackoverflow, because pythonistic
return filecontents

# Return hex encoded string output of binary input
def payload_encode_input(filecontents):
hue = filecontents.encode("hex")
hue = binascii.hexlify(filecontents)
filecontents = '\\x' + '\\x'.join(hue[i:i+2] for i in xrange(0, len(hue), 2)) # Stackoverflow, because pythonistic
return filecontents

Expand Down Expand Up @@ -71,18 +72,16 @@ def parse_request(input_var, url):
headerList = []
host = ""
for line in header_lines:
tmpList = line.split(": ")
key, value = line.split(": ", 1)
headerDict = {}
headerDict['Key'] = tmpList[0]
headerDict['Value'] = tmpList[1]
headerDict['Key'] = key
headerDict['Value'] = value

# Grab important values
if headerDict['Key'].lower() == "host":
host = headerDict['Value']

headerList.append(headerDict)
del headerDict
del tmpList

postisupload = False
fileboundary = ""
Expand Down Expand Up @@ -122,9 +121,6 @@ def parse_request(input_var, url):

tmp['body'] = sectionBody
bodyList.append(tmp)
del tmp
del sectionHeader
del sectionBody

else:
# Create a list of body values (check for JSON, etc)
Expand All @@ -133,14 +129,11 @@ def parse_request(input_var, url):
body_var_List = body_data.split("&")
body_var_List = filter(None, body_var_List)
for item in body_var_List:
tmpList = item.split("=")
key, value = item.split("=", 1)
bodyDict = {}
bodyDict['Key'] = tmpList[0]
bodyDict['Value'] = tmpList[1]
bodyDict['Key'] = key
bodyDict['Value'] = value
bodyList.append(bodyDict)
del tmpList
del bodyDict


# Returned dict, chocked full of useful information formatted nicely for your convienience!
returnDict = {}
Expand All @@ -165,9 +158,7 @@ def parse_response(input_var, url):
flags = []

# Split request into headers/body and parse header into list
request_parts = input_var.split("\r\n\r\n")
header_data = request_parts[0]
body_data = request_parts[1]
header_data, body_data = input_var.split("\r\n\r\n", 1)
header_lines = header_data.split("\r\n")
header_lines = filter(None, header_lines) # Filter any blank lines

Expand All @@ -181,17 +172,15 @@ def parse_response(input_var, url):
headerList = []
content_type = ""
for line in header_lines:
tmpList = line.split(": ")
key, value = line.split(": ", 1)
headerDict = {}
headerDict['Key'] = tmpList[0]
headerDict['Value'] = tmpList[1]
headerDict['Key'] = key
headerDict['Value'] = value

if headerDict['Key'].lower() == "Content-Type".lower():
content_type = headerDict['Value']

headerList.append(headerDict)
del headerDict
del tmpList

# Returned dict, chocked full of useful information formatted nicely for your convienience!
returnDict = {}
Expand Down Expand Up @@ -261,9 +250,7 @@ def xss_gen(requestList, settingsDict):
# Each request is done as a function that one requestion completion, calls the next function.
# The result is an unclobered browser and no race conditions! (Because cookies may need to be set, etc)

# Counter for function numbers
i = 0
for conv in requestList:
for i, conv in enumerate(requestList):
requestDict = parse_request(conv['request'], conv['url'])
responseDict = parse_response(conv['response'], conv['url']) # Currently unused, for future heuristics

Expand All @@ -290,9 +277,6 @@ def xss_gen(requestList, settingsDict):
multipart += 'Content-Disposition: form-data; name="' + item['name'] + '"; filename="' + item['filename'] + '"\\r\\n'
multipart += 'Content-Type: ' + content_type + '\\r\\n\\r\\n'
multipart += filecontents + '\\r\\n'

del filecontents
del content_type
else:
multipart += 'Content-Disposition: form-data; name="' + item['name'] + '"; filename="' + item['filename'] + '"\\r\\n'
multipart += 'Content-Type: ' + item['contenttype'] + '\\r\\n\\r\\n'
Expand Down Expand Up @@ -339,7 +323,6 @@ def xss_gen(requestList, settingsDict):

payload += " }\n"
payload += "\n"
i += 1

payload += "</script>"
return payload
Expand Down Expand Up @@ -389,7 +372,6 @@ def xss_gen(requestList, settingsDict):
tmpList[key] = value.replace("\n", "")
if len(tmpList):
settingsDict['parseList'] = tmpList
del tmpList
else:
print "Error, parse list not found!"
if "-f=" in option:
Expand All @@ -409,12 +391,8 @@ def xss_gen(requestList, settingsDict):
print "Error while parsing file " + fileuploadlist + " on line #" + str(key)
print " ->'" + value.replace("\n", "") + "'"
sys.exit()
del rowparts
if tmpDict:
settingsDict['fileDict'] = tmpDict

del tmpDict
del fileuploadlinesList
else:
print "Input filelist not found!"
sys.exit()
Expand Down