This repository has been archived by the owner on Jan 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
session.py
executable file
·73 lines (64 loc) · 1.95 KB
/
session.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python
"""
Session Analyzer Module for Grabber v0.1
Copyright (C) 2006 - Romain Gaucher - http://rgaucher.info
"""
import sys,re,time,datetime
from grabber import getContentDirectURL_GET
sessions = {}
def normalize_whitespace(text):
return ' '.join(text.split())
def getDirectSessionID(currentURL, sid):
k = currentURL.find(sid)
if k > 0:
return currentURL[k+10:]
return None
def stripNoneASCII(output):
# should be somepthing to do that.. :/
newOutput = ""
for s in output:
try:
s = s.encode()
newOutput += s
except UnicodeDecodeError:
continue
return newOutput
regDate = re.compile(r'^Date: (.*)$', re.I)
def lookAtSessionID(url, sidName, regSession):
global sessions
handle = getContentDirectURL_GET(url,"")
if handle != None:
output = handle.read()
header = str(handle.info()).split('\n')
for h in header:
# extract date header information
if regDate.match(h):
out = regDate.search(h)
date = out.group(1)
# convert this date into the good GMT number
# ie time in seconds since 01/01/1970 00:00:00
gi = time.strptime(normalize_whitespace(date.replace('GMT','')), "%a, %d %b %Y %H:%M:%S")
gi = time.mktime(gi) - time.mktime(time.gmtime(0))
output = output.replace('\n','')
output = output.replace('\t','')
# print output[790:821]
output = stripNoneASCII(output)
if output.find(sidName) > 0:
if regSession.match(output):
out = regSession.search(output)
ssn = out.group(2)
if ssn != None:
if gi != None:
sessions[ssn] = gi
else:
sessions[ssn] = ''
def process(url, database, sidName):
regString = "(.*)" + sidName + "=([a-z|A-Z|0-9]+)(.*)"
regSession = re.compile(regString,re.I)
print url, sidName, regString
for k in range(0,1000):
lookAtSessionID(url, sidName, regSession)
o = open('results/sessions.txt','w')
for s in sessions:
o.write("%s, %s\n" % (s, sessions[s]))
o.close()