def append_sequence_item(self, responseId, requestId=''): topItem = self.sequenceStepsTreeWidget.topLevelItem( self.sequenceStepsTreeWidget.topLevelItemCount() - 1) if topItem is None: current_max = 0 else: current_max = int(topItem.text(0)) stepnum = str(current_max + 1) row = self.Data.read_responses_by_id(self.cursor, responseId) if not row: return self.sequenceResponseIds.add(responseId) responseItems = interface.data_row_to_response_items(row) url = responseItems[ResponsesTable.URL] method = responseItems[ResponsesTable.REQ_METHOD] contentType = responseItems[ ResponsesTable.RES_CONTENT_TYPE].lower().strip() charset = ContentHelper.getCharSet(contentType) if contentType and ';' in contentType: contentType = contentType[0:contentType.index(';')] reqHeaders = responseItems[ResponsesTable.REQ_HEADERS] reqData = responseItems[ResponsesTable.REQ_DATA] requestHeaders, requestBody, rawRequest = ContentHelper.combineRaw( reqHeaders, reqData) resHeaders = responseItems[ResponsesTable.RES_HEADERS] resData = responseItems[ResponsesTable.RES_DATA] responseHeaders, responseBody, rawResponse = ContentHelper.combineRaw( resHeaders, resData, charset) sequence_item = { 'responseUrl': url, 'responseId': responseId, 'rawResponse': rawResponse, 'rawRequest': rawRequest, 'method': method, } self.sequence_items[stepnum] = sequence_item status = self.check_pattern_match(sequence_item) item = QTreeWidgetItem([stepnum, status, method, contentType, url]) self.sequenceStepsTreeWidget.addTopLevelItem(item) self.hide_media_type_item(item, contentType) self.formCapture.process_target_request(responseId, requestId, method, url, reqHeaders, reqData) return item
def fill_from_response(self, url, headers, body, content_type = None): if not url: url = 'about:blank' if not content_type: content_type = ContentHelper.getContentTypeFromHeaders(headers) charset = ContentHelper.getCharSet(content_type) qurl = QUrl.fromEncoded(url) # TODO: improve setting for non-html content, especially css self.setContent(body, content_type, qurl)
def append_sequence_item(self, responseId, requestId = ''): topItem = self.sequenceStepsTreeWidget.topLevelItem(self.sequenceStepsTreeWidget.topLevelItemCount()-1) if topItem is None: current_max = 0 else: current_max = int(topItem.text(0)) stepnum = str(current_max + 1) row = self.Data.read_responses_by_id(self.cursor, responseId) if not row: return self.sequenceResponseIds.add(responseId) responseItems = interface.data_row_to_response_items(row) url = responseItems[ResponsesTable.URL] method = responseItems[ResponsesTable.REQ_METHOD] contentType = responseItems[ResponsesTable.RES_CONTENT_TYPE].lower().strip() charset = ContentHelper.getCharSet(contentType) if contentType and ';' in contentType: contentType = contentType[0:contentType.index(';')] reqHeaders = responseItems[ResponsesTable.REQ_HEADERS] reqData = responseItems[ResponsesTable.REQ_DATA] requestHeaders, requestBody, rawRequest = ContentHelper.combineRaw(reqHeaders, reqData) resHeaders = responseItems[ResponsesTable.RES_HEADERS] resData = responseItems[ResponsesTable.RES_DATA] responseHeaders, responseBody, rawResponse = ContentHelper.combineRaw(resHeaders, resData, charset) sequence_item = { 'responseUrl' : url, 'responseId' : responseId, 'rawResponse' : rawResponse, 'rawRequest' : rawRequest, 'method' : method, } self.sequence_items[stepnum] = sequence_item status = self.check_pattern_match(sequence_item) item = QTreeWidgetItem([stepnum, status, method, contentType, url]) self.sequenceStepsTreeWidget.addTopLevelItem(item) self.hide_media_type_item(item, contentType) self.formCapture.process_target_request(responseId, requestId, method, url, reqHeaders, reqData) return item
def analyze_response(self, response): # return Need Sequence, Run Again if not self.session_detection: return True, False is_insession = False is_outofsession = False charset = ContentHelper.getCharSet(response.content_type) responseHeaders, responseBody, rawResponse = ContentHelper.combineRaw( response.headers, response.body, charset) rawResponse_lower = '' if self.use_insession_re: if self.re_insession.search(rawResponse): is_insession = True elif self.insession_pattern: rawResponse_lower = rawResponse.lower() if -1 != rawResponse_lower.find(self.insession_pattern): is_insession = True if self.use_outofsession_re: if self.re_outofsession.search(rawResponse): is_outofsession = True elif self.outofsession_pattern: if '' == rawResponse_lower: rawResponse_lower = rawResponse.lower() if -1 != rawResponse_lower.find(self.outofsession_pattern): is_outofsession = True if is_insession and not is_outofsession: return False, False elif not is_insession and is_outofsession: return True, True elif not is_insession and not is_outofsession: return False, False else: # conflicted, so run sequence, but not item return True, False
def analyze_response(self, response): # return Need Sequence, Run Again if not self.session_detection: return True, False is_insession = False is_outofsession = False charset = ContentHelper.getCharSet(response.content_type) responseHeaders, responseBody, rawResponse = ContentHelper.combineRaw(response.headers, response.body, charset) rawResponse_lower = '' if self.use_insession_re: if self.re_insession.search(rawResponse): is_insession = True elif self.insession_pattern: rawResponse_lower = rawResponse.lower() if -1 != rawResponse_lower.find(self.insession_pattern): is_insession = True if self.use_outofsession_re: if self.re_outofsession.search(rawResponse): is_outofsession = True elif self.outofsession_pattern: if '' == rawResponse_lower: rawResponse_lower = rawResponse.lower() if -1 != rawResponse_lower.find(self.outofsession_pattern): is_outofsession = True if is_insession and not is_outofsession: return False, False elif not is_insession and is_outofsession: return True, True elif not is_insession and not is_outofsession: return False, False else: # conflicted, so run sequence, but not item return True, False