コード例 #1
0
ファイル: LogAnalyzer.cs プロジェクト: war-and-code/IronWASP
        List <LogAssociation> FindFormSubmitAssociations(Session MainLog, List <Session> SessionList, RefererAssociationType RefAssoType)
        {
            List <LogAssociation> Associations = new List <LogAssociation>();

            if (MainLog.Response == null)
            {
                return(Associations);
            }

            //Match form submission with absolute url match and absolute field/values match
            foreach (IronHtml.FormElement FormEle in MainLog.Response.Html.GetFormElements())
            {
                try
                {
                    Request FormReq = new Request(FormEle.Action);
                    foreach (Session Sess in SessionList)
                    {
                        if (!Sess.Request.IsNormal)
                        {
                            continue;
                        }
                        if (Sess.Request.FullUrl.Equals(FormReq.FullUrl) && Sess.Request.Method.Equals(FormEle.Method, StringComparison.OrdinalIgnoreCase) && Sess.Response != null)
                        {
                            if (FormEle.DoAllInputFieldValuesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.FormNamesAndValues, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else if (FormEle.DoHiddenInputFieldValuesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.FormNamesAndHiddenValuesOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else if (FormEle.DoInputFieldNamesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullAbsolute, LogAssociationMatchLevel.FormNamesOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                        }
                    }
                }
                catch
                {
                    Request FormReq = new Request(MainLog.Request.RelativeUrlToAbsoluteUrl(FormEle.Action));
                    foreach (Session Sess in SessionList)
                    {
                        if (!Sess.Request.IsNormal)
                        {
                            continue;
                        }
                        if (Sess.Request.FullUrl.Equals(FormReq.FullUrl) && Sess.Request.Method.Equals(FormEle.Method, StringComparison.OrdinalIgnoreCase) && Sess.Response != null)
                        {
                            if (FormEle.DoAllInputFieldValuesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.FormNamesAndValues, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else if (FormEle.DoHiddenInputFieldValuesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.FormNamesAndHiddenValuesOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                            else if (FormEle.DoInputFieldNamesMatchRequest(Sess.Request))
                            {
                                LogAssociation LogAsso = new LogAssociation(LogAssociationType.FormSubmission, RefAssoType, IronHtml.UrlInHtmlMatch.FullRelative, LogAssociationMatchLevel.FormNamesOnly, MainLog, Sess);
                                Associations.Add(LogAsso);
                            }
                        }
                    }
                }
            }
            return(Associations);
        }
コード例 #2
0
ファイル: LogReplayer.cs プロジェクト: war-and-code/IronWASP
        Request GetFormSubmission(LogAssociation CurrentAsso, Session PlaySess)
        {
            Response Res = PlaySess.Response;
            List <IronHtml.FormElement> BestMatches       = new List <IronHtml.FormElement>();
            List <IronHtml.FormElement> SecondBestMatches = new List <IronHtml.FormElement>();

            IronHtml.FormElementCollection NewFormElements = new IronHtml.FormElementCollection(Res.Html.GetFormElements());

            Request ReqToMatchAgainst = CurrentAsso.DestinationLog.Request;

            //List<IronHtml.FormElement> FormElements = CurrentAsso.DestinationLog.Response.Html.GetFormElements();
            foreach (IronHtml.FormElement FormEle in CurrentAsso.SourceLog.Response.Html.GetFormElements())
            {
                if (FormEle.DoAllInputFieldValuesMatchRequest(ReqToMatchAgainst))
                {
                    BestMatches.Add(FormEle);
                }
                else if (FormEle.DoHiddenInputFieldValuesMatchRequest(ReqToMatchAgainst))
                {
                    BestMatches.Add(FormEle);
                }
                else if (FormEle.DoInputFieldNamesMatchRequest(ReqToMatchAgainst))
                {
                    SecondBestMatches.Add(FormEle);
                }
            }

            foreach (List <IronHtml.FormElement> Matches in new List <List <IronHtml.FormElement> >()
            {
                BestMatches, SecondBestMatches
            })
            {
                //check by link id
                foreach (IronHtml.FormElement FormEle in Matches)
                {
                    if (FormEle.HasId)
                    {
                        List <IronHtml.Element> MatchingForms = NewFormElements.GetElementsWithId(FormEle.Id);
                        if (MatchingForms.Count > 0 && ((IronHtml.FormElement)MatchingForms[0]).DoInputFieldNamesMatchRequest(ReqToMatchAgainst))
                        {
                            return(((IronHtml.FormElement)MatchingForms[0]).GetFormSubmissionWithHiddenValuesFromFormAndOtherFromSecondArgument(PlaySess.Request, ReqToMatchAgainst));
                        }
                    }
                }
                //check by link name
                foreach (IronHtml.FormElement FormEle in Matches)
                {
                    if (FormEle.HasName)
                    {
                        List <IronHtml.Element> MatchingForms = NewFormElements.GetElementsWithName(FormEle.Name);
                        if (MatchingForms.Count > 0 && ((IronHtml.FormElement)MatchingForms[0]).DoInputFieldNamesMatchRequest(ReqToMatchAgainst))
                        {
                            return(((IronHtml.FormElement)MatchingForms[0]).GetFormSubmissionWithHiddenValuesFromFormAndOtherFromSecondArgument(PlaySess.Request, ReqToMatchAgainst));
                        }
                    }
                }
            }

            foreach (IronHtml.FormElement NewFormEle in NewFormElements.GetElements())
            {
                if (NewFormEle.DoInputFieldNamesMatchRequest(ReqToMatchAgainst))
                {
                    return(NewFormEle.GetFormSubmissionWithHiddenValuesFromFormAndOtherFromSecondArgument(PlaySess.Request, ReqToMatchAgainst));
                }
            }

            return(null);
        }