@Override protected TestResult testSite(Site site, TestResult testResult) throws Throwable { long startTime = System.nanoTime(); DefaultHttpClient httpclient = new DefaultHttpClient(); String responseBody = ""; String responseBody2 = ""; try { HttpPost request = new HttpPost(site.getAddress() + "doLogin?username=username&password=%E6%E6%27"); HttpResponse response = httpclient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); responseBody = EntityUtils.toString(entity); if (responseBody.contains("Exception") || responseBody.contains("exception") || responseBody.contains("Caused by") || responseBody.contains("caused by")) { testResult.setResultEnum(ResultEnum.failed); testResult.setMessage( "The application gives an attacker very useful feedback on attempted attacks " + "by displaying detailed error messages and stack traces."); } else if (statusCode == 500 || statusCode == 200) { HttpGet request2 = new HttpGet(site.getAddress() + "..."); HttpResponse response2 = httpclient.execute(request2); int statusCode2 = response2.getStatusLine().getStatusCode(); if (statusCode2 == 404 || statusCode2 == 200) { testResult.setResultEnum(ResultEnum.passed); testResult.setMessage( "Ok, your application handles errors codes and tries not to leak " + "information!"); } } else { testResult.setResultEnum(ResultEnum.error); testResult.setMessage( "The test didn't work properly, are you providing a proper and secure error " + "handling?"); } } finally { httpclient.getConnectionManager().shutdown(); } setDuration(testResult, startTime); return testResult; }
@Override protected TestResult testSite(Site site, TestResult testResult) throws Throwable { DefaultHttpClient httpclient = new DefaultHttpClient(); String responseBody = ""; String responseBody2 = ""; try { HttpGet request = new HttpGet(site.getAddress() + "j_security_check?username=guest&password=%E6%E6%27"); HttpResponse response = httpclient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); responseBody = EntityUtils.toString(entity); if (responseBody.contains("Exception") || responseBody.contains("exception") || responseBody.contains("Caused by") || responseBody.contains("caused by")) { testResult.setPassed(false); testResult.setMessage("Your application has improper error handling!"); } else if (statusCode == 500 || statusCode == 200) { HttpGet request2 = new HttpGet(site.getAddress() + "..."); HttpResponse response2 = httpclient.execute(request2); int statusCode2 = response2.getStatusLine().getStatusCode(); HttpEntity entity2 = response2.getEntity(); responseBody2 = EntityUtils.toString(entity2); if (responseBody2.contains("Jetty") || responseBody2.contains("jetty")) { testResult.setPassed(false); testResult.setMessage( "Your application has improved error handling, but still leaks information!"); } else if (statusCode2 == 404 || statusCode2 == 200) { testResult.setPassed(true); testResult.setMessage( "Ok, your application handles errors codes and tries not to leak information!"); } } else { testResult.setPassed(false); testResult.setMessage( "The test didn't work properly, are you providing a proper and secure error handling?"); } } finally { httpclient.getConnectionManager().shutdown(); } return testResult; }