Skip to content

Commit

Permalink
Fixed verbose errors and removed unused libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulDoyensec committed Oct 15, 2024
1 parent 2471230 commit 5c81db3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.tsunami.plugins.detectors.credentials.genericweakcredentialdetector.testers.tomcat;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.nio.charset.StandardCharsets.UTF_8;

Expand All @@ -35,9 +34,7 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.sql.Timestamp;
import java.util.Base64;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.inject.Inject;
Expand Down Expand Up @@ -77,8 +74,8 @@ public boolean canAccept(NetworkService networkService) {
boolean canAcceptByNmapReport =
NetworkServiceUtils.getWebServiceName(networkService).equals(AJP13_SERVICE);

if (canAcceptByNmapReport) {
return true;
if (!canAcceptByNmapReport) {
return false;
}

boolean canAcceptByCustomFingerprint = false;
Expand All @@ -99,14 +96,16 @@ public boolean canAccept(NetworkService networkService) {
2, "HTTP/1.1", "/manager/html", host, host, host, port, true, headers, attributes);

byte[] response = sendAndReceive(host, port, request.getBytes());
AjpMessage responseMessage = AjpReader.parseMessage(response);
AjpMessage responseMessage = AjpReader.parseMessage(response);

canAcceptByCustomFingerprint = responseMessage.getDescription()
.toLowerCase().contains(TOMCAT_AUTH_HEADER.toLowerCase());

} catch (Exception e) {
// This catch block will catch both IOException and NullPointerException
logger.atWarning().withCause(e).log("Unable to query '%s'.", uriAuthority);
} catch (NullPointerException e) {
logger.atWarning().log("Unable to query '%s'.", uriAuthority);
return false;
} catch (IOException e){
logger.atWarning().log("Unable to query '%s'.", uriAuthority);
return false;
}

Expand All @@ -127,7 +126,7 @@ private boolean isTomcatAccessible(NetworkService networkService, TestCredential
String[] uriParts = uriAuthority.split(":");
String host = uriParts[0];
int port = Integer.parseInt(uriParts[1]);
var url = String.format("http://%s/%s", uriAuthority, "manager/html");
var url = String.format("%s/%s", uriAuthority, "manager/html");

logger.atInfo().log("uriAuthority: %s", uriAuthority);
try {
Expand All @@ -153,7 +152,7 @@ private boolean isTomcatAccessible(NetworkService networkService, TestCredential
} catch (IOException e) {
logger.atWarning().withCause(e).log("Unable to query '%s'.", url);
return false;
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public boolean canAccept(NetworkService networkService) {
return true;
}

if (!NetworkServiceUtils.isWebService(networkService)) {
return false;
}

boolean canAcceptByCustomFingerprint = false;

var url =
Expand Down

0 comments on commit 5c81db3

Please sign in to comment.