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

FiddlerCore - How to Delay a Request

1 Answer 367 Views
FiddlerCore
This is a migrated thread and some comments may be shown as answers.
Harry
Top achievements
Rank 1
Harry asked on 22 Nov 2018, 09:44 PM

I'm having an issue with an WinHTTP application I'm intercepting and modifying data for. I'm setting the WinHTTP proxy as a loopback to capture and modify the response, however the WinHTTP application checks for a loopback after the response and denies authorization if one is found.

I've tried setting the loopback, decoding the response, and right before sending my modified response, resetting the WinHTTP settings to default. The problem i'm facing is that this WinHTTP application actually polls the server twice in a row, so if I reset the proxy once, i need to set it again and then reset it again before modifying the response a 2nd time.

Is there a way I can delay the 2nd request so that I have enough time to reset and set the first one? I've tried using Thread.Sleep but that doesn't work. Thanks.

        void Start()
        {
            CaptureConfiguration.CaptureDomain = "https://toirplusvip.com/";

            SetWinHTTPProxy();

            FiddlerApplication.AfterSessionComplete += FiddlerApplication_AfterSessionComplete;
            FiddlerApplication.BeforeRequest += FiddlerApplication_BeforeRequest;
            FiddlerApplication.BeforeResponse += FiddlerApplication_BeforeResponse;
            FiddlerApplication.Startup(8877, false, true, true);
        }

        public void SetWinHTTPProxy()
        {
            var proc1 = new ProcessStartInfo();
            string anyCommand = "netsh winhttp set proxy 127.0.0.1:8877 \"<-loopback>\"";
            proc1.UseShellExecute = true;
            proc1.WorkingDirectory = @"C:\Windows\System32";
            proc1.FileName = @"C:\Windows\System32\cmd.exe";
            proc1.Verb = "runas";
            proc1.Arguments = "/c " + anyCommand;
            proc1.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(proc1);
        }

        public void ResetWinHTTPProxy()
        {
            var proc1 = new ProcessStartInfo();
            string anyCommand = "netsh winhttp reset proxy";
            proc1.UseShellExecute = true;
            proc1.WorkingDirectory = @"C:\Windows\System32";
            proc1.FileName = @"C:\Windows\System32\cmd.exe";
            proc1.Verb = "runas";
            proc1.Arguments = "/c " + anyCommand;
            proc1.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(proc1);
        }

        private void FiddlerApplication_BeforeResponse(Session oSession)
        {
            if (oSession.fullUrl.ToLower().Contains("toirplusvip.com/checklogin_vip_aimode2.php"))
            {
                Console.WriteLine(oSession.fullUrl.ToLower());
                Console.WriteLine("beeuty");
                oSession.utilDecodeResponse();
                var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
                var epoch = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
                var sessionID = "8763c665bc13e4ba56ee578c161dc1f4";
                String input = "rnd='&ret=" + sessionID + "&token=" + epoch + "&code=0";
                Console.WriteLine(input);
                Cryptography c = new Cryptography();
                String nBody = c.EncryptString(input, key, iv);

                ResetWinHTTPProxy(); // needs to be reset in between

                oSession.utilSetResponseBody(nBody);
                return;
            }
        }

1 Answer, 1 is accepted

Sort by
0
Harry
Top achievements
Rank 1
answered on 24 Nov 2018, 05:30 AM
Nvm I figured it out, if an admin can delete this topic that would be great. Thanks.
Tags
FiddlerCore
Asked by
Harry
Top achievements
Rank 1
Answers by
Harry
Top achievements
Rank 1
Share this question
or