Updated websocketproxy to support Cookies

This commit is contained in:
Tobia Zanarella 2017-11-14 09:58:02 +01:00
parent 0f66017f6f
commit 4ac567670e
1 changed files with 25 additions and 6 deletions

19
websockify/websocketproxy.py Normal file → Executable file
View File

@ -140,7 +140,22 @@ Traffic Legend:
# The files in targets contain the lines # The files in targets contain the lines
# in the form of token: host:port # in the form of token: host:port
token = ''
# Extract the token parameter from cookie
if 'Cookie' in self.headers:
cookiestr = self.headers['Cookie']
cookiestr.replace( 'Cookie: ', '', 1 )
cookies = cookiestr.split('; ')
for cookie in cookies:
cookie = cookie.split('=')
if 'token' in cookie[0]:
token = cookie[1]
break
# Extract the token parameter from url # Extract the token parameter from url
if token == '':
args = parse_qs(urlparse(path)[4]) # 4 is the query from url args = parse_qs(urlparse(path)[4]) # 4 is the query from url
if not 'token' in args or not len(args['token']): if not 'token' in args or not len(args['token']):
@ -148,6 +163,10 @@ Traffic Legend:
token = args['token'][0].rstrip('\n') token = args['token'][0].rstrip('\n')
if token == '':
raise self.server.EClose( "Empty Token defined" )
# Search for the token
result_pair = target_plugin.lookup( token ) result_pair = target_plugin.lookup( token )
if result_pair is not None: if result_pair is not None: