/// <summary> /// /// </summary> /// <param name="requestObj"></param> public PluginInstruction ProcessServerResponseHeaders(RequestObj requestObj) { PluginInstruction pluginInstruction = new PluginInstruction(); return(pluginInstruction); }
public PluginInstruction OnPostClientHeadersRequest(RequestObj requestObj) { PluginInstruction instruction = new PluginInstruction(); instruction.Instruction = Instruction.DoNothing; if (requestObj == null) { throw new ProxyWarningException("The request object is invalid"); } if (string.IsNullOrEmpty(requestObj.ClientRequestObj.Host)) { return(instruction); } string hostName = requestObj.ClientRequestObj.Host.ToLower(); // If hostname is mapped WITHOUT wildcard if (Plugin.HostMapping.Config.MappingsHostname?.Count > 0 && Plugin.HostMapping.Config.MappingsHostname.ContainsKey(hostName) && requestObj.ClientRequestObj.ClientRequestHeaders.ContainsKey("Host")) { this.pluginProperties.PluginHost.LoggingInst.LogMessage( "HostMapping", ProxyProtocol.Undefined, Loglevel.Debug, "HostMapping.OnPostClientHeadersRequest(): Replacing host \"{0}\" by \"{1}\" (by hostname)", requestObj.ClientRequestObj.ClientRequestHeaders["Host"][0].ToString(), Plugin.HostMapping.Config.MappingsHostname[hostName]); requestObj.ClientRequestObj.ClientRequestHeaders["Host"].Clear(); requestObj.ClientRequestObj.ClientRequestHeaders["Host"].Add(Plugin.HostMapping.Config.MappingsHostname[hostName]); requestObj.ClientRequestObj.Host = Plugin.HostMapping.Config.MappingsHostname[hostName]; // If hostname is mapped WITH wildcard } else if (Plugin.HostMapping.Config.MappingsHostWildcards?.Count > 0) { foreach (var replHost in Plugin.HostMapping.Config.MappingsHostWildcards.Keys) { var mappingPair = Plugin.HostMapping.Config.MappingsHostWildcards[replHost]; if (mappingPair.PatternReg.Match(hostName).Success) { this.pluginProperties.PluginHost.LoggingInst.LogMessage( "HostMapping", ProxyProtocol.Undefined, Loglevel.Debug, "HostMapping.OnPostClientHeadersRequest(): Replacing host \"{0}\" by \"{1}\" (by hostname wildcard)", requestObj.ClientRequestObj.ClientRequestHeaders["Host"][0].ToString(), replHost); requestObj.ClientRequestObj.ClientRequestHeaders["Host"].Clear(); requestObj.ClientRequestObj.ClientRequestHeaders["Host"].Add(replHost); requestObj.ClientRequestObj.Host = replHost; break; } } } return(instruction); }
/// <summary> /// /// </summary> /// <param name="requestObj"></param> public PluginInstruction ProcessServerResponseHeaders(RequestObj requestObj) { RedirectType redirType; PluginInstruction pluginInstruction = new PluginInstruction(); // Handle HSTS header this.ProcessHstsHeader(requestObj); // Determine redirection mode redirType = this.DetermineRedirectType(requestObj); // The HTTP lClient request triggers a regular HTML data response. // 1. Transfer the peer system response (Server response string, headers, data) // // -> DONT DO ANYTHING if (redirType == RedirectType.Http2http2XX) { // Set PluginInstruction values pluginInstruction.Instruction = Instruction.DoNothing; Logging.Instance.LogMessage( requestObj.Id, ProxyProtocol.Undefined, Loglevel.Debug, "SslStrip.ProcessServerResponseHeaders(): TYPE Http2http2XX, {0} \"{1}\" -> \"-\", host:{2}, MimeType:{3}", requestObj.ServerResponseObj.ContentTypeEncoding.ContentType, requestObj.ClientRequestObj.GetRequestedUrl(), requestObj.ClientRequestObj.Host, requestObj.ServerResponseObj.ContentTypeEncoding.ContentType); // The HTTP client request triggers a request to a HTTP Url // 1. Transfer the peer system response (Server response string, headers, data) // // -> DONT DO ANYTHING } else if (redirType == RedirectType.Http2Http3XX) { // Set PluginInstruction values pluginInstruction.Instruction = Instruction.DoNothing; Logging.Instance.LogMessage( requestObj.Id, ProxyProtocol.Undefined, Loglevel.Debug, "SslStrip.ProcessServerResponseHeaders(): TYPE Http2Http3XX \"{0}\" -> \"{1}\"", requestObj.ClientRequestObj.GetRequestedUrl(), requestObj.ServerResponseObj.ResponseHeaders["Location"][0]); // SslStrip : The HTTP client request triggers a request to a HTTPS Url // 1. Cache the HTTP/HTTPS mapping // 2. Replace the "https" scheme in the redirect location by "http" // 3. Transfer the peer system response (Server response string, headers, data) } else if (redirType == RedirectType.Http2Https3XXDifferentUrl) { this.ProcessHeadersDifferentRedirectLocation(requestObj); // Set PluginInstruction values pluginInstruction.Instruction = Instruction.DoNothing; //// Http2Https3XXSameUrl -> Remember redirect, strip SSL, request new Url SSLCacheAndRedirectClient2RedirectLocation() Logging.Instance.LogMessage( requestObj.Id, ProxyProtocol.Undefined, Loglevel.Debug, "SslStrip.ProcessServerResponseHeaders(): TYPE Http2Https3XXDifferentUrl \"{0}\" -> \"{1}\"", requestObj.ClientRequestObj.GetRequestedUrl(), requestObj.ServerResponseObj.ResponseHeaders["Location"][0]); // 1. Resend the same request again to the same Url but with "https" scheme instead of "http" // 2. Transfer the peer system response (Server response string, headers, data) } else if (redirType == RedirectType.Http2Https3XXSameUrl) { this.ProcessHeadersSameRedirectLocation(requestObj); // Set PluginInstruction values pluginInstruction.Instruction = Instruction.ReloadUrlWithHttps; Logging.Instance.LogMessage( requestObj.Id, ProxyProtocol.Undefined, Loglevel.Debug, "SslStrip.ProcessServerResponseHeaders(): TYPE Http2Https3XXSameUrl \"{0}\" -> \"{1}\" OldScheme:{2}", requestObj.ClientRequestObj.GetRequestedUrl(), requestObj.ServerResponseObj.ResponseHeaders["Location"][0], requestObj.ProxyProtocol.ToString().ToLower()); // This should never happen!! // No clue what to do at this point! } else { // Set PluginInstruction values pluginInstruction.Instruction = Instruction.DoNothing; Logging.Instance.LogMessage( requestObj.Id, ProxyProtocol.Undefined, Loglevel.Debug, "SslStrip.DoClientRequestProcessing(): TYPE definition error for Url \"{0}\" ", requestObj.ClientRequestObj.GetRequestedUrl()); } return(pluginInstruction); }