2019-03-02 05:43:02 +05:30
|
|
|
import re
|
2019-03-03 16:17:06 +05:30
|
|
|
import json
|
2018-11-09 20:32:08 +05:30
|
|
|
import string
|
|
|
|
|
import random
|
|
|
|
|
import requests
|
2019-04-12 18:03:00 +05:30
|
|
|
|
|
|
|
|
import core.config
|
2018-11-09 20:32:08 +05:30
|
|
|
from core.colors import bad
|
|
|
|
|
|
2019-04-12 18:03:00 +05:30
|
|
|
def log(data, mode='', show=False):
|
|
|
|
|
suffix = '\n'
|
|
|
|
|
if mode == 'run':
|
|
|
|
|
suffix = '\r'
|
|
|
|
|
if not core.config.globalVariables['url_file']:
|
|
|
|
|
print (data, end=suffix)
|
|
|
|
|
else:
|
|
|
|
|
if show:
|
|
|
|
|
print (data, end=suffix)
|
|
|
|
|
|
|
|
|
|
def extractHeaders(headers):
|
2019-04-12 18:12:15 +05:30
|
|
|
headers = headers.replace('\\n', '\n')
|
|
|
|
|
sorted_headers = {}
|
2019-04-12 18:03:00 +05:30
|
|
|
matches = re.findall(r'(.*):\s(.*)', headers)
|
|
|
|
|
for match in matches:
|
|
|
|
|
header = match[0]
|
|
|
|
|
value = match[1]
|
|
|
|
|
try:
|
|
|
|
|
if value[-1] == ',':
|
|
|
|
|
value = value[:-1]
|
2019-04-12 18:12:15 +05:30
|
|
|
sorted_headers[header] = value
|
2019-04-12 18:03:00 +05:30
|
|
|
except IndexError:
|
|
|
|
|
pass
|
2019-04-12 18:12:15 +05:30
|
|
|
return sorted_headers
|
2019-04-12 18:03:00 +05:30
|
|
|
|
2019-03-02 07:30:42 +05:30
|
|
|
def unityExtracter(arrayOfArrays, usable):
|
2019-03-03 16:17:06 +05:30
|
|
|
"extracts the value from single valued list from a list of lists"
|
2019-03-02 07:30:42 +05:30
|
|
|
remainingArray = []
|
|
|
|
|
for array in arrayOfArrays:
|
|
|
|
|
if len(array) == 1:
|
|
|
|
|
usable.append(array[0])
|
|
|
|
|
else:
|
|
|
|
|
remainingArray.append(array)
|
|
|
|
|
return remainingArray
|
|
|
|
|
|
2019-03-02 05:43:02 +05:30
|
|
|
def slicer(array, n=2):
|
2019-03-03 16:17:06 +05:30
|
|
|
"divides a list into n parts"
|
2019-03-02 05:43:02 +05:30
|
|
|
k, m = divmod(len(array), n)
|
2019-03-02 07:30:42 +05:30
|
|
|
return list(array[i * k + min(i, m):(i + 1) * k + min(i + 1, m)] for i in range(n))
|
2019-03-02 05:43:02 +05:30
|
|
|
|
2019-03-03 16:17:06 +05:30
|
|
|
def joiner(array, include):
|
|
|
|
|
"converts a list of parameters into parameter and value pair"
|
2019-03-02 05:43:02 +05:30
|
|
|
params = {}
|
|
|
|
|
for element in array:
|
|
|
|
|
params[element] = randomString(6)
|
2019-03-03 16:17:06 +05:30
|
|
|
params.update(include)
|
2019-03-02 05:43:02 +05:30
|
|
|
return params
|
|
|
|
|
|
2018-11-09 20:32:08 +05:30
|
|
|
def stabilize(url):
|
2019-03-03 16:17:06 +05:30
|
|
|
"picks up the best suiting protocol if not present already"
|
2018-11-09 20:32:08 +05:30
|
|
|
if 'http' not in url:
|
|
|
|
|
try:
|
|
|
|
|
requests.get('http://%s' % url) # Makes request to the target with http schema
|
|
|
|
|
url = 'http://%s' % url
|
|
|
|
|
except: # if it fails, maybe the target uses https schema
|
|
|
|
|
url = 'https://%s' % url
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
requests.get(url) # Makes request to the target
|
|
|
|
|
except Exception as e: # if it fails, the target is unreachable
|
|
|
|
|
if 'ssl' in str(e).lower():
|
2018-11-10 05:29:33 +05:30
|
|
|
pass
|
2018-11-09 20:32:08 +05:30
|
|
|
else:
|
|
|
|
|
print ('%s Unable to connect to the target.' % bad)
|
|
|
|
|
quit()
|
|
|
|
|
return url
|
|
|
|
|
|
2019-03-02 05:43:02 +05:30
|
|
|
def removeTags(html):
|
2019-03-03 16:17:06 +05:30
|
|
|
"removes all the html from a webpage source"
|
2019-03-02 05:43:02 +05:30
|
|
|
return re.sub(r'(?s)<.*?>', '', html)
|
|
|
|
|
|
|
|
|
|
def lineComparer(response1, response2):
|
2019-03-03 16:17:06 +05:30
|
|
|
"compares two webpage and finds the non-matching lines"
|
2019-03-02 05:43:02 +05:30
|
|
|
response1 = response1.split('\n')
|
|
|
|
|
response2 = response2.split('\n')
|
|
|
|
|
num = 0
|
|
|
|
|
dynamicLines = []
|
|
|
|
|
for line1, line2 in zip(response1, response2):
|
|
|
|
|
if line1 != line2:
|
|
|
|
|
dynamicLines.append(num)
|
|
|
|
|
num += 1
|
|
|
|
|
return dynamicLines
|
|
|
|
|
|
2019-03-03 16:17:06 +05:30
|
|
|
def randomString(n):
|
|
|
|
|
"generates a random string of length n"
|
|
|
|
|
return ''.join(random.choice(string.ascii_lowercase) for i in range(n))
|
|
|
|
|
|
|
|
|
|
def e(string):
|
|
|
|
|
"utf encodes a string"
|
|
|
|
|
return string.encode('utf-8')
|
|
|
|
|
|
|
|
|
|
def d(string):
|
|
|
|
|
"utf decodes a string"
|
|
|
|
|
return string.decode('utf-8')
|
2018-11-09 20:32:08 +05:30
|
|
|
|
|
|
|
|
def flattenParams(params):
|
|
|
|
|
flatted = []
|
|
|
|
|
for name, value in params.items():
|
|
|
|
|
flatted.append(name + '=' + value)
|
|
|
|
|
return '?' + '&'.join(flatted)
|
|
|
|
|
|
2019-03-03 16:17:06 +05:30
|
|
|
def getParams(data):
|
|
|
|
|
params = {}
|
|
|
|
|
try:
|
|
|
|
|
params = json.loads(str(data).replace('\'', '"'))
|
|
|
|
|
return params
|
|
|
|
|
except json.decoder.JSONDecodeError:
|
|
|
|
|
if data.startswith('?'):
|
|
|
|
|
data = data[1:]
|
|
|
|
|
parts = data.split('&')
|
|
|
|
|
for part in parts:
|
|
|
|
|
each = part.split('=')
|
|
|
|
|
try:
|
|
|
|
|
params[each[0]] = each[1]
|
|
|
|
|
except IndexError:
|
|
|
|
|
params = None
|
|
|
|
|
return params
|