Class ExceptionHandler


  • public class ExceptionHandler
    extends Object
    During the different RMI operations you have always a roughly same set of exceptions that can occur. To have a unified error handling and to avoid too much duplicate code, the most common exceptions are handled by this class. The overall exception handling could be improved even more by defining exception handlers that automatically handle the exceptions that could be thrown by a specific type of attack (e.g. codebase, deserialize, ...). This may be implemented in future and will remove much more duplicate code.
    Author:
    Tobias Neitzel (@qtc_de)
    • Constructor Detail

      • ExceptionHandler

        public ExceptionHandler()
    • Method Detail

      • requirementException

        public static void requirementException​(eu.tneitzel.argparse4j.global.exceptions.RequirementException e)
        Parameters:
        e - description in progress
      • internalError

        public static void internalError​(String functionName,
                                         String message)
        Parameters:
        functionName - description in progress
        message - description in progress
      • internalException

        public static void internalException​(Exception e,
                                             String functionName,
                                             boolean exit)
        Parameters:
        e - description in progress
        functionName - description in progress
        exit - description in progress
      • unexpectedException

        public static void unexpectedException​(Exception e,
                                               String during1,
                                               String during2,
                                               boolean exit)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
        exit - description in progress
      • unknownCodebaseException

        public static void unknownCodebaseException​(Throwable e,
                                                    boolean exit)
        Parameters:
        e - description in progress
        exit - description in progress
      • alreadyBoundException

        public static void alreadyBoundException​(Exception e,
                                                 String boundName)
        Parameters:
        e - description in progress
        boundName - description in progress
      • nonLocalhost

        public static void nonLocalhost​(Exception e,
                                        String callName,
                                        boolean bypass)
        Parameters:
        e - description in progress
        callName - description in progress
        bypass - description in progress
      • jep290

        public static void jep290​(Exception e)
        Parameters:
        e - description in progress
      • deserializeClassNotFound

        public static void deserializeClassNotFound​(Exception e)
        Parameters:
        e - description in progress
      • deserializeClassNotFoundRandom

        public static void deserializeClassNotFoundRandom​(Exception e,
                                                          String during1,
                                                          String during2,
                                                          String className)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
        className - description in progress
      • deserializeClassCast

        public static void deserializeClassCast​(Exception e,
                                                boolean wasString)
        Parameters:
        e - description in progress
        wasString - description in progress
      • codebaseClassNotFound

        public static void codebaseClassNotFound​(Exception e,
                                                 String className)
        Parameters:
        e - description in progress
        className - description in progress
      • codebaseSecurityManager

        public static void codebaseSecurityManager​(Exception e)
        Parameters:
        e - description in progress
      • codebaseClassNotFoundRandom

        public static void codebaseClassNotFoundRandom​(Exception e,
                                                       String className,
                                                       String payloadName)
        Parameters:
        e - description in progress
        className - description in progress
        payloadName - description in progress
      • codebaseClassCast

        public static void codebaseClassCast​(Exception e,
                                             boolean wasString)
        Parameters:
        e - description in progress
        wasString - description in progress
      • codebaseClassFormat

        public static void codebaseClassFormat​(Exception e)
        Parameters:
        e - description in progress
      • connectionRefused

        public static void connectionRefused​(Exception e,
                                             String during1,
                                             String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • noRouteToHost

        public static void noRouteToHost​(Exception e,
                                         String during1,
                                         String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • noJRMPServer

        public static void noJRMPServer​(Exception e,
                                        String during1,
                                        String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • sslError

        public static void sslError​(Exception e,
                                    String during1,
                                    String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • invalidClass

        public static void invalidClass​(Exception e,
                                        String endpoint)
        Parameters:
        e - description in progress
        endpoint - description in progress
      • invalidClass

        public static void invalidClass​(Exception e,
                                        String endpoint,
                                        boolean trace)
        Parameters:
        e - description in progress
        endpoint - description in progress
        trace - description in progress
      • invalidClassBind

        public static void invalidClassBind​(Exception e,
                                            String operation,
                                            String className)
        Parameters:
        e - description in progress
        operation - description in progress
        className - description in progress
      • invalidClassEnum

        public static void invalidClassEnum​(Exception e,
                                            String callName)
        Parameters:
        e - description in progress
        callName - description in progress
      • unsupportedOperationException

        public static void unsupportedOperationException​(Exception e,
                                                         String callName)
        Parameters:
        e - description in progress
        callName - description in progress
      • unsupportedOperationExceptionEnum

        public static void unsupportedOperationExceptionEnum​(Exception e,
                                                             String callName)
        Parameters:
        e - description in progress
        callName - description in progress
      • accessControl

        public static void accessControl​(Exception e,
                                         String during1,
                                         String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • singleEntryRegistry

        public static void singleEntryRegistry​(Exception e,
                                               String during1)
        Parameters:
        e - description in progress
        during1 - description in progress
      • noSuchObjectException

        public static void noSuchObjectException​(Exception e,
                                                 String object,
                                                 boolean exit)
        Parameters:
        e - description in progress
        object - description in progress
        exit - description in progress
      • noSuchObjectException

        public static void noSuchObjectException​(Exception e,
                                                 ObjID objID,
                                                 boolean exit)
        Parameters:
        e - description in progress
        objID - description in progress
        exit - description in progress
      • noSuchObjectExceptionRegistryEnum

        public static void noSuchObjectExceptionRegistryEnum()
      • eofException

        public static void eofException​(Exception e,
                                        String during1,
                                        String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • invalidListenerFormat

        public static void invalidListenerFormat​(boolean gadget)
        Parameters:
        gadget - description in progress
      • invalidHostFormat

        public static void invalidHostFormat​(String format)
        Parameters:
        format - description in progress
      • invalidSignature

        public static void invalidSignature​(String signature)
        Parameters:
        signature - description in progress
      • unknownDeserializationException

        public static void unknownDeserializationException​(Exception e)
        Parameters:
        e - description in progress
      • unsupportedClassVersion

        public static void unsupportedClassVersion​(Exception e,
                                                   String during1,
                                                   String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • illegalArgument

        public static void illegalArgument​(Exception e)
        Parameters:
        e - description in progress
      • illegalArgumentCodebase

        public static void illegalArgumentCodebase​(Exception e)
        Parameters:
        e - description in progress
      • cannotCompile

        public static void cannotCompile​(Exception e,
                                         String during1,
                                         String during2,
                                         boolean exit)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
        exit - description in progress
      • unknownHost

        public static void unknownHost​(Exception e,
                                       String host,
                                       boolean exit)
        Parameters:
        e - description in progress
        host - description in progress
        exit - description in progress
      • networkUnreachable

        public static void networkUnreachable​(Exception e,
                                              String during1,
                                              String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • bindException

        public static void bindException​(Exception e)
        Parameters:
        e - description in progress
      • ysoNotPresent

        public static void ysoNotPresent​(String location)
        Parameters:
        location - description in progress
      • missingSignature

        public static void missingSignature()
      • missingTarget

        public static void missingTarget​(String action)
        Parameters:
        action - description in progress
      • invalidObjectId

        public static void invalidObjectId​(String objID)
        Parameters:
        objID - description in progress
      • wrongArgumentCount

        public static void wrongArgumentCount​(int expected,
                                              int is)
        Parameters:
        expected - description in progress
        is - description in progress
      • unrecognizedMethodHash

        public static void unrecognizedMethodHash​(Exception e,
                                                  String action,
                                                  String signature)
        Parameters:
        e - description in progress
        action - description in progress
        signature - description in progress
      • localhostBypassNoException

        public static void localhostBypassNoException()
      • lookupClassNotFoundException

        public static void lookupClassNotFoundException​(Exception e,
                                                        String name)
        Parameters:
        e - description in progress
        name - description in progress
      • notBoundException

        public static void notBoundException​(Exception e,
                                             String boundName)
        Parameters:
        e - description in progress
        boundName - description in progress
      • timeoutException

        public static void timeoutException​(Exception e,
                                            String during1,
                                            String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • connectionReset

        public static void connectionReset​(Exception e,
                                           String during1,
                                           String during2)
        Parameters:
        e - description in progress
        during1 - description in progress
        during2 - description in progress
      • genericCall

        public static void genericCall​(Exception e)
        Parameters:
        e - description in progress
      • connectException

        public static void connectException​(Exception e,
                                            String callName)
        Parameters:
        e - description in progress
        callName - description in progress
      • connectIOException

        public static void connectIOException​(Exception e,
                                              String callName)
        Parameters:
        e - description in progress
        callName - description in progress
      • invalidClassException

        public static void invalidClassException​(Exception e)
        Parameters:
        e - description in progress
      • getThrowable

        public static Throwable getThrowable​(String name,
                                             Throwable e)
        Walks down a stacktrace and searches for a specific exception name. If it finds the corresponding name, the corresponding Throwable is returned.
        Parameters:
        name - Exception name to look for.
        e - stack trace to search in.
        Returns:
        identified Throwable.
      • showStackTrace

        public static <T extends Throwable> void showStackTrace​(T e)
        By using the --stack-trace option, uses can always display stack traces if they want to. This is handled by this function. It checks whether --stack-trace was used and prints the stacktrace if desired. This function should be used in most of the error handling code of remote-method-guesser.
        Type Parameters:
        T - throwable type
        Parameters:
        e - Exception that was caught.
      • stackTrace

        public static <T extends Throwable> void stackTrace​(T e)
        Helper function that prints a stacktrace with a prefixed Logger item.
        Type Parameters:
        T - throwable type
        Parameters:
        e - Exception that was caught.
      • getCause

        public static Throwable getCause​(Throwable e)
        Taken from https://stackoverflow.com/questions/17747175/how-can-i-loop-through-exception-getcause-to-find-root-cause-with-detail-messa Returns the actual cause of an exception.
        Parameters:
        e - Exception that should be handled.
        Returns:
        cause of the Exception.
      • handleCodebaseException

        public static void handleCodebaseException​(Exception exception,
                                                   String className,
                                                   RMIComponent component,
                                                   String method)
        Handle an Exception that is thrown during codebase attacks. The exception reasons are similar for most RMI components and it makes sense to use a unified function here.
        Parameters:
        exception - Exception that was raised during the codebase attack
        className - ClassName that was used during the codebase attack
        component - RMIComponent that was targeted
        method - Server-side methodName that was used for the attack
      • handleCodebaseException

        public static void handleCodebaseException​(Exception exception,
                                                   String className,
                                                   RMIComponent component,
                                                   String method,
                                                   String randomClassName)
        Handle an Exception that is thrown during codebase attacks. The exception reasons are similar for most RMI components and it makes sense to use a unified function here. This method uses an additional randomClassName parameter. This can be used to indicate that a canary was used during the attack.
        Parameters:
        exception - Exception that was raised during the codebase attack
        className - ClassName that was used during the codebase attack
        component - RMIComponent that was targeted
        method - Server-side methodName that was used for the attack
        randomClassName - Class name of the canary that was used during the attack
      • handleGadgetCallException

        public static void handleGadgetCallException​(Exception exception,
                                                     RMIComponent component,
                                                     String method)
        Handle an Exception that is thrown during gadget call attacks. The exception reasons are similar for most RMI components and it makes sense to use a unified function here.
        Parameters:
        exception - Exception that was raised during the gadget call attack
        component - RMIComponent that was targeted
        method - Server-side methodName that was used for the attack
      • handleGadgetCallException

        public static void handleGadgetCallException​(Exception exception,
                                                     RMIComponent component,
                                                     String method,
                                                     String randomClassName)
        Handle an Exception that is thrown during gadget call attacks. The exception reasons are similar for most RMI components and it makes sense to use a unified function here. This method uses an additional randomClassName parameter. This can be used to indicate that a canary was used during the attack.
        Parameters:
        exception - Exception that was raised during the gadget call attack
        component - RMIComponent that was targeted
        method - Server-side methodName that was used for the attack
        randomClassName - Class name of the canary that was used during the attack