Exemple #1
0
        /// <summary>
        /// Adds a request to the current Traffic Viewer File
        /// </summary>
        /// <param name="request"></param>
        /// <param name="description"></param>
        private void AddAppScanRequest(XmlNode request, string description)
        {
            TVRequestInfo reqInfo = new TVRequestInfo();

            reqInfo.Description = description;
            reqInfo.IsHttps     = request.Attributes["scheme"] != null && request.Attributes["scheme"].Equals("https");
            reqInfo.ThreadId    = Properties.Resources.Settings;

            XmlNode rawRequestNode = request.SelectSingleNode("raw");

            byte[] rawRequestBytes = new byte[0];
            if (rawRequestNode.Attributes["encoding"] != null && rawRequestNode.Attributes["encoding"].Value.Equals("none"))
            {
                string rawRequest = String.Empty;
                rawRequest      = rawRequestNode.InnerText;
                rawRequestBytes = Constants.DefaultEncoding.GetBytes(rawRequest);
            }
            reqInfo.RequestLine = HttpRequestInfo.GetRequestLine(rawRequestBytes);
            reqInfo.Id          = _tvFile.AddRequestInfo(reqInfo);
            _tvFile.SaveRequest(reqInfo.Id, rawRequestBytes);

            XmlNode response = request.SelectSingleNode("response");

            //put together the response

            if (response != null)
            {
                ByteArrayBuilder builder     = new ByteArrayBuilder();
                XmlNode          headersNode = response.SelectSingleNode("headers");
                if (headersNode != null && headersNode.Attributes["value"] != null)
                {
                    builder.AddChunkReference(Constants.DefaultEncoding.GetBytes(headersNode.Attributes["value"].Value));
                }

                XmlNode bodyNode = response.SelectSingleNode("body");
                if (bodyNode != null)
                {
                    bool isCompressed = bodyNode.Attributes["compressedBinaryValue"] != null && bodyNode.Attributes["compressedBinaryValue"].Value == "true";


                    string body      = bodyNode.Attributes["value"].Value;
                    byte[] bodyBytes = new byte[0];
                    if (isCompressed)
                    {
                        bodyBytes = Utils.DecompressBytesFromBase64String(body);
                    }
                    else
                    {
                        body      = Utils.Base64Decode(body);
                        bodyBytes = Constants.DefaultEncoding.GetBytes(body);
                    }
                    builder.AddChunkReference(bodyBytes);
                }
                _tvFile.SaveResponse(reqInfo.Id, builder.ToArray());
            }
        }
 private void HandleFirstRequestLine(string line, byte[] lineBytes)
 {
     _currentThreadInfo.Location = LocationInThread.InsideRequest;
     //if a current request already exists in the thread this is end of that request
     //except in the case of AppScan standard where manual explore requests are doubled
     if (!Utils.IsMatch(_currentThreadInfo.Description, _proxyConnectionToSiteRegex) &&
         _currentThreadInfo.CurrentRequests.Count > 0)
     {
         KeyValuePair <int, RequestResponseBytes> top = _currentThreadInfo.CurrentRequests.Pop();
         TVRequestInfo header = _trafficViewerFile.GetRequestInfo(top.Key);
         if (header != null)
         {
             if (top.Value.RawResponse == null)                    //there is no response, time out
             {
                 if (top.Value.RequestSize > header.RequestLength)
                 {
                     _trafficViewerFile.SaveRequest(top.Key, top.Value);
                 }
             }
             else
             {
                 //the request was already saved save the response if necessary
                 if (top.Value.ResponseSize > header.ResponseLength)
                 {
                     _trafficViewerFile.SaveResponse(top.Key, top.Value);
                 }
             }
             //this concludes the current request update the requests counter
             _thisSessionRequestCount++;
         }
     }
     //discard exclusions
     if (IsExcluded(line))
     {
         _currentThreadInfo.Location = LocationInThread.Exclusion;
         return;
     }
     //create new request header
     _currentHeader             = new TVRequestInfo();
     _currentHeader.Description = _currentThreadInfo.Description;
     _currentHeader.ThreadId    = _currentThreadInfo.ThreadId;
     _currentHeader.RequestLine = line;
     try
     {
         _currentHeader.RequestTime = DateTime.ParseExact(_currentTime, _timeFormat, _dateTimeFormatInfo);
     }
     catch { }
     //save newly created request header to the list of headers
     _currentIndex = _trafficViewerFile.AddRequestInfo(_currentHeader);
     if (lineBytes != null)             //if lineBytes is null we are using the _currentRequestData
     {
         //create new requestdata
         _currentRequestData = new RequestResponseBytes();
         _currentRequestData.AddToRequest(lineBytes);
     }
     _isNewThreadChunk = false;
     //push request header and request data to the stack of active requests for the current thread
     _currentThreadInfo.CurrentRequests.Push(new KeyValuePair <int, RequestResponseBytes>(_currentIndex, _currentRequestData));
     //since a request line was encountered we are inside a request from now on
 }
Exemple #3
0
        private void AddRequest(ITrafficDataAccessor currentFile, Uri uri, string fullQuery, string format)
        {
            string          request     = String.Format(format, uri.AbsolutePath, fullQuery, uri.Host, uri.Port);
            HttpRequestInfo requestInfo = new HttpRequestInfo(request);
            TVRequestInfo   tvReqInfo   = new TVRequestInfo();

            tvReqInfo.Description = Resources.UriParserDescription;
            tvReqInfo.RequestLine = HttpRequestInfo.GetRequestLine(request);
            tvReqInfo.ThreadId    = "N/A";
            tvReqInfo.RequestTime = DateTime.Now;
            tvReqInfo.IsHttps     = String.Compare(uri.Scheme, "https", true) == 0;
            currentFile.AddRequestInfo(tvReqInfo);
            currentFile.SaveRequest(tvReqInfo.Id, requestInfo.ToArray(false));
        }
Exemple #4
0
        /// <summary>
        /// Adds a request to the data accessor
        /// </summary>
        /// <param name="request"></param>
        private void AddHttpRequest(HttpRequestInfo request)
        {
            var reqInfo = new TVRequestInfo();

            reqInfo.Host    = request.Host;
            reqInfo.IsHttps = request.IsSecure;

            byte [] rawRequest = request.ToArray();

            reqInfo.RequestLine = HttpRequestInfo.GetRequestLine(rawRequest);
            reqInfo.Description = "Script Explore";

            var id = _curDataAccessor.AddRequestInfo(reqInfo);

            _curDataAccessor.SaveRequest(id, rawRequest);
        }
Exemple #5
0
        private void AddRequest(ITrafficDataAccessor currentFile, Entry entry)
        {
            Uri uri = entry.Request.Url;
            //check exclusions
            Request         harRequest  = entry.Request;
            string          request     = String.Format("{0} {1} {2}\r\n\r\n", harRequest.Method, uri.PathAndQuery, harRequest.HttpVersion);
            HttpRequestInfo requestInfo = new HttpRequestInfo(request);

            //add the headers
            foreach (var header in harRequest.Headers)
            {
                if (!header.Name.ToLower().Equals("accept-encoding") &&
                    !header.Name.ToLower().Equals("if-modified-since") &&
                    !header.Name.ToLower().Equals("if-none-match"))
                {
                    requestInfo.Headers.Add(header.Name, header.Value);
                }
            }
            if (harRequest.PostData != null)
            {
                requestInfo.ContentData = Constants.DefaultEncoding.GetBytes(harRequest.PostData.Text);
            }
            TVRequestInfo tvReqInfo = new TVRequestInfo();

            tvReqInfo.Description = Resources.HarParserDescription;
            tvReqInfo.RequestLine = HttpRequestInfo.GetRequestLine(request);
            tvReqInfo.ThreadId    = "N/A";
            tvReqInfo.RequestTime = DateTime.Now;
            tvReqInfo.IsHttps     = String.Compare(uri.Scheme, "https", true) == 0;
            tvReqInfo.Host        = uri.Host;

            Response         harResponse  = entry.Response;
            string           responseHead = String.Format("{0} {1}\r\n\r\n", harResponse.HttpVersion, harResponse.Status);
            HttpResponseInfo respInfo     = new HttpResponseInfo(responseHead);

            foreach (var header in harResponse.Headers)
            {
                respInfo.Headers.Add(header.Name, header.Value);
            }
            if (harResponse.Content != null && !String.IsNullOrWhiteSpace(harResponse.Content.Text))
            {
                respInfo.ResponseBody.AddChunkReference(Constants.DefaultEncoding.GetBytes(harResponse.Content.Text));
            }

            currentFile.AddRequestInfo(tvReqInfo);
            currentFile.SaveRequestResponse(tvReqInfo.Id, requestInfo.ToArray(false), respInfo.ToArray());
        }