def testMarksEndpointsAsFuzzedOnlyIfCheckRequestReproducible(self): self.assertTrue(False) with self.mockUtilityCalls(): cb, state, burpCallbacks = self._ctc() em = GenericMock() em.fuzzed = False em.setFuzzed = GenericMock() requestA = GenericMock() utility.counter = 0 def wasReproducible(): if utility.counter == 0: utility.counter += 1 return True else: return False requestA.wasReproducible = wasReproducible em.requests = [requestA] state.endpointTableModel.endpoints = {"GET|/lol": em} requestA.analyzedResponse.statusCode = 200 requestA.repeatedAnalyzedResponse.statusCode = 200 cb.fuzzButtonClicked(GenericMock()) self.assertEquals(state.endpointTableModel.setFuzzed.call_count, 0)
def _fr(self): callbacks = GenericMock() state = GenericMock() extensions = [GenericMock(), GenericMock()] fuzzRunner = FuzzRunner(state, callbacks, extensions) return fuzzRunner, state, callbacks, extensions
def testPersistsMetadata(self): etm, state, callbacks = self._cetm() em = GenericMock() etm.generateEndpointHash = GenericMock() etm.generateEndpointHash.return_value = "uniqueid" etm.setFuzzed(em, True) self.assertEquals(callbacks.saveExtensionSetting.call_count, 1)
def testGenerateEndpointHash(self): etm, state, callbacks = self._cetm() mockRequestInfo = GenericMock() mockRequestInfo.method = "GET" mockRequestInfo.url = URL("http://www.example.org/users") mockRequestInfo.status = "200" hash, _, _ = etm.generateEndpointHash(mockRequestInfo) self.assertEquals(hash, "GET|http://www.example.org/users")
def testFuzzRequestModel(self): fr, state, callbacks, extensions = self._fr() extension = GenericMock() scanner = GenericMock() extension.getScannerChecks.return_value = [scanner] fr.extensions = [("scanner_name", extension)] fr.fuzzRequestModel(GenericMock()) self.assertEquals(state.fuzzExecutorService.submit.call_count, 5) state.fuzzExecutorService.submit.return_value.isDone = raise_exception
def testContainsId(self): em = EndpointModel("GET", "/lol") requestA = GenericMock() requestA.httpRequestResponse.request = String( "qwfqwfqwfq 748bbea58bb5db34e95d02edb2935c0f25cb1593e5ab837767e260a349c02ca7" ).getBytes() requestB = GenericMock() requestB.httpRequestResponse.request = String("qgwgqwgwgqw").getBytes() em.requests = [requestA, requestB] self.assertTrue(em.containsId)
def testGenerateEndpointHash64ByteHexadecimal(self): etm, state, callbacks = self._cetm() mockRequestInfo = GenericMock() mockRequestInfo.method = "GET" mockRequestInfo.url = URL( "http://www.example.org/users/748bbea58bb5db34e95d02edb2935c0f25cb1593e5ab837767e260a349c02ca7" ) mockRequestInfo.status = "200" hash, _, _ = etm.generateEndpointHash(mockRequestInfo) self.assertEquals(hash, "GET|http://www.example.org/users/{ID}")
def testBuildRequestUpdatesContentLength(self): callbacks = GenericMock() request = String("POST / HTTP/1.1\r\nHost:lelele\r\nContent-length: 16\r\n\r\n{\"param\":1234}\r\n").getBytes() callbacks.helpers.updateParameter.raise = UnsupportedOperationException sip = ScannerInsertionPoint(callbacks, request, "name", "value", IScannerInsertionPoint.INS_PARAM_JSON, 61, 65) sip.updateContentLength = GenericMock() ret = sip.buildRequest(String("lol").getBytes()) self.assertEquals(sip.updateContentLength.call_count, 1)
def testClearEndpointTableModel(self): etm, state, callbacks = self._cetm() etm.fireTableDataChanged = GenericMock() ret = callbacks.helpers.analyzeRequest.return_value ret.method = "GET" ret.url = URL("http://www.example.org/users?count=50") etm.add(GenericMock()) etm.clear() self.assertEqual(len(etm.endpoints), 0) self.assertEqual(etm.fireTableDataChanged.call_count, 1)
def testResendRequestModelLogoutURL(self): with self.mockUtilityCalls(): cb, state, burpCallbacks = self._ctc() utility.log = GenericMock() request = GenericMock() request.analyzedRequest.url.path = "/logout" utility.resend_request_model(state, burpCallbacks, request) self.assertEquals(burpCallbacks.makeHttpRequest.call_count, 0) self.assertEquals(state.endpointTableModel.update.call_count, 0) self.assertEquals(utility.log.call_count, 1)
def testGetContextMenuInvocation(self): fr, state, callbacks, extensions = self._fr() extension = GenericMock() scanner = GenericMock() extension.getScannerChecks.return_value = [scanner] fr.extensions = [("paramminer", extension)] # the paramminer string triggers the clicks. fr.fuzzRequestModel(GenericMock()) self.assertEquals(state.fuzzExecutorService.submit.call_count, 5) state.fuzzExecutorService.submit.return_value.isDone = raise_exception self.assertTrue(extension.getContextMenuFactories.call_count, 5)
def testEndpointTableModelUpdate(self): etm, state, callbacks, endpointModel = self._cetm_populate() requestModel = GenericMock() newResponse = GenericMock() etm.update(requestModel, newResponse) self.assertEquals(callbacks.saveBuffersToTempFiles.call_args[0], newResponse) self.assertEquals(requestModel.repeatedHttpRequestResponse, callbacks.saveBuffersToTempFiles.return_value) self.assertEquals(requestModel.repeated, True) self.assertEquals(requestModel.repeatedAnalyzedResponse, callbacks.helpers.analyzeResponse.return_value)
def testRefreshPersistsSettings(self): cb, state, burpCallbacks = self._ctc() state.scopeTextArea.text = "https://example.com/\nhttps://example.org/\n" burpCallbacks.getSiteMap.return_value = [ GenericMock(), GenericMock(), GenericMock() ] cb.refreshButtonClicked(GenericMock()) self.assertEquals(burpCallbacks.saveExtensionSetting.call_count, 1) self.assertEquals(burpCallbacks.getSiteMap.call_count, 2) self.assertEquals(state.endpointTableModel.clear.call_count, 1) self.assertEquals(state.endpointTableModel.add.call_count, 6)
def testAddEndpointTableModelSimple(self): state = GenericMock() callbacks = GenericMock() etm = EndpointTableModel(state, callbacks) ret = callbacks.helpers.analyzeRequest.return_value ret.method = "GET" ret.url = URL("http://www.example.org/users") etm.add(GenericMock()) self.assertEqual(len(etm.endpoints), 1) self.assertEqual(etm.endpoints["GET|http://www.example.org/users"].url, "http://www.example.org/users") self.assertEqual( etm.endpoints["GET|http://www.example.org/users"].method, "GET")
def testCanRunMainWithoutCrashing(self): be = BurpExtender() callbacks = GenericMock() callbacks.getScanIssues.return_value = [] be.registerExtenderCallbacks(callbacks) self.assertEqual(callbacks.setExtensionName.call_count, 1)
def testBuildRequestPath(self): ipg, callbacks = self._ipg() firstLine = "GET /folder1/folder1/file.php HTTP/1.1" secondLine = "Host: example.org" headers = ArrayList() headers.add(firstLine) headers.add(secondLine) request = GenericMock() request.repeatedAnalyzedRequest.parameters = [] request.repeatedAnalyzedRequest.headers = headers request.repeatedHttpRequestResponse.request = String(firstLine + "\r\n" + secondLine + "\r\n").getBytes() insertionPoints = ipg.getInsertionPoints(request, False) insertionPoints[0].updateContentLength = lambda x: x insertionPoints[1].updateContentLength = lambda x: x insertionPoints[2].updateContentLength = lambda x: x callbacks.helpers.urlEncode.return_value = "LOLLOLLOL" ret = insertionPoints[0].buildRequest(String("LOLLOLLOL").getBytes()) self.assertTrue(str(String(ret)).startswith("GET /LOLLOLLOL/folder1/file.php HTTP/1.1")) ret = insertionPoints[1].buildRequest(String("LOLLOLLOL").getBytes()) self.assertTrue(str(String(ret)).startswith("GET /folder1/LOLLOLLOL/file.php HTTP/1.1")) ret = insertionPoints[2].buildRequest(String("LOLLOLLOL").getBytes()) self.assertTrue(str(String(ret)).startswith("GET /folder1/folder1/LOLLOLLOL HTTP/1.1"))
def testClearWhenEmpty(self): etm, state, callbacks = self._cetm() etm.fireTableDataChanged = GenericMock() etm.clear() self.assertEqual(etm.fireTableDataChanged.call_count, 0)
def testRunAllButtonInvalidState(self): with self.mockSwingClasses(): with self.mockUtilityCalls(): cb, state, burpCallbacks = self._ctc() state.status = STATUS_FAILED cb.resendAllButtonClicked(GenericMock()) self.assertEquals(ui.JOptionPane.showMessageDialog.call_count, 1)
def testCheckButtonBasicCalls(self): with self.mockSwingClasses(): with self.mockUtilityCalls(): cb, state, burpCallbacks = self._ctc() cb.checkButtonClicked(GenericMock()) self.assertEquals(utility.apply_rules.call_count, 1) self.assertEquals(utility.get_header.call_count, 1)
def testInsertionPointHeaderBuildRequest(self): callbacks = GenericMock() request = String("GET / HTTP/1.1\r\nHost: lelele\r\n\r\n").getBytes() sip = ScannerInsertionPoint(callbacks, request, "Host", "lelele", IScannerInsertionPoint.INS_HEADER, 22, 28) sip.updateContentLength = lambda x: x ret = sip.buildRequest(String("lol").getBytes()) self.assertTrue("Host: lol" in str(String(ret)))
def testCheckButtonPersistsState(self): cb, state, burpCallbacks = self._ctc() with self.mockSwingClasses(): with self.mockUtilityCalls(): cb.checkButtonClicked(GenericMock()) self.assertEquals( burpCallbacks.saveExtensionSetting.call_count, 1)
def testAddButton(self): with self.mockSwingClasses(): cb, state, burpCallbacks = self._ctc() state.replacementRuleTableModel.rules = [ ReplacementRuleModel(1, "type", "search", "replacement") ] ui.JTextField.return_value.text = "" cb.addButtonClicked(GenericMock()) self.assertEquals(state.replacementRuleTableModel.add.call_count, 0, "Should be 0 because input is empty.") ui.JTextField.return_value.text = "valid" cb.addButtonClicked(GenericMock()) self.assertEquals(state.replacementRuleTableModel.add.call_count, 1, "Should have saved user input.") self.assertEquals(burpCallbacks.saveExtensionSetting.call_count, 1)
def testSameStatusPercentage(self): em = EndpointModel("GET", "/lol") requestA = GenericMock() requestB = GenericMock() em.requests = [requestA, requestB] requestA.repeatedAnalyzedResponse.statusCode = 200 requestA.analyzedResponse.statusCode = 200 requestB.repeatedAnalyzedResponse.statusCode = 200 requestB.analyzedResponse.statusCode = 403 self.assertEquals(em.percentSameStatus, 50) requestB.repeatedAnalyzedResponse.statusCode = 200 requestB.analyzedResponse.statusCode = 200 self.assertEquals(em.percentSameStatus, 100)
def testAddEndpointTableModelMax100(self): state = GenericMock() callbacks = GenericMock() etm = EndpointTableModel(state, callbacks) ret = callbacks.helpers.analyzeRequest.return_value ret.method = "GET" ret.url = URL("http://www.example.org/users") for a in range(200): etm.add(GenericMock()) self.assertEqual(len(etm.endpoints), 1) self.assertEqual(etm.endpoints["GET|http://www.example.org/users"].url, "http://www.example.org/users") self.assertEqual( etm.endpoints["GET|http://www.example.org/users"].method, "GET") self.assertEqual( len(etm.endpoints["GET|http://www.example.org/users"].requests), etm.MAX_REQUESTS_PER_ENDPOINT)
def testApplyRulesSubstituteHeader(self): rrtm = self._crrtm() rrtm.add(utility.REPLACE_HEADER_NAME, "X-test-header", "newvalue") bytes = String("wuh eva").getBytes() headers = ArrayList() headers.add("GET / HTTP/1.1") headers.add("Host: example.org") headers.add("X-test-header: oldvalue") callbacks = GenericMock() utility.Arrays = GenericMock() callbacks.helpers.analyzeRequest.return_value.headers = headers modified, _ = utility.apply_rules(callbacks, rrtm.rules, bytes) newHeaders = callbacks.helpers.buildHttpMessage.call_args[0] self.assertEquals(modified, 1) self.assertTrue("X-test-header: newvalue" in newHeaders, "Should contain new replaced header.")
def testIssueCheckerOnlyOnce(self): ic, state, callbacks = self._ic() state.scope_urls = ["http://example.org/"] ic.reportIssue = GenericMock() issue = GenericMock() issue.url = URL("http://www.example.org/users") issue.issueName = "SQL Injection" callbacks.getScanIssues.return_value = [issue] ic.run() self.assertEquals(ic.reportIssue.call_count, 1) ic.run() self.assertEquals( ic.reportIssue.call_count, 1, "Should still be one because it's the same issue and it has already been reported." )
def testRunAllButtonValidState(self): with self.mockSwingClasses(): with self.mockUtilityCalls(): cb, state, burpCallbacks = self._ctc() state.status = STATUS_OK etm, _, _, endpointModel = self._cetm_populate() state.endpointTableModel = etm cb.resendAllButtonClicked(GenericMock()) self.assertEquals(state.executorService.submit.call_count, 2)
def testResendRequestModel(self): cb, state, burpCallbacks = self._ctc() etm, _, _, endpointModel = self._cetm_populate() state.endpointTableModel = etm state.endpointTableModel.update = GenericMock() ui.apply_rules.return_value = (1, bytearray("lel")) resend_request_model(state, burpCallbacks, endpointModel.requests[0]) self.assertEquals(burpCallbacks.makeHttpRequest.call_count, 1) self.assertEquals(state.endpointTableModel.update.call_count, 1)
def testBuildRequestXmlAttr(self): callbacks = GenericMock() request = String("POST / HTTP/1.1\r\nHost:lelele\r\nContent-length: lelel\r\n\r\n<xml a=\"lol\">whatever</xml>\r\n").getBytes() callbacks.helpers.updateParameter.raise = UnsupportedOperationException sip = ScannerInsertionPoint(callbacks, request, "name", "value", IScannerInsertionPoint.INS_PARAM_XML_ATTR, 63, 66) sip.updateContentLength = lambda x: x ret = sip.buildRequest(String("evil <awfafw ''\"").getBytes()) self.assertTrue("<xml a=\"evil <awfafw ''"\">whatever</xml>" in str(String(ret)))
def testRequestsTableModelUpdateMethod(self): rtm, state, callback = self._crtm() rtm.fireTableRowsInserted = GenericMock() dict = self._cem("GET", "http://www.example.org/users") dict = self._cem("GET", "http://www.example.org/users", dict) rtm.updateRequests(dict["GET|http://www.example.org/users"].requests) self.assertEquals(len(rtm.requests), 2) self.assertEquals(rtm.fireTableRowsInserted.call_count, 1) self.assertEquals(rtm.fireTableRowsInserted.call_args, (0, 1))