Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
c46293d5
Commit
c46293d5
authored
Nov 30, 2019
by
Honfika
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better websocker unmask
parent
7cb42ed1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
13 deletions
+53
-13
ProxyTestController.cs
.../Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
+15
-2
WebSocketDecoder.cs
src/Titanium.Web.Proxy/WebSocketDecoder.cs
+38
-11
No files found.
examples/Titanium.Web.Proxy.Examples.Basic/ProxyTestController.cs
View file @
c46293d5
...
@@ -152,9 +152,21 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -152,9 +152,21 @@ namespace Titanium.Web.Proxy.Examples.Basic
}
}
}
}
private
void
WebSocket_DataSent
(
object
sender
,
DataEventArgs
e
)
{
var
args
=
(
SessionEventArgs
)
sender
;
WebSocketDataSentReceived
(
args
,
e
,
true
);
}
private
void
WebSocket_DataReceived
(
object
sender
,
DataEventArgs
e
)
private
void
WebSocket_DataReceived
(
object
sender
,
DataEventArgs
e
)
{
{
var
args
=
(
SessionEventArgs
)
sender
;
var
args
=
(
SessionEventArgs
)
sender
;
WebSocketDataSentReceived
(
args
,
e
,
false
);
}
private
void
WebSocketDataSentReceived
(
SessionEventArgs
args
,
DataEventArgs
e
,
bool
sent
)
{
var
color
=
sent
?
ConsoleColor
.
Green
:
ConsoleColor
.
Blue
;
foreach
(
var
frame
in
args
.
WebSocketDecoder
.
Decode
(
e
.
Buffer
,
e
.
Offset
,
e
.
Count
))
foreach
(
var
frame
in
args
.
WebSocketDecoder
.
Decode
(
e
.
Buffer
,
e
.
Offset
,
e
.
Count
))
{
{
...
@@ -162,12 +174,12 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -162,12 +174,12 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
{
var
data
=
frame
.
Data
.
ToArray
();
var
data
=
frame
.
Data
.
ToArray
();
string
str
=
string
.
Join
(
","
,
data
.
ToArray
().
Select
(
x
=>
x
.
ToString
(
"X2"
)));
string
str
=
string
.
Join
(
","
,
data
.
ToArray
().
Select
(
x
=>
x
.
ToString
(
"X2"
)));
writeToConsole
(
str
,
ConsoleColor
.
Blue
).
Wait
();
writeToConsole
(
str
,
color
).
Wait
();
}
}
if
(
frame
.
OpCode
==
WebsocketOpCode
.
Text
)
if
(
frame
.
OpCode
==
WebsocketOpCode
.
Text
)
{
{
writeToConsole
(
frame
.
GetText
(),
ConsoleColor
.
Blue
).
Wait
();
writeToConsole
(
frame
.
GetText
(),
color
).
Wait
();
}
}
}
}
}
}
...
@@ -233,6 +245,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
...
@@ -233,6 +245,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
{
if
(
e
.
HttpClient
.
ConnectRequest
?.
TunnelType
==
TunnelType
.
Websocket
)
if
(
e
.
HttpClient
.
ConnectRequest
?.
TunnelType
==
TunnelType
.
Websocket
)
{
{
e
.
DataSent
+=
WebSocket_DataSent
;
e
.
DataReceived
+=
WebSocket_DataReceived
;
e
.
DataReceived
+=
WebSocket_DataReceived
;
}
}
...
...
src/Titanium.Web.Proxy/WebSocketDecoder.cs
View file @
c46293d5
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
System.Runtime.InteropServices
;
using
Titanium.Web.Proxy.StreamExtended.BufferPool
;
using
Titanium.Web.Proxy.StreamExtended.BufferPool
;
namespace
Titanium.Web.Proxy
namespace
Titanium.Web.Proxy
...
@@ -60,25 +61,51 @@ namespace Titanium.Web.Proxy
...
@@ -60,25 +61,51 @@ namespace Titanium.Web.Proxy
}
}
}
}
uint
mask
=
0
;
if
(
size
<
0
)
if
(
masked
)
{
{
//mask = (uint)(((long)data1[idx++] << 24) + (data1[idx++] << 16) + (data1[idx++] << 8) + data1[idx++]);
;
mask
=
(
uint
)(
data1
[
idx
++]
+
(
data1
[
idx
++]
<<
8
)
+
(
data1
[
idx
++]
<<
16
)
+
((
long
)
data1
[
idx
++]
<<
24
));
}
if
(
data1
.
Length
<
idx
+
size
)
{
break
;
}
}
if
(
masked
)
if
(
masked
)
{
{
uint
m
=
mask
;
//mask = (uint)(((long)data1[idx++] << 24) + (data1[idx++] << 16) + (data1[idx++] << 8) + data1[idx++]);
for
(
int
i
=
0
;
i
<
size
;
i
++)
//mask = (uint)(data1[idx++] + (data1[idx++] << 8) + (data1[idx++] << 16) + ((long)data1[idx++] << 24));
var
uData
=
MemoryMarshal
.
Cast
<
byte
,
uint
>(
data1
.
Slice
(
idx
,
(
int
)
size
+
4
));
idx
+=
4
;
uint
mask
=
uData
[
0
];
long
size1
=
size
;
if
(
size
>
4
)
{
uData
=
uData
.
Slice
(
1
);
for
(
int
i
=
0
;
i
<
uData
.
Length
;
i
++)
{
{
data
[
i
+
idx
]
=
(
byte
)(
data1
[
i
+
idx
]
^
(
byte
)
mask
);
uData
[
i
]
=
uData
[
i
]
^
mask
;
}
size1
-=
uData
.
Length
*
4
;
}
if
(
size1
>
0
)
{
int
pos
=
(
int
)(
idx
+
size
-
size1
);
data1
[
pos
]
^=
(
byte
)
mask
;
m
>>=
8
;
if
(
size1
>
1
)
{
data1
[
pos
+
1
]
^=
(
byte
)(
mask
>>
8
);
}
if
(
m
==
0
)
if
(
size1
>
2
)
m
=
mask
;
{
data1
[
pos
+
2
]
^=
(
byte
)(
mask
>>
16
);
}
}
;
}
}
}
var
frameData
=
buffer
.
Slice
(
idx
,
(
int
)
size
);
var
frameData
=
buffer
.
Slice
(
idx
,
(
int
)
size
);
...
...
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