Skip to content

Instantly share code, notes, and snippets.

@4k1
Created May 13, 2018 19:52
Show Gist options
  • Save 4k1/3ffba860eaee8667ef6bacfba0c7a84f to your computer and use it in GitHub Desktop.
Save 4k1/3ffba860eaee8667ef6bacfba0c7a84f to your computer and use it in GitHub Desktop.
Calculate Session Identifier entropy with Claude Shannon formula.
# calc_entropy.py
# Calculate Session Identifier entropy with Claude Shannon formula.
# https://github.com/4k1
import math
import sys
import time
import urllib.request
# Check params
if (len(sys.argv) != 3):
print ('Usage: python3 %s url cookie' % sys.argv[0])
quit()
p_url = sys.argv[1]
p_target = sys.argv[2]
# Initialize
charlist = []
maxlength = 0
def addcharlist(cl, v):
ncl = list(set(cl + list(v)))
return ncl
# SessionID collection
print ("[ ] Collecting " + p_target + "...")
for i in range(0, 10000):
time.sleep(0.1)
headers = { "User-Agent" : "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)" } #
req = urllib.request.Request(p_url, None, headers)
response = urllib.request.urlopen(req)
for h, v in response.headers.items():
if h.lower() == "set-cookie":
r = v.split(';')[0].strip()
n = r.find('=')
if p_target == r[:n]:
charlist = addcharlist(charlist, r[n+1:])
if len(r[n+1:]) > maxlength:
maxlength = len(r[n+1:])
break
print ("[+] Collected.")
# Calculation
fb = len(charlist)
fl = maxlength
fbl = math.pow(fb, fl)
fH = math.log2(fbl)
# Report
print (" Length : " + str(fl))
print (" Charlist : " + str(fb))
print (" Strength : " + str(fH) + " bit(s).")
print ("[+] Ok.")
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment