protected override void ActionFunction(TVRequestInfo curReqInfo) { int index = -1; TVRequestInfo tvInfo; var curReqData = _dataSource.LoadRequestData(curReqInfo.Id); if (curReqData == null) { ErrorBox.ShowDialog("No request data for selected request"); } HttpRequestInfo curHttpReqInfo = new HttpRequestInfo(curReqData); while ((tvInfo = _dataSource.GetNext(ref index)) != null) { if (tvInfo.Id != curReqInfo.Id) { //replicate the headers byte[] reqData = _dataSource.LoadRequestData(tvInfo.Id); HttpRequestInfo reqInfo = new HttpRequestInfo(reqData); reqInfo.Headers = new HTTPHeaders(); reqInfo.Cookies.Clear(); foreach (var header in curHttpReqInfo.Headers) { reqInfo.Headers.Add(header.Name, header.Values.ToArray()); } _dataSource.SaveRequest(tvInfo.Id, reqInfo.ToArray(false)); } } }
/// <summary> /// Adds the request to the proxy data store /// </summary> protected void AddRequestToDataStore() { TVRequestInfo currDataStoreRequestInfo = new TVRequestInfo(); currDataStoreRequestInfo.RequestLine = _requestInfo.RequestLine; currDataStoreRequestInfo.Description = _requestDescription; currDataStoreRequestInfo.RequestTime = _currentRequestTime; currDataStoreRequestInfo.ThreadId = Utils.GetCurrentWin32ThreadId().ToString(); currDataStoreRequestInfo.IsHttps = _requestInfo.IsSecure; currDataStoreRequestInfo.Host = _requestInfo.Host; int reqId = TrafficDataStore.AddRequestInfo(currDataStoreRequestInfo); if (reqId != -1) { _currentRequestResponseBytes = new RequestResponseBytes(); _currentRequestResponseBytes.AddToRequest(_requestInfo.ToArray(false)); //saving the request in a direct to site format, since it will come //in proxy format GET http://site.com/ rather than GET /, //if we need a server to connect to the target the client will handle that TrafficDataStore.SaveRequest(reqId, _currentRequestResponseBytes); _currDataStoreRequestInfo = TrafficDataStore.GetRequestInfo(reqId); } }
/// <summary> /// Loads data into selected view /// </summary> private void LoadSelectedView() { if (_control.SelectedTab == RequestViewerTabs.HttpTraffic) { _control.CrossThreadPopulateTrafficView(_requestText, _responseText); } if (_control.SelectedTab == RequestViewerTabs.Entities) { _control.LoadEntitiesView(_currentId, _dataSource, _requestText); } else if (_control.SelectedTab == RequestViewerTabs.Browser || _control.SelectedTab == RequestViewerTabs.DOM) { if (_responseBytes != null && _responseBytes.Length > 0) { _control.NavigateBrowser(_dataSource.GetRequestInfo(_currentId), _responseBytes); } } else if (_control.SelectedTab == RequestViewerTabs.LogSync) { TVRequestInfo reqHeader = _dataSource.GetRequestInfo(_currentId); if (reqHeader != null) { _control.LogSyncViewEvent = reqHeader.RequestTime; } } }
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 }
/// <summary> /// Gets a memory stream to search in for the specified context /// </summary> /// <param name="dataSource"></param> /// <param name="header"></param> /// <param name="context"></param> /// <returns></returns> protected MemoryStream GetMemoryStream(ITrafficDataAccessor dataSource, TVRequestInfo header, SearchContext context) { MemoryStream toBeSearched; if (context == SearchContext.Request || context == SearchContext.RequestBody) { toBeSearched = new MemoryStream(dataSource.LoadRequestData(header.Id)); } else if (context == SearchContext.Response) { toBeSearched = new MemoryStream(dataSource.LoadResponseData(header.Id)); } else { toBeSearched = new MemoryStream(); byte[] data = dataSource.LoadRequestData(header.Id); toBeSearched.Write(data, 0, data.Length); data = Constants.DefaultEncoding.GetBytes(Environment.NewLine); toBeSearched.Write(data, 0, data.Length); data = dataSource.LoadResponseData(header.Id); toBeSearched.Write(data, 0, data.Length); //reset the prosition so readline can start from the beggining toBeSearched.Position = 0; } return(toBeSearched); }
public void EditARequest() { string originalRequest = "GET / HTTP/1.1"; string originalResponse = "HTTP/1.1 200 OK"; TrafficViewerFile file = new TrafficViewerFile(); int reqId = file.AddRequestResponse(originalRequest, originalResponse); Assert.AreEqual(1, file.RequestCount); TVRequestInfo reqInfo = file.GetRequestInfo(reqId); string newRequest = "POST /login HTTP/1.1"; string newResponse = "HTTP/1.1 302 Redirect"; file.SaveRequest(reqId, Encoding.UTF8.GetBytes(newRequest)); file.SaveResponse(reqId, Encoding.UTF8.GetBytes(newResponse)); //check the response info was updated Assert.AreEqual(newRequest, reqInfo.RequestLine); Assert.AreEqual("302", reqInfo.ResponseStatus); Assert.AreEqual(newRequest.Length, reqInfo.RequestLength); Assert.AreEqual(newResponse.Length, reqInfo.ResponseLength); string loadedRequest = Encoding.UTF8.GetString(file.LoadRequestData(reqId)); Assert.AreEqual(newRequest, loadedRequest); string loadedResponse = Encoding.UTF8.GetString(file.LoadResponseData(reqId)); Assert.AreEqual(newResponse, loadedResponse); file.Close(false); }
private void HandleSendingRequestLine(string line) { byte[] bytes; bytes = ReadNextBytes(line, _sendingRequestRegex); if (bytes != null) { if (_currentRequestData == null || _currentRequestData.RawResponse != null) { _currentRequestData = new RequestResponseBytes(); _currentHeader = null; } _currentRequestData.AddToRequest(bytes); //check if this the start of a new request if (_currentHeader == null || String.IsNullOrEmpty(_currentHeader.RequestLine)) { string reqLine = HttpRequestInfo.GetRequestLine(_currentRequestData.RawRequest); //check if it's recognized as a valid request line if (_lineTypeSelector.GetLineType(reqLine) == LineType.FirstRequestLine) { HandleFirstRequestLine(reqLine, null); } } } }
/// <summary> /// Sends http request asynchroneusly /// </summary> /// <param name="param"></param> private void SendAsync(object param) { object[] paramArray = param as object[]; if (paramArray == null || paramArray.Length != 2) { return; } ITrafficDataAccessor source = paramArray[0] as ITrafficDataAccessor; Queue <TVRequestInfo> requestsToSend = paramArray[1] as Queue <TVRequestInfo>; if (source == null || requestsToSend == null) { return; } while (true) { TVRequestInfo info = null; lock (_lock) { if (requestsToSend.Count == 0) { return; } info = requestsToSend.Dequeue(); } if (info != null) { SendRequest(source, info); } } }
public void TestRequestLineAfterReplace() { TrafficViewer.Instance.NewTvf(); ITrafficDataAccessor tvf = TrafficViewer.Instance.TrafficViewerFile; string firstRequest = "GET http://site.com/a1 HTTP/1.1\r\nHeader1: a1"; tvf.AddRequestResponse(firstRequest, String.Empty); TVRequestInfo reqInfo = tvf.GetRequestInfo(0); Assert.AreEqual("GET http://site.com/a1 HTTP/1.1", reqInfo.RequestLine); Assert.AreEqual(1, tvf.RequestCount); LineSearcher searcher = new LineSearcher(); LineMatches result = new LineMatches(); SearchCriteriaSet criteriaSet = new SearchCriteriaSet(); criteriaSet.Add(new SearchCriteria(SearchContext.RequestLine, true, "a1|a=2|<r>2</r>")); searcher.Search(tvf, criteriaSet, result); tvf.Replace(result, "replacement"); firstRequest = Constants.DefaultEncoding.GetString(tvf.LoadRequestData(0)); Assert.AreEqual("GET http://site.com/replacement HTTP/1.1\r\nHeader1: a1", firstRequest); Assert.AreEqual("GET http://site.com/replacement HTTP/1.1", reqInfo.RequestLine); }
//[TestMethod] public void TestLoginExportType() { TempFile temp = new TempFile(); temp.Write(Resources.AltoroLogin); TrafficViewerFile origFile = new TrafficViewerFile(); origFile.Open(temp.Path); Assert.AreEqual(4, origFile.RequestCount); //export IList <ITrafficExporter> exporters = TrafficViewer.Instance.TrafficExporters; ITrafficExporter loginExporter = null; foreach (ITrafficExporter exporter in exporters) { if (exporter.Caption == "ASE Login Files (.login)") { loginExporter = exporter; } } Assert.IsNotNull(loginExporter); TempFile exportedFile = new TempFile("exporttest.login"); Stream stream = exportedFile.OpenStream(); loginExporter.Export(origFile, stream, "demo.testfire.net", 80); stream.Close(); //import the exported file TrafficViewerFile import = new TrafficViewerFile(); ITrafficParser configurationParser = TrafficViewer.Instance.GetParser("Configuration Parser"); Assert.IsNotNull(configurationParser); configurationParser.Parse(exportedFile.Path, import, ParsingOptions.GetLegacyAppScanProfile()); Assert.AreEqual(origFile.RequestCount, import.RequestCount); int i = -1; TVRequestInfo origInfo; while ((origInfo = origFile.GetNext(ref i)) != null) { TVRequestInfo importInfo = import.GetRequestInfo(origInfo.Id); string origRequest = Constants.DefaultEncoding.GetString(origFile.LoadRequestData(origInfo.Id)); string importedRequest = Constants.DefaultEncoding.GetString(import.LoadRequestData(origInfo.Id)); Assert.AreEqual(origRequest, importedRequest); } }
private void TrafficViewSaveRequested(RequestTrafficViewSaveArgs e) { if (_currentId > -1) { //update the request info //parse the data HttpRequestInfo reqInfo = new HttpRequestInfo(e.Request); _responseBytes = Constants.DefaultEncoding.GetBytes(e.Response); HttpResponseInfo respInfo = new HttpResponseInfo(); respInfo.ProcessResponse(_responseBytes); TVRequestInfo currentTVInfo = _dataSource.GetRequestInfo(_currentId); //do not set the dom uniqueness id, needs to be explicitly calculated currentTVInfo.DomUniquenessId = String.Empty; currentTVInfo.RequestLine = reqInfo.RequestLine; currentTVInfo.RequestTime = DateTime.Now; currentTVInfo.ResponseStatus = respInfo.Status.ToString(); currentTVInfo.ResponseTime = DateTime.Now; currentTVInfo.Description = "Traffic Viewer Request"; currentTVInfo.ThreadId = "[0000]"; //convert the strings to bytes RequestResponseBytes reqData = new RequestResponseBytes(); reqData.AddToRequest(Constants.DefaultEncoding.GetBytes(e.Request)); reqData.AddToResponse(_responseBytes); //save the requests to the current data source _dataSource.SaveRequest(_currentId, reqData); _dataSource.SaveResponse(_currentId, reqData); _requestText = e.Request; _responseText = e.Response; } }
private void AddRequestToFuzz(string requestToFuzz, TVRequestInfo tvInfo) { if (!_requestsToFuzz.ContainsKey(requestToFuzz)) { _requestsToFuzz.Add(requestToFuzz, tvInfo); } }
/// <summary> /// Traps the response and triggers the event for the current thread /// </summary> /// <param name="tvReqInfo"></param> /// <param name="httpRespInfo"></param> /// <returns>True of False if the request was trapped or not</returns> public bool TrapResponse(TVRequestInfo tvReqInfo, HttpResponseInfo httpRespInfo) { if (_trapResponses) { //trigger the event, if (_responseTrapped != null) { string rawResponse = httpRespInfo.ToString(); if (MatchesTrapDefs(httpRespInfo)) { ManualResetEvent reqLock = new ManualResetEvent(false); _trapOn.BeginInvoke(this, new EventArgs(), null, null); _responseTrapped.BeginInvoke(new RequestTrapEventEventArgs(tvReqInfo, httpRespInfo, reqLock), null, null); //wait for the event to finish reqLock.WaitOne(); _trapOff.BeginInvoke(this, new EventArgs(), null, null); //the request was trapped return true return(true); } } } return(false); }
private void HandleFirstResponseLine(string line, byte[] lineBytes) { //if you are inside an exclusion discard if (_currentThreadInfo.Location == LocationInThread.Exclusion) { return; } //if you never had a request before discard if (_currentIndex < 0) { return; } //save current request if (_currentRequestData.RawRequest != null) { if (_currentHeader != null && _currentHeader.RequestLength < _currentRequestData.RequestSize) { _trafficViewerFile.SaveRequest(_currentIndex, _currentRequestData); } } //handle the case when there are two or more subsequent responses on the same thread(AppScan Manual Explore) //the fact that we still have more than one requests in this threads stack means we //didn't finish to process the first while (_currentRequestData.RawResponse != null && _currentThreadInfo.CurrentRequests.Count > 1) { //the fact that we are now receiving the second response means that the first request is complete //extract the first request from the stack of current requests of the thread, save it and drop it KeyValuePair <int, RequestResponseBytes> top = _currentThreadInfo.CurrentRequests.Pop(); TVRequestInfo header = _trafficViewerFile.GetRequestInfo(top.Key); //save the response only if it has changed since last if (top.Value.ResponseSize > header.ResponseLength) { _trafficViewerFile.SaveResponse(top.Key, top.Value); } //update the request counter _thisSessionRequestCount++; //set the _currentRequestData to the next request data in the stack _currentRequestData = _currentThreadInfo.CurrentRequests.Peek().Value; _currentIndex = _currentThreadInfo.CurrentRequests.Peek().Key; _currentHeader = _trafficViewerFile.GetRequestInfo(_currentIndex); } if (lineBytes != null) { _currentRequestData.AddToResponse(lineBytes); } _isNewThreadChunk = false; _currentHeader.ResponseStatus = Utils.RegexFirstGroupValue(line, _responseStatusRegex); try { _currentHeader.ResponseTime = DateTime.ParseExact(_currentTime, _timeFormat, _dateTimeFormatInfo); } catch { } _currentThreadInfo.Location = LocationInThread.InsideResponse; }
protected override void ActionFunction(TVRequestInfo curReqInfo) { while (curReqInfo != null && curReqInfo.RefererId != -1) { _requestList.Select(curReqInfo.RefererId, false); curReqInfo = _dataSource.GetRequestInfo(curReqInfo.RefererId); } }
/// <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()); } }
/// <summary> /// Sends all the requests in the attached file /// </summary> /// <param name="source"></param> public void Send(ITrafficDataAccessor source) { int id = -1; TVRequestInfo info = null; PatternTracker.Instance.PatternsToTrack = source.Profile.GetTrackingPatterns(); while ((info = source.GetNext(ref id)) != null) { SendRequest(source, info); } }
/// <summary> /// Navigates the browser control to a temporary resource containing the response bytes /// </summary> /// <param name="requestHeader">The request information</param> /// <param name="fullResponse">The full response</param> public void Navigate(TVRequestInfo requestHeader, byte[] fullResponse) { if (requestHeader == null) { return; } HttpResponseInfo respInfo = new HttpResponseInfo(); respInfo.ProcessResponse(fullResponse); byte [] fileContent = GetResponseBody(respInfo); if (_responseBytes == fileContent) { return; //this response is already displayed } _responseBytes = fileContent; if (_responseBytes != null) { //extract the file name from the request header string reqLine = requestHeader.RequestLine; int index = reqLine.IndexOf(' '); //after the first space follows the uri reqLine = reqLine.Substring(index + 1); string tempFileName = Utils.GetFileNameFromUri(reqLine); //attach .htm to certain extensions or if the file doesn't have an extension if (Utils.IsMatch(tempFileName, SCRIPTING_LANGUAGES_EXTENSION) || !tempFileName.Contains(".")) { tempFileName += HTM_EXTENSION; } //if the overriding extension is set append it tempFileName += ExtensionOverride; //we don't care if the file name is empty, the temp file class will handle this case try { //create a temp file _temp = new TempFile(tempFileName); _temp.Write(_responseBytes); _webBrowser.Navigate(_temp.Url); } catch { } } else { _webBrowser.Navigate("about:blank"); } }
public void EditTVF() { TrafficViewerFile tvf = UnitTestUtils.GenerateTestTvf(); //check delete int initialCount = tvf.RequestCount; //get the first request id int i = -1; TVRequestInfo first = tvf.GetNext(ref i); TVRequestInfo second = tvf.GetNext(ref i); HttpRequestInfo secondRequest = new HttpRequestInfo(tvf.LoadRequestData(second.Id)); HttpResponseInfo secondResponse = new HttpResponseInfo(); byte [] respBytes = tvf.LoadResponseData(second.Id); secondResponse.ProcessResponse(respBytes); int referenceResponseStatus = secondResponse.Status; int referenceHash = secondRequest.GetHashCode(); Assert.IsTrue(tvf.RemoveRequest(first.Id)); Assert.AreEqual(initialCount - 1, tvf.RequestCount); Assert.IsNull(tvf.GetPrevious(ref i)); RequestDataCache.Instance.Clear(); //check that //check add TVRequestInfo reqInfo = new TVRequestInfo(); reqInfo.RequestLine = "GET /newrequest HTTP/1.1"; string request = "GET /newrequest HTTP/1.1\r\nHeader1:1\r\n\r\n"; string response = "HTTP 200 OK\r\nHeader1:1\r\n\r\n<html><body>Added request</body></html>"; RequestResponseBytes reqData = new RequestResponseBytes(); reqData.AddToRequest(Constants.DefaultEncoding.GetBytes(request)); reqData.AddToResponse(Constants.DefaultEncoding.GetBytes(response)); tvf.AddRequestInfo(reqInfo); tvf.SaveRequest(reqInfo.Id, reqData); tvf.SaveResponse(reqInfo.Id, reqData); //Check that the request was added response = Constants.DefaultEncoding.GetString(tvf.LoadResponseData(reqInfo.Id)); Assert.AreEqual(38, response.IndexOf("Added request")); Assert.AreEqual(65, response.Length); //modify the recently added request slightly }
public string SendTest(string mutatedRequest, string host, int port, bool useSSL) { HttpRequestInfo reqInfo = new HttpRequestInfo(mutatedRequest, false); reqInfo.IsSecure = useSSL; reqInfo.Host = host; reqInfo.Port = port; IHttpClient client = _httpClientFactory.MakeClient(); client.SetNetworkSettings(_netSettings); DateTime reqTime = DateTime.Now; HttpResponseInfo resp = null; TVRequestInfo tvReqInfo = null; if (_verbose) { tvReqInfo = SaveRequest("Custom Test", reqInfo, useSSL, String.Empty, reqTime, reqTime, ""); } try { resp = client.SendRequest(reqInfo); } catch { } DateTime respTime = DateTime.Now; string response; if (resp != null) { PatternTracker.Instance.UpdatePatternValues(resp); response = resp.ToString(); if (tvReqInfo != null) { tvReqInfo.ResponseTime = DateTime.Now; _trafficFile.UpdateRequestInfo(tvReqInfo); _trafficFile.SaveResponse(tvReqInfo.Id, resp.ToArray()); } } else { response = String.Empty; } return(response); }
/// <summary> /// Navigates the browser /// </summary> /// <param name="requestHeader"></param> /// <param name="fullResponse"></param> public void NavigateBrowser(TVRequestInfo requestHeader, byte[] fullResponse) { this.Invoke((MethodInvoker) delegate { if (SelectedTab == RequestViewerTabs.Browser) { _pageBrowserView.Navigate(requestHeader, fullResponse); } else { _domView.Navigate(requestHeader, fullResponse); } }); }
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)); }
/// <summary> /// Searches only in the specified subset /// </summary> /// <param name="dataSource"></param> /// <param name="criteriaSet"></param> /// <param name="result"></param> /// <param name="subset"></param> private void SubsetSearch(ITrafficDataAccessor dataSource, SearchCriteriaSet criteriaSet, ISearchResult result, SearchSubset subset) { foreach (int reqId in subset) { TVRequestInfo header = dataSource.GetRequestInfo(reqId); if (_stopSearch) { break; } if (header != null) { RequestMatches(dataSource, header, criteriaSet, result); } } }
/// <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); }
public void SaveAndOpen() { string expectedRequest = "GET / HTTP/1.1"; string expectedResponse = "HTTP/1.1 200 OK"; TrafficViewerFile file = new TrafficViewerFile(); int reqId = file.AddRequestResponse(expectedRequest, expectedResponse); file.GetRequestInfo(reqId).IsHttps = true; Assert.AreEqual(1, file.RequestCount); TempFile temp = new TempFile(".tvf"); file.Save(temp.Path); //verify that the file can be saved Assert.IsTrue(File.Exists(temp.Path), "Cannot save the file"); file.Close(false); //make a new file and verify we can open TrafficViewerFile file2 = new TrafficViewerFile(); file2.Open(temp.Path); //verify actual file was open Assert.AreEqual(1, file2.RequestCount, "Incorrect request count after opening saved file"); //verify request data is correct int requestId = -1; TVRequestInfo info = file2.GetNext(ref requestId); Assert.IsNotNull(info, "Cannot obtain request info"); //veryfy transport info Assert.IsTrue(info.IsHttps); //verify request data string loadedRequest = Encoding.UTF8.GetString(file2.LoadRequestData(info.Id)); Assert.AreEqual(expectedRequest, loadedRequest); string loadedResponse = Encoding.UTF8.GetString(file2.LoadResponseData(info.Id)); Assert.AreEqual(expectedResponse, loadedResponse); file2.Close(false); }
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()); }
/// <summary> /// Gets the next unsent request /// </summary> /// <returns>Http Request Info</returns> private HttpRequestInfo GetNextRequest() { TVRequestInfo tvReqInfo = null; HttpRequestInfo httpReqInfo = null; ICacheable cacheEntry = null; //get the next unvisited request bool isCached = true; int hash = 0; do { tvReqInfo = Source.GetNext(ref _currId); if (tvReqInfo != null) { isCached = true; //skip js files and images if (!Utils.IsMatch(tvReqInfo.RequestLine, KNOWN_RESOURCE_EXTENSIONS)) { byte[] requestBytes = Source.LoadRequestData(tvReqInfo.Id); httpReqInfo = new HttpRequestInfo(requestBytes); //skip invalid requests if (httpReqInfo.Path.Contains("/")) { hash = httpReqInfo.GetHashCode(); //check the cache for the request to see if it was already visited //allow the same request to be sent more than once if (hash != _lastRequestHash) { cacheEntry = TrafficServerCache.Instance.GetEntry(hash); isCached = cacheEntry != null; } } } } //keep doing this until the end of requests or until we found a request that is not cached }while (tvReqInfo != null && isCached); if (hash != _lastRequestHash) { _lastRequestHash = hash; //clear the cache so we don't skip any repeats of the previous request TrafficServerCache.Instance.Clear(); } return(httpReqInfo); }
void ValidateTrafficSourcesRequestsAreSame(ITrafficDataAccessor src1, ITrafficDataAccessor src2, bool includeResponses = true) { Assert.AreEqual(src1.RequestCount, src2.RequestCount); int i = -1, j = -1; while (true) { TVRequestInfo first = src1.GetNext(ref i); TVRequestInfo second = src2.GetNext(ref j); if (first == null && second == null) { break; } Assert.AreEqual(first.RequestLine, second.RequestLine); //proceed to compare http requests byte[] firstRequest = src1.LoadRequestData(first.Id); byte[] secondRequest = src2.LoadRequestData(second.Id); HttpRequestInfo firstRequestInfo = new HttpRequestInfo(firstRequest); HttpRequestInfo seconRequestInfo = new HttpRequestInfo(secondRequest); Assert.AreEqual(firstRequestInfo.ToString(), seconRequestInfo.ToString()); if (includeResponses) { //proceed to compare responses Assert.AreEqual(first.ResponseStatus, second.ResponseStatus); byte[] firstResponse = src1.LoadResponseData(first.Id); byte[] secondResponse = src2.LoadResponseData(second.Id); HttpResponseInfo firstResponseInfo = new HttpResponseInfo(firstResponse); HttpResponseInfo secondResponseInfo = new HttpResponseInfo(secondResponse); Assert.AreEqual(firstResponseInfo.ToString(), secondResponseInfo.ToString()); } } }
private static void ValidateASEFile(TrafficViewerFile tvFile) { //after the import we should have 2 requests Assert.AreEqual(2, tvFile.RequestCount); int i = -1; TVRequestInfo first = tvFile.GetNext(ref i); TVRequestInfo second = tvFile.GetNext(ref i); Assert.AreEqual("GET /index1 HTTP/1.1", first.RequestLine); Assert.AreEqual("[1000]", first.ThreadId); Assert.AreEqual("Stage::Purpose1", first.Description); Assert.AreEqual("POST /index2 HTTP/1.1", second.RequestLine); Assert.AreEqual("[2000]", second.ThreadId); Assert.AreEqual("Stage::Purpose2", second.Description); TimeSpan diff = second.RequestTime.Subtract(first.RequestTime); Assert.AreEqual(10, diff.Milliseconds); Assert.AreEqual(" 0.03s", first.Duration); //check the requests HttpRequestInfo req1 = new HttpRequestInfo(tvFile.LoadRequestData(first.Id)); HttpRequestInfo req2 = new HttpRequestInfo(tvFile.LoadRequestData(second.Id)); Assert.AreEqual("demo.testfire.net", req1.Host); Assert.AreEqual("www.altoromutual.com", req2.Host); //check the responses Assert.AreEqual("200", first.ResponseStatus); Assert.AreEqual("302", second.ResponseStatus); HttpResponseInfo resp1 = new HttpResponseInfo(); HttpResponseInfo resp2 = new HttpResponseInfo(); resp1.ProcessResponse(tvFile.LoadResponseData(first.Id)); resp2.ProcessResponse(tvFile.LoadResponseData(second.Id)); string firstBody = resp1.ResponseBody.ToString(); string secondBody = resp2.ResponseBody.ToString(); Assert.IsTrue(firstBody.Contains("interrupt")); Assert.IsFalse(firstBody.Contains("--function")); Assert.IsTrue(secondBody.Contains("inter\nrupt")); }
private void DoDiff(int indexOfFirst, int indexOfSecond) { TVRequestInfo info1 = _source.GetRequestInfo(indexOfFirst); TVRequestInfo info2 = _source.GetRequestInfo(indexOfSecond); _requestID1.Text = info1.Id + ", " + info1.Description + ", " + info1.DomUniquenessId; _requestID2.Text = info2.Id + ", " + info2.Description + ", " + info2.DomUniquenessId;; _progress.Visible = true; _timer.Start(); //turn off the diff buttons so the user doesn't start another async operation by mistake DiffButtonsSwitch(false); _diffWorker.RunWorkerAsync(new int[2] { indexOfFirst, indexOfSecond }); }