titanium-web-proxy icon indicating copy to clipboard operation
titanium-web-proxy copied to clipboard

Redirecting socket request

Open lightfiretw opened this issue 6 years ago • 8 comments

When trying to change the request URI for socket requests, the requests URI doesn't change.

Code

        private async Task OnRequest(object sender, SessionEventArgs e)
        {
            e.HttpClient.Request.RequestUri = new Uri("https://mywebsite.com/?socket=" + e.HttpClient.Request.RequestUri.AbsoluteUri);
            e.HttpClient.Request.Host = new Uri("https://mywebsite.com").Host;
        }

When testing on https://www.websocket.org/echo.html The first request which is https://echo.websocket.org/?encoding=text, should be redirected to https://mywebsite.com/?socket=https://echo.websocket.org/?encoding=text But it turns into https://mywebsite.com/?encoding=text instead.

lightfiretw avatar Apr 01 '19 10:04 lightfiretw

I can't reproduce this issue.

I've added the following code to the BefureRequest handler:

            if (e.HttpClient.Request.RequestUri.ToString().Contains("websocket.org"))
            {
                e.HttpClient.Request.RequestUri =
                    new Uri("http://www.httpvshttps.com/?socket=" + e.HttpClient.Request.RequestUri.AbsoluteUri);
                e.HttpClient.Request.Host = new Uri("http://www.httpvshttps.com").Host;
            }


When opening https://www.websocket.org/echo.html Wiresharks shows: image

As expected. (With HTTPS it seems to be the same)

Could you please create a small test project to reproduce the problem?


I've found a related issue, that the HeaderText proeprty (and because that the ToString(), too) shows incorrect request URL, but it is not sent to the server.

honfika avatar Apr 26 '19 13:04 honfika

By the way: as a workaround for the HeaderText and Request.ToString issue you can set the OriginalUrl ptoperty, too (path only):

e.HttpClient.Request.OriginalUrl = "/?socket=" + e.HttpClient.Request.RequestUri.AbsoluteUri;

honfika avatar Apr 26 '19 13:04 honfika

Do you have an upstream proxy? I've reproduced the issue in the following configuration:

client => TWP => Fiddler => server

honfika avatar Apr 26 '19 14:04 honfika

Do you have an upstream proxy? I've reproduced the issue in the following configuration:

Yes, I do. I'm using Burp suite to check if calls are correctly sent. So my flow is like Client=>Burp=>Server. Also noticed something interesting, when using HTTPS for socket upgrade and redirecting the HOST changes(changes to https://mywebsite.com/), but trying with HTTP nothing get changed(https://echo.websocket.org/?encoding=text), it's like it bypassed the proxy.

lightfiretw avatar Apr 29 '19 02:04 lightfiretw

Could you please try the latest package?

honfika avatar Jul 21 '19 08:07 honfika

Sure, unfortunately it is still the same. HTTPS the request host is changed but not the request path, HTTP it just ignores the modification for the request and connects to the original request.

I noticed for HTTPS that the httpCmd in RequestHandler.cs handleHttpSessionRequest is set before invokeBeforeRequest(args) is called, causing handleWebSocketUpgrade to connect to unmodified path. Not sure if I'm correct of not though.

Currently I am just straight up setting handleWebSocketUpgrade to suit my needs.

lightfiretw avatar Jul 23 '19 07:07 lightfiretw

Please try the latest package again.

honfika avatar Dec 26 '19 08:12 honfika

unfortunately it is still the same.

wY1k avatar Mar 05 '23 14:03 wY1k