-
Notifications
You must be signed in to change notification settings - Fork 779
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
Added traffic plugin support #549
Open
gschaden
wants to merge
2
commits into
novnc:master
Choose a base branch
from
gschaden:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from websockify.traffic_plugins import BasePlugin | ||
from websockify import pyDes | ||
|
||
class RFBDes(pyDes.des): | ||
def setKey(self, key): | ||
"""RFB protocol for authentication requires client to encrypt | ||
challenge sent by server with password using DES method. However, | ||
bits in each byte of the password are put in reverse order before | ||
using it as encryption key.""" | ||
newkey = [] | ||
for ki in range(len(key)): | ||
bsrc = ord(key[ki]) | ||
btgt = 0 | ||
for i in range(8): | ||
if bsrc & (1 << i): | ||
btgt = btgt | (1 << 7 - i) | ||
newkey.append(btgt) | ||
super(RFBDes, self).setKey(newkey) | ||
|
||
"""Intercepts VNC traffic and injects the password from a provided token""" | ||
class VncTokenAuthenticationTrafficPlugin(BasePlugin): | ||
def __init__(self, handler, tsock): | ||
super().__init__(handler, tsock) | ||
self.password = self.handler.target_attribtues["password"] | ||
self.client_packet_count = 0 | ||
self.target_packet_count = 0 | ||
|
||
def from_client(self, s): | ||
self.client_packet_count += 1 | ||
if self.client_packet_count == 2: | ||
return None | ||
return s | ||
|
||
def from_target(self, s): | ||
self.target_packet_count += 1 | ||
if self.target_packet_count == 2 and b"\x02" in s[1:]: # check if password is supported | ||
self.tsock.send(b'\x02') | ||
self.handle_auth = True | ||
s = None # dont forward to client | ||
if self.target_packet_count == 3 and self.handle_auth: # challenge | ||
self.handle_auth = False | ||
pw = (self.password + '\0' * 8)[:8] # make sure its 8 chars long, zero padded | ||
des = RFBDes(pw) | ||
response = des.encrypt(s) | ||
self.tsock.send(response) | ||
return b'\x01\x01' # send "no auth" required to client | ||
return s |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid this is a bit fragile. There is no guarantee that the stream will be split in packages in a specific way.
Some rudimentary protocol handling will be needed here.
Have you considered a proxy model, instead of this filtering model? It might be a better fit.