コード例 #1
0
ファイル: HTTPMessage.cs プロジェクト: melagiri/IronWASP
 public HTTPMessage(string HTTPInput)
 {
     string[] MessageParts = HTTPInput.Split(new string[] { "\r\n\r\n" }, 2, StringSplitOptions.RemoveEmptyEntries);
     if (MessageParts.Length == 0)
     {
         throw new Exception("Invalid HTTP Message Header");
     }
     MessageParts[0] += "\r\n";
     string[] HeaderArray = MessageParts[0].Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
     if (HeaderArray.Length == 0)
     {
         throw new Exception("Invalid HTTP Message Header");
     }
     FirstHeader = HeaderArray[0];
     if (FirstHeader.Length == 0)
     {
         throw new Exception("Invalid HTTP Message Header");
     }
     HeaderArray[0] = "";
     Headers        = new HeaderParameters(HeaderArray);
     if (MessageParts.Length == 2)
     {
         HasBody    = true;
         BodyString = MessageParts[1];
     }
 }
コード例 #2
0
ファイル: HTTPMessage.cs プロジェクト: kartikeyap/IronWASP
 public HTTPMessage(string HTTPInput)
 {
     int EndOfHeaders = HTTPInput.IndexOf("\r\n\r\n");
     if (EndOfHeaders < 0)
     {
         EndOfHeaders = HTTPInput.Length - 1;
     }
     string[] MessageParts = new string[] { "", "" };
     MessageParts[0] = HTTPInput.Substring(0, EndOfHeaders);
     try
     {
         MessageParts[1] = HTTPInput.Substring(EndOfHeaders + 4);
     }
     catch { }
     //string[] MessageParts = HTTPInput.Split(new string[] { "\r\n\r\n" }, 2, StringSplitOptions.RemoveEmptyEntries);
     if (MessageParts.Length == 0) throw new Exception("Invalid HTTP Message Header");
     MessageParts[0] += "\r\n";
     string[] HeaderArray = MessageParts[0].Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
     if (HeaderArray.Length == 0) throw new Exception("Invalid HTTP Message Header");
     FirstHeader = HeaderArray[0];
     if (FirstHeader.Length == 0) throw new Exception("Invalid HTTP Message Header");
     HeaderArray[0] = "";
     Headers = new HeaderParameters(HeaderArray);
     if (MessageParts.Length == 2)
     {
         HasBody = true;
         BodyString = MessageParts[1];
     }
 }
コード例 #3
0
        public static string GetResponseTriggerHighlighting(string Trigg, Response Res)
        {
            StringBuilder SB        = new StringBuilder();
            string        ResHeader = Res.GetHeadersAsString();
            string        ResBody   = Res.BodyString;

            List <string> AllTriggerVariations = new List <string>();

            AllTriggerVariations.Add(Trigg);
            if (!AllTriggerVariations.Contains(CookieParameters.Encode(Trigg)))
            {
                AllTriggerVariations.Add(CookieParameters.Encode(Trigg));
            }
            if (!AllTriggerVariations.Contains(HeaderParameters.Encode(Trigg)))
            {
                AllTriggerVariations.Add(HeaderParameters.Encode(Trigg));
            }

            try
            {
                List <string> HeaderAdjustments = GetHeaderVariations(Trigg, Res.Headers, ResHeader);
                foreach (string HA in HeaderAdjustments)
                {
                    if (!AllTriggerVariations.Contains(HA))
                    {
                        AllTriggerVariations.Add(HA);
                    }
                }
            }
            catch { }

            List <string> HeaderTriggerVariations = new List <string>();

            foreach (string CurrentVariation in AllTriggerVariations)
            {
                if (!HeaderTriggerVariations.Contains(CurrentVariation) && ResHeader.Contains(CurrentVariation))
                {
                    HeaderTriggerVariations.Add(CurrentVariation);
                }
            }
            ResHeader = Highlighter.InsertHighlights(ResHeader, HeaderTriggerVariations);

            ResBody = GetResponseBodyHighlighting(ResBody, Trigg);
            if (!ResHeader.Contains("<i<hlg>>") && !ResBody.Contains("<i<hlg>>"))
            {
                foreach (string TriggLine in Tools.SplitLines(Trigg))
                {
                    ResBody = GetResponseBodyHighlighting(ResBody, TriggLine);
                }
            }

            SB.Append(Highlighter.SnipHeaderSection(ResHeader).TrimEnd());
            SB.AppendLine(); SB.AppendLine();
            SB.Append(Highlighter.SnipBodySection(ResBody));
            return(SB.ToString().Replace("\n", "<i<br>>"));
        }
コード例 #4
0
 internal void CreateSetCookieListFromParameters(HeaderParameters Headers)
 {
     this.setCookies = new List <SetCookie>();
     if (Headers.Has("Set-Cookie"))
     {
         foreach (string SCString in Headers.GetAll("Set-Cookie"))
         {
             SetCookie SC = new SetCookie(SCString);
             this.SetCookies.Add(SC);
         }
     }
 }
コード例 #5
0
ファイル: HTTPMessage.cs プロジェクト: welias/IronWASP
 public HTTPMessage(string HTTPInput)
 {
     string[] MessageParts = HTTPInput.Split(new string[] { "\r\n\r\n" }, 2, StringSplitOptions.RemoveEmptyEntries);
     if (MessageParts.Length == 0) throw new Exception("Invalid HTTP Message Header");
     MessageParts[0] += "\r\n";
     string[] HeaderArray = MessageParts[0].Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
     if (HeaderArray.Length == 0) throw new Exception("Invalid HTTP Message Header");
     FirstHeader = HeaderArray[0];
     if (FirstHeader.Length == 0) throw new Exception("Invalid HTTP Message Header");
     HeaderArray[0] = "";
     Headers = new HeaderParameters(HeaderArray);
     if (MessageParts.Length == 2)
     {
         HasBody = true;
         BodyString = MessageParts[1];
     }
 }
コード例 #6
0
ファイル: HTTPMessage.cs プロジェクト: xuezs/IronWASP
        public HTTPMessage(string HTTPInput)
        {
            int EndOfHeaders = HTTPInput.IndexOf("\r\n\r\n");

            if (EndOfHeaders < 0)
            {
                EndOfHeaders = HTTPInput.Length;
            }
            string[] MessageParts = new string[] { "", "" };
            MessageParts[0] = HTTPInput.Substring(0, EndOfHeaders);
            try
            {
                MessageParts[1] = HTTPInput.Substring(EndOfHeaders + 4);
            }
            catch { }
            //string[] MessageParts = HTTPInput.Split(new string[] { "\r\n\r\n" }, 2, StringSplitOptions.RemoveEmptyEntries);
            if (MessageParts.Length == 0)
            {
                throw new Exception("Invalid HTTP Message Header");
            }
            MessageParts[0] += "\r\n";
            string[] HeaderArray = MessageParts[0].Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            if (HeaderArray.Length == 0)
            {
                throw new Exception("Invalid HTTP Message Header");
            }
            FirstHeader = HeaderArray[0];
            if (FirstHeader.Length == 0)
            {
                throw new Exception("Invalid HTTP Message Header");
            }
            HeaderArray[0] = "";
            Headers        = new HeaderParameters(HeaderArray);
            if (MessageParts.Length == 2)
            {
                HasBody    = true;
                BodyString = MessageParts[1];
            }
        }
コード例 #7
0
ファイル: HeaderParameters.cs プロジェクト: 0ks3ii/IronWASP
 internal HeaderParameters(HeaderParameters Headers)
 {
     this.ParameterStore = Headers.ParameterStore;
 }
コード例 #8
0
ファイル: Response.cs プロジェクト: kartikeyap/IronWASP
 internal void CreateSetCookieListFromParameters(HeaderParameters Headers)
 {
     this.setCookies = new List<SetCookie>();
     if (Headers.Has("Set-Cookie"))
     {
         foreach (string SCString in Headers.GetAll("Set-Cookie"))
         {
             SetCookie SC = new SetCookie(SCString);
             this.SetCookies.Add(SC);
         }
     }
 }
コード例 #9
0
 internal ResponseHeaderParameters(Response Response, HeaderParameters ResponseHeaders)
     : base(ResponseHeaders)
 {
     this.Response = Response;
     this.Response.CreateSetCookieListFromParameters(ResponseHeaders);
 }
コード例 #10
0
 internal HeaderParameters(HeaderParameters Headers)
 {
     this.ParameterStore = Headers.ParameterStore;
 }
コード例 #11
0
 internal RequestHeaderParameters(Request Request, HeaderParameters RequestHeaders) : base(RequestHeaders)
 {
     this.Request = Request;
 }
コード例 #12
0
ファイル: Finding.cs プロジェクト: 0ks3ii/IronWASP
        public static List<string> GetHeaderVariations(string Trigg, HeaderParameters Headers, string HeaderString)
        {
            List<string> FinalMatches = new List<string>();
            if (Trigg.Contains(":"))
            {
                string[] Parts = Trigg.Split(new char[] { ':' }, 2);
                string TrimmedName = Parts[0].Trim();
                string TrimmedValue = Parts[1].Trim();
                if (TrimmedName.Length > 0)
                {
                    List<string[]> Matches = new List<string[]>();
                    foreach (string Name in Headers.GetNames())
                    {
                        if (Name.Trim().Equals(TrimmedName, StringComparison.OrdinalIgnoreCase))
                        {
                            foreach (string Value in Headers.GetAll(Name))
                            {
                                if (Value.Trim().Equals(TrimmedValue))
                                {
                                    Matches.Add(new string[] { Name, Value });
                                }
                            }
                        }
                    }

                    List<string> Lines = Tools.SplitLines(HeaderString);
                    foreach (string Line in Lines)
                    {
                        foreach (string[] Match in Matches)
                        {
                            string EncodedName = "";
                            string EncodedValue = "";

                            if (Line.StartsWith(Match[0]))
                            {
                                EncodedName = Match[0];
                            }
                            else if (Line.StartsWith(RequestHeaderParameters.Encode(Match[0])))
                            {
                                EncodedName = RequestHeaderParameters.Encode(Match[0]);
                            }
                            else if (Line.StartsWith(ResponseHeaderParameters.Encode(Match[0])))
                            {
                                EncodedName = ResponseHeaderParameters.Encode(Match[0]);
                            }

                            if (Line.EndsWith(Match[1]))
                            {
                                EncodedValue = Match[1];
                            }
                            else if (Line.EndsWith(RequestHeaderParameters.Encode(Match[1])))
                            {
                                EncodedValue = RequestHeaderParameters.Encode(Match[1]);
                            }
                            else if (Line.EndsWith(ResponseHeaderParameters.Encode(Match[1])))
                            {
                                EncodedValue = ResponseHeaderParameters.Encode(Match[1]);
                            }

                            if (EncodedValue.Length > 0)//If EncodedValue is empty then .Replace(EncodedValue, "") throws an exception, as empty value cannot be replaced
                            {
                                if (Line.Substring(EncodedName.Length).Replace(EncodedValue, "").Trim().Equals(":"))
                                {
                                    FinalMatches.Add(Line);
                                }
                            }
                            else
                            {
                                if (Line.Substring(EncodedName.Length).Trim().Equals(":"))
                                {
                                    FinalMatches.Add(Line);
                                }
                            }
                        }
                    }
                }
            }
            return FinalMatches;
        }
コード例 #13
0
 internal ResponseHeaderParameters(Response Response, HeaderParameters ResponseHeaders) : base(ResponseHeaders)
 {
     this.Response = Response;
     this.Response.CreateSetCookieListFromParameters(ResponseHeaders);
 }
コード例 #14
0
 internal RequestHeaderParameters(Request Request, HeaderParameters RequestHeaders)
     : base(RequestHeaders)
 {
     this.Request = Request;
 }
コード例 #15
0
        public static List <string> GetHeaderVariations(string Trigg, HeaderParameters Headers, string HeaderString)
        {
            List <string> FinalMatches = new List <string>();

            if (Trigg.Contains(":"))
            {
                string[] Parts        = Trigg.Split(new char[] { ':' }, 2);
                string   TrimmedName  = Parts[0].Trim();
                string   TrimmedValue = Parts[1].Trim();
                if (TrimmedName.Length > 0)
                {
                    List <string[]> Matches = new List <string[]>();
                    foreach (string Name in Headers.GetNames())
                    {
                        if (Name.Trim().Equals(TrimmedName, StringComparison.OrdinalIgnoreCase))
                        {
                            foreach (string Value in Headers.GetAll(Name))
                            {
                                if (Value.Trim().Equals(TrimmedValue))
                                {
                                    Matches.Add(new string[] { Name, Value });
                                }
                            }
                        }
                    }

                    List <string> Lines = Tools.SplitLines(HeaderString);
                    foreach (string Line in Lines)
                    {
                        foreach (string[] Match in Matches)
                        {
                            string EncodedName  = "";
                            string EncodedValue = "";

                            if (Line.StartsWith(Match[0]))
                            {
                                EncodedName = Match[0];
                            }
                            else if (Line.StartsWith(RequestHeaderParameters.Encode(Match[0])))
                            {
                                EncodedName = RequestHeaderParameters.Encode(Match[0]);
                            }
                            else if (Line.StartsWith(ResponseHeaderParameters.Encode(Match[0])))
                            {
                                EncodedName = ResponseHeaderParameters.Encode(Match[0]);
                            }

                            if (Line.EndsWith(Match[1]))
                            {
                                EncodedValue = Match[1];
                            }
                            else if (Line.EndsWith(RequestHeaderParameters.Encode(Match[1])))
                            {
                                EncodedValue = RequestHeaderParameters.Encode(Match[1]);
                            }
                            else if (Line.EndsWith(ResponseHeaderParameters.Encode(Match[1])))
                            {
                                EncodedValue = ResponseHeaderParameters.Encode(Match[1]);
                            }

                            if (EncodedValue.Length > 0)//If EncodedValue is empty then .Replace(EncodedValue, "") throws an exception, as empty value cannot be replaced
                            {
                                if (Line.Substring(EncodedName.Length).Replace(EncodedValue, "").Trim().Equals(":"))
                                {
                                    FinalMatches.Add(Line);
                                }
                            }
                            else
                            {
                                if (Line.Substring(EncodedName.Length).Trim().Equals(":"))
                                {
                                    FinalMatches.Add(Line);
                                }
                            }
                        }
                    }
                }
            }
            return(FinalMatches);
        }