This is a migrated thread and some comments may be shown as answers.

Can't extract websocket payload from binary to ascii

11 Answers 1699 Views
Windows
This is a migrated thread and some comments may be shown as answers.
Risto
Top achievements
Rank 1
Risto asked on 12 Jun 2017, 02:35 PM

Hi!

Website sends data over websocket and I can see it under WebSocket tab (see fiddler1.png). My purpose was to get the message payloads to the file as ascii text. So I found https://www.codeproject.com/Articles/718660/Debug-Inspect-WebSocket-traffic-with-Fiddler. Now I see the websocket messages in the session window but script passes by where payload should be recognized as binary (see fiddler2.png) - condition

if (oMsg.FrameType == WebSocketFrameTypes.Binary)
{
    payloadString = HexToString(payloadString);
 
}

never became true. When I saved payload to file it looked binary to me.

Chrome -> Developer tools -> Network ->WS->Frames shows the payload data in JSON format. I would appreciate if anyone drops a hint where I am going wrong.

 

 

 

 

11 Answers, 1 is accepted

Sort by
0
Risto
Top achievements
Rank 1
answered on 12 Jun 2017, 04:39 PM
Fiddler 4.6.20171.9220 
0
Risto
Top achievements
Rank 1
answered on 04 Sep 2017, 05:09 PM

I use

static function OnWebSocketMessage(oMsg: WebSocketMessage)
{
FiddlerApplication.Log.LogString(oMsg);
}

for displaying websocket message at Fiddler the log tab. As you see the payload is in binary or encoded and Chrome developer tool is capable to display it in JSON format. Tried also with https://www.websocket.org/echo.html and this site payload was nice and readable. Can anyone tell me what should I do to get payload in FiddlerScript in JSON format as Chrome Developer tool shows.

0
Simeon
Telerik team
answered on 07 Sep 2017, 05:15 PM
Hello,

Hi, the reason for this condition in your script:

if (oMsg.FrameType == WebSocketFrameTypes.Binary)
{
    payloadString = HexToString(payloadString);
 
}

to never become true is that the WebSocket traffic, which you are debugging, is not from a Binary type as far as I can tell from the images which you attached. Instead it is from a Text type.

The PayloadAsString() method of Fiddler tries to decode the payload using UTF-8 encoding. In your case the encoding seems to be ASCII as you say so. You should use the PayloadAsBytes() method and try to decode the byte array, which this method returns, using ASCII encoding.

I hope that this information is helpful for you!

Regards,

Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Risto
Top achievements
Rank 1
answered on 15 Sep 2017, 04:05 PM

Thank you!

I managed to create byteArray

var payloadByteArray = oMsg.PayloadAsBytes();

the result I printed to log tab and it looks like:

18:39:08:3360 34,220,22,55,67,30,127,38,112,32,141,169,161,177,57,100,198,29,204,180,132,51,45,160,103,211,0,0

But then failed to turn it to some humanreadable format with:

var payloadBString=payloadByteArray.ToString();

then payloadBString result in log looked like:

18:39:08:3360 System.Byte[]

var payloadBString=Utilities.ByteArrayToString(payloadByteArray);

the result at log tab was like:

18:55:02:0908 B4 9D 5B B2 E3 20 0C 44 37 34 A9 0A 60 13 67 FF 1B 1B 9B FB 63 84 4F F3 28 65 03 A3 8A AE C7 16 A2 FB F4 C0 98 EC A7 40 6E 13 1D 30 09 03 C5 91 81 D5 71 AF 3F 37 78 27 ......

Tried HexToString(payloadBString); but this also failed failed.

 

0
Risto
Top achievements
Rank 1
answered on 21 Sep 2017, 06:53 AM

Tried to convert the payload byte array to some human readable but failed. I am not quite sure what do you mean under "using ASCII encoding". Can you give some code examples?

I am not sure what format the data is. You probably found out from my screenshots that it is in Text type (how I do not know because payload looks crap to me in Fiddler WS tab and printed out to log tab). 

0
Simeon
Telerik team
answered on 21 Sep 2017, 02:20 PM
Hi,

If you are sure about the encoding of the byte array you could use some of the GetString method overloads from the Encoding class. For more information regarding character encoding you could read this post.

Regards,
Simeon
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Risto
Top achievements
Rank 1
answered on 21 Sep 2017, 07:35 PM

I do not know what format or encoding the payload is (or is it compressed or encrypted or image). All I know that payloads in Fiddler and frames in Chrome dev-tools have quite match. If I'd know I've already managed to narrow my search in google :)

Tried all encoding options that Fiddlerscript editor suggested (ASCII, BigEndianUnicode, Default, Unicode, UTF32, UTF7, UTF8) for example:

var pBA = oMsg.PayloadAsBytes();
var cc = Encoding.UTF8.GetString(pBA);
FiddlerApplication.Log.LogString(cc);

but they all returned same unreadable crap. Byte array bytes have values from 0 to 255

 

0
Alexander
Telerik team
answered on 28 Sep 2017, 10:03 AM
Hello,

Would it be possible that you create archive the WebSocket connection in SAZ file and send it over to us? In order to do that start Fiddler, do the WebSocket comunication, then go to File -> Save -> All Sessions... and save the file.

Regards,
Alexander
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Risto
Top achievements
Rank 1
answered on 28 Sep 2017, 04:00 PM
Thank you! I sent the file over Help->Feedback (https://fiddler.ideas.aha.io/ideas/FID-I-231)
0
Risto
Top achievements
Rank 1
answered on 29 Sep 2017, 12:39 PM

Yes! "deflate" was the keyword. I found Eric's script from Fiddler Ideas (actually script was there missing but GodBlessGoogle) and this worked fine for me:

   if (oSession.RequestHeaders.ExistsAndContains("Sec-WebSocket-Extensions", "permessage-deflate")) {
      oSession.RequestHeaders.Remove("Sec-WebSocket-Extensions");
   }

0
zhi
Top achievements
Rank 1
answered on 07 Mar 2018, 04:14 AM

Hi Risto,

I am just running into a problem when i try to store the request message from server side to local file. I could already read the message in the Fiddler main window but i want to save the message to local file. Then it could be easily read and manipulated. I saw your question here, it seems that you have already worked it out.

Thanks so much for your reply!

Tags
Windows
Asked by
Risto
Top achievements
Rank 1
Answers by
Risto
Top achievements
Rank 1
Simeon
Telerik team
Alexander
Telerik team
zhi
Top achievements
Rank 1
Share this question
or