Can't extract websocket payload from binary to ascii

12 posts, 0 answers
  1. Risto
    Risto avatar
    19 posts
    Member since:
    Mar 2014

    Posted 12 Jun 2017 Link to this post

    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.

     

     

     

     

  2. Risto
    Risto avatar
    19 posts
    Member since:
    Mar 2014

    Posted 12 Jun 2017 in reply to Risto Link to this post

    Fiddler 4.6.20171.9220 
  3. Risto
    Risto avatar
    19 posts
    Member since:
    Mar 2014

    Posted 04 Sep 2017 Link to this post

    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.

  4. Simeon
    Admin
    Simeon avatar
    195 posts

    Posted 07 Sep 2017 Link to this post

    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
  5. Risto
    Risto avatar
    19 posts
    Member since:
    Mar 2014

    Posted 15 Sep 2017 in reply to Simeon Link to this post

    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.

     

  6. Risto
    Risto avatar
    19 posts
    Member since:
    Mar 2014

    Posted 21 Sep 2017 Link to this post

    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). 

  7. Simeon
    Admin
    Simeon avatar
    195 posts

    Posted 21 Sep 2017 Link to this post

    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
  8. Risto
    Risto avatar
    19 posts
    Member since:
    Mar 2014

    Posted 21 Sep 2017 in reply to Simeon Link to this post

    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

     

  9. Alexander
    Admin
    Alexander avatar
    383 posts

    Posted 28 Sep 2017 Link to this post

    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
  10. Risto
    Risto avatar
    19 posts
    Member since:
    Mar 2014

    Posted 28 Sep 2017 in reply to Alexander Link to this post

    Thank you! I sent the file over Help->Feedback (https://fiddler.ideas.aha.io/ideas/FID-I-231)
  11. Risto
    Risto avatar
    19 posts
    Member since:
    Mar 2014

    Posted 29 Sep 2017 Link to this post

    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");
       }

  12. zhi
    zhi avatar
    1 posts
    Member since:
    Mar 2018

    Posted 06 Mar 2018 Link to this post

    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!

Back to Top