Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
vncproxy
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ed7ec2eb
authored
May 11, 2022
by
Fábián János
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vncproxy has been repaired (python 3.6)
parent
ac315429
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
19 deletions
+24
-19
proxy.py
+4
-2
websockets.py
+20
-17
No files found.
proxy.py
View file @
ed7ec2eb
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
from
os
import
environ
from
os
import
environ
from
django.conf
import
settings
from
twisted.internet
import
defer
from
twisted.internet
import
defer
from
twisted.internet
import
protocol
from
twisted.internet
import
protocol
from
twisted.internet.protocol
import
Factory
,
Protocol
from
twisted.internet.protocol
import
Factory
,
Protocol
...
@@ -79,7 +80,8 @@ class ProxyClientFactory(protocol.ReconnectingClientFactory):
...
@@ -79,7 +80,8 @@ class ProxyClientFactory(protocol.ReconnectingClientFactory):
class
VNCWebSocketHandler
(
Protocol
):
class
VNCWebSocketHandler
(
Protocol
):
def
makeConnection
(
self
,
transport
):
def
makeConnection
(
self
,
transport
):
try
:
try
:
value
=
signing
.
loads
(
transport
.
request
.
args
[
'd'
][
0
],
settings
.
configure
()
value
=
signing
.
loads
(
transport
.
request
.
args
[
b
'd'
][
0
]
.
decode
(),
key
=
PROXY_SECRET
,
max_age
=
KEY_MAX_AGE
)
key
=
PROXY_SECRET
,
max_age
=
KEY_MAX_AGE
)
try
:
try
:
self
.
src
=
transport
.
request
.
requestHeaders
.
getRawHeaders
(
self
.
src
=
transport
.
request
.
requestHeaders
.
getRawHeaders
(
...
@@ -134,7 +136,7 @@ if __name__ == "__main__":
...
@@ -134,7 +136,7 @@ if __name__ == "__main__":
opts
,
args
=
parser
.
parse_args
()
opts
,
args
=
parser
.
parse_args
()
logging
.
basicConfig
(
level
=
opts
.
loglevel
)
logging
.
basicConfig
(
level
=
opts
.
loglevel
)
resource
=
File
(
'.'
)
resource
=
File
(
'.'
)
resource
.
putChild
(
'vnc'
,
WebSocketsResource
(
resource
.
putChild
(
b
'vnc'
,
WebSocketsResource
(
lookupProtocolForFactory
(
VNCWebSocketFactory
())))
lookupProtocolForFactory
(
VNCWebSocketFactory
())))
reactor
.
listenTCP
(
9999
,
Site
(
resource
))
reactor
.
listenTCP
(
9999
,
Site
(
resource
))
reactor
.
run
()
reactor
.
run
()
websockets.py
View file @
ed7ec2eb
...
@@ -13,7 +13,7 @@ factory.
...
@@ -13,7 +13,7 @@ factory.
"""
"""
import
base64
import
base64
import
struct
from
hashlib
import
sha1
from
hashlib
import
sha1
from
struct
import
pack
,
unpack
from
struct
import
pack
,
unpack
...
@@ -88,7 +88,7 @@ def _makeAccept(key):
...
@@ -88,7 +88,7 @@ def _makeAccept(key):
@rtype: C{str}
@rtype: C{str}
@return: An encoded response.
@return: An encoded response.
"""
"""
return
sha1
(
"
%
s
%
s"
%
(
key
,
_WS_GUID
))
.
digest
()
.
encode
(
"base64"
)
.
strip
(
)
return
base64
.
b64encode
(
sha1
((
key
+
_WS_GUID
)
.
encode
(
"ascii"
))
.
digest
())
.
decode
(
"ascii"
)
def
_mask
(
buf
,
key
):
def
_mask
(
buf
,
key
):
...
@@ -104,10 +104,10 @@ def _mask(buf, key):
...
@@ -104,10 +104,10 @@ def _mask(buf, key):
@rtype: C{str}
@rtype: C{str}
@return: A masked buffer of bytes.
@return: A masked buffer of bytes.
"""
"""
key
=
[
ord
(
i
)
for
i
in
key
]
key
=
[
i
for
i
in
key
]
buf
=
list
(
buf
)
buf
=
list
(
buf
)
for
i
,
char
in
enumerate
(
buf
):
for
i
,
char
in
enumerate
(
buf
):
buf
[
i
]
=
chr
(
ord
(
char
)
^
key
[
i
%
4
])
buf
[
i
]
=
chr
(
char
^
key
[
i
%
4
])
return
""
.
join
(
buf
)
return
""
.
join
(
buf
)
...
@@ -129,7 +129,6 @@ def _makeFrame(buf, opcode, fin, mask=None):
...
@@ -129,7 +129,6 @@ def _makeFrame(buf, opcode, fin, mask=None):
@type mask: C{int} or C{NoneType}
@type mask: C{int} or C{NoneType}
@param mask: If specified, the masking key to apply on the created frame.
@param mask: If specified, the masking key to apply on the created frame.
@rtype: C{str}
@rtype: C{str}
@return: A packed frame.
@return: A packed frame.
"""
"""
...
@@ -140,11 +139,11 @@ def _makeFrame(buf, opcode, fin, mask=None):
...
@@ -140,11 +139,11 @@ def _makeFrame(buf, opcode, fin, mask=None):
lengthMask
=
0
lengthMask
=
0
if
bufferLength
>
0xffff
:
if
bufferLength
>
0xffff
:
length
=
"
%
s
%
s"
%
(
chr
(
lengthMask
|
0x7f
),
pack
(
">Q"
,
bufferLength
)
)
length
=
bytes
(
chr
(
lengthMask
|
0x7f
),
'UTF-8'
)
+
pack
(
">Q"
,
bufferLength
)
elif
bufferLength
>
0x7d
:
elif
bufferLength
>
0x7d
:
length
=
"
%
s
%
s"
%
(
chr
(
lengthMask
|
0x7e
),
pack
(
">H"
,
bufferLength
)
)
length
=
bytes
(
chr
(
lengthMask
|
0x7e
),
'UTF-8'
)
+
pack
(
">H"
,
bufferLength
)
else
:
else
:
length
=
chr
(
lengthMask
|
bufferLength
)
length
=
bytes
(
chr
(
lengthMask
|
bufferLength
),
'UTF-8'
)
if
fin
:
if
fin
:
header
=
0x80
header
=
0x80
...
@@ -154,7 +153,7 @@ def _makeFrame(buf, opcode, fin, mask=None):
...
@@ -154,7 +153,7 @@ def _makeFrame(buf, opcode, fin, mask=None):
header
=
chr
(
header
|
opcode
.
value
)
header
=
chr
(
header
|
opcode
.
value
)
if
mask
is
not
None
:
if
mask
is
not
None
:
buf
=
"
%
s
%
s"
%
(
mask
,
_mask
(
buf
,
mask
))
buf
=
"
%
s
%
s"
%
(
mask
,
_mask
(
buf
,
mask
))
frame
=
"
%
s
%
s
%
s"
%
(
header
,
length
,
buf
)
frame
=
bytes
(
header
,
'raw_unicode_escape'
)
.
strip
()
+
length
+
buf
return
frame
return
frame
...
@@ -170,7 +169,7 @@ def _parseFrames(frameBuffer, needMask=True):
...
@@ -170,7 +169,7 @@ def _parseFrames(frameBuffer, needMask=True):
@type needMask: C{bool}
@type needMask: C{bool}
"""
"""
start
=
0
start
=
0
payload
=
""
.
join
(
frameBuffer
)
payload
=
b
""
.
join
(
frameBuffer
)
while
True
:
while
True
:
# If there's not at least two bytes in the buffer, bail.
# If there's not at least two bytes in the buffer, bail.
...
@@ -178,7 +177,7 @@ def _parseFrames(frameBuffer, needMask=True):
...
@@ -178,7 +177,7 @@ def _parseFrames(frameBuffer, needMask=True):
break
break
# Grab the header. This single byte holds some flags and an opcode
# Grab the header. This single byte holds some flags and an opcode
header
=
ord
(
payload
[
start
])
header
=
payload
[
start
]
if
header
&
0x70
:
if
header
&
0x70
:
# At least one of the reserved flags is set. Pork chop sandwiches!
# At least one of the reserved flags is set. Pork chop sandwiches!
raise
_WSException
(
"Reserved flag in frame (
%
d)"
%
(
header
,))
raise
_WSException
(
"Reserved flag in frame (
%
d)"
%
(
header
,))
...
@@ -195,7 +194,7 @@ def _parseFrames(frameBuffer, needMask=True):
...
@@ -195,7 +194,7 @@ def _parseFrames(frameBuffer, needMask=True):
# Get the payload length and determine whether we need to look for an
# Get the payload length and determine whether we need to look for an
# extra length.
# extra length.
length
=
ord
(
payload
[
start
+
1
])
length
=
payload
[
start
+
1
]
masked
=
length
&
0x80
masked
=
length
&
0x80
if
not
masked
and
needMask
:
if
not
masked
and
needMask
:
...
@@ -343,9 +342,13 @@ class WebSocketsTransport(object):
...
@@ -343,9 +342,13 @@ class WebSocketsTransport(object):
# Send a closing frame. It's only polite. (And might keep the browser
# Send a closing frame. It's only polite. (And might keep the browser
# from hanging.)
# from hanging.)
if
not
self
.
_disconnecting
:
if
not
self
.
_disconnecting
:
data
=
"
%
s
%
s"
%
(
pack
(
">H"
,
code
.
value
),
reason
)
msg
=
b
''
frame
=
_makeFrame
(
data
,
CONTROLS
.
CLOSE
,
True
)
if
code
is
not
None
:
self
.
_transport
.
write
(
frame
)
msg
+=
struct
.
pack
(
">H"
,
code
.
value
)
if
reason
is
not
None
:
msg
+=
reason
.
encode
(
"UTF-8"
)
self
.
_transport
.
write
(
msg
)
self
.
_disconnecting
=
True
self
.
_disconnecting
=
True
self
.
_transport
.
loseConnection
()
self
.
_transport
.
loseConnection
()
...
@@ -462,7 +465,7 @@ class _WebSocketsProtocolWrapperReceiver():
...
@@ -462,7 +465,7 @@ class _WebSocketsProtocolWrapperReceiver():
return
return
self
.
_messages
.
append
(
data
)
self
.
_messages
.
append
(
data
)
if
fin
:
if
fin
:
content
=
""
.
join
(
self
.
_messages
)
content
=
b
""
.
join
(
self
.
_messages
)
self
.
_messages
[:]
=
[]
self
.
_messages
[:]
=
[]
self
.
_wrappedProtocol
.
dataReceived
(
content
)
self
.
_wrappedProtocol
.
dataReceived
(
content
)
...
@@ -618,7 +621,7 @@ class WebSocketsResource(object):
...
@@ -618,7 +621,7 @@ class WebSocketsResource(object):
# If we fail at all, we'll fail with 400 and no response.
# If we fail at all, we'll fail with 400 and no response.
failed
=
False
failed
=
False
if
request
.
method
!=
"GET"
:
if
request
.
method
!=
b
"GET"
:
# 4.2.1.1 GET is required.
# 4.2.1.1 GET is required.
failed
=
True
failed
=
True
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment