Ejemplo n.º 1
0
        private static void GenerateToken()
        {
            DisplayHeader();
            DisplaySubheader("Generate Token");

            var validseconds = EasyConsole.Input.ReadInt("Token validity in seconds (10-3000): ", 10, 3000);
            var targeturl    = EasyConsole.Input.ReadString("Target url: ");
            var sourceIP     = EasyConsole.Input.ReadString("Source IP (no syntax check): ");
            var salted       = EasyConsole.Input.ReadKeyYesOrNo("Add salt?");

            Console.WriteLine();
            var debug = EasyConsole.Input.ReadKeyYesOrNo("Add debug flag?");

            _tokenData = new ProxyRequestData()
            {
                ValidUntil = DateTime.Now.AddSeconds(validseconds), Url = targeturl, IP = IPAddress.Parse(sourceIP), Debug = debug, Salted = salted
            };
            _token = ProxyRequestDataEncoder.EncodeAndEncrypt(_tokenData, _key);

            Console.WriteLine();
            Console.WriteLine();
            DisplayToken();

            ContinueWithEnter();
        }
Ejemplo n.º 2
0
        private HttpRequestMessage CreateRequest(ProxyRequestData data)
        {
            var req = new HttpRequestMessage(HttpMethod.Get, data.Url);

            req.Headers.Add("X-Forwarded-For", data.IP.ToString());
            return(req);
        }
Ejemplo n.º 3
0
        internal string ProxyingAutodiscoverRequestIfApplicable(ProxyRequestData proxyRequestData, string redirectServer)
        {
            if (proxyRequestData == null)
            {
                return(null);
            }
            ExTraceGlobals.AuthenticationTracer.TraceDebug <string>(0L, "AutodiscoverProxy::ProxyingAutodiscoverRequestIfApplicable. Entry. redirectServer = {0}", redirectServer);
            string result = null;

            if (!AutodiscoverProxy.TryProxyAutodiscoverRequest(proxyRequestData, redirectServer, out result))
            {
                ExTraceGlobals.AuthenticationTracer.TraceError <ProxyRequestData, string>(0L, "AutodiscoverProxy::ProxyingAutodiscoverRequestIfApplicable. Cannot proxy this request. proxyRequestData = {0}, redirectServer = {1}", proxyRequestData, redirectServer);
            }
            else
            {
                proxyRequestData.Response.AddHeader("X-Autodiscover-Proxy", redirectServer);
            }
            ExTraceGlobals.AuthenticationTracer.TraceDebug <string>(0L, "AutodiscoverProxy::ProxyingAutodiscoverRequestIfApplicable. Exit. redirectServer = {0}", redirectServer);
            return(result);
        }
Ejemplo n.º 4
0
        private static void DecodeToken()
        {
            DisplayHeader();
            Console.WriteLine($"Key:         {_key}");
            Console.WriteLine();
            DisplaySubheader("Decode Token");
            var token = EasyConsole.Input.ReadString("Encoded & Encrypted token:");

            try
            {
                _tokenData = ProxyRequestDataDecoder.CreateFromEncodedAndEncrypted(token, _key);
                _token     = token;
                Console.WriteLine();
                DisplayToken();
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Decoding token failed: {ex.Message}");
            }
            ContinueWithEnter();
        }
Ejemplo n.º 5
0
 private static bool TryProxyAutodiscoverRequest(ProxyRequestData proxyRequestData, string redirectServer, out string rawResponse)
 {
     ExTraceGlobals.AuthenticationTracer.TraceDebug <string>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest. Entrypoint. redirectServer = {0}.", redirectServer);
     rawResponse = null;
     if (string.IsNullOrEmpty(redirectServer))
     {
         ExTraceGlobals.AuthenticationTracer.TraceError <string>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest. This is an invalid server name. redirectServer = {0}.", redirectServer);
         return(false);
     }
     try
     {
         HttpWebRequest httpWebRequest = proxyRequestData.CloneRequest(redirectServer);
         CertificateValidationManager.SetComponentId(httpWebRequest, "AutodiscoverProxy");
         using (WebResponse response = httpWebRequest.GetResponse())
         {
             using (Stream responseStream = response.GetResponseStream())
             {
                 rawResponse = AutodiscoverProxy.GetResponse(responseStream);
                 if (rawResponse == null)
                 {
                     ExTraceGlobals.AuthenticationTracer.TraceError <string>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest. received wrong number of user response. rawResponse = {0}.", rawResponse);
                     return(false);
                 }
                 ExTraceGlobals.AuthenticationTracer.TraceDebug <string, string>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest. Received response for user. redirectServer = {0}, rawResponse = {1}.", redirectServer, rawResponse);
             }
         }
     }
     catch (LocalizedException arg)
     {
         ExTraceGlobals.AuthenticationTracer.TraceError <LocalizedException>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest caught with a LocalizedException. LocalizedException = {0}.", arg);
         return(false);
     }
     catch (WebException arg2)
     {
         ExTraceGlobals.AuthenticationTracer.TraceError <WebException>(0L, "AutodiscoverProxy::TryProxyAutodiscoverRequest caught with a WebException. WebException = {0}.", arg2);
         return(false);
     }
     return(true);
 }