Class WordlistHandler


  • public class WordlistHandler
    extends Object
    The WordlistHandler is responsible for reading and writing wordlist files. During read operations, it also creates the corresponding MethodCandidates right away and during write operations, it writes method hashes and meta information into the corresponding wordlist.
    Author:
    Tobias Neitzel (@qtc_de)
    • Constructor Detail

      • WordlistHandler

        public WordlistHandler​(String wordlistFile,
                               String wordlistFolder,
                               boolean updateWordlists,
                               boolean zeroArg)
        Create a new WordlistHandler.
        Parameters:
        wordlistFile - wordlist file to use (if not null, takes priority over wordlist Folder)
        wordlistFolder - wordlist folder to look for wordlist files
        updateWordlists - whether wordlists should be updated to the advanced format
        zeroArg - whether to process zero argument methods
    • Method Detail

      • getWordlistMethods

        public Set<MethodCandidate> getWordlistMethods()
                                                throws IOException
        Read the specified wordlist and return the corresponding MethodCandidates. Only uses a wordlist file, if one was specified. Otherwise, it searches the specified wordlist folder. If there is also no wordlist folder specified, it defaults to the internal wordlists that are stored within the JAR.
        Returns:
        HashSet of MethodCandidates build from the wordlist
        Throws:
        IOException - if an IO operation fails
      • getWordlistMethodsFromStream

        public static HashSet<MethodCandidate> getWordlistMethodsFromStream()
                                                                     throws IOException
        This function is responsible for loading internal wordlist files. These are stored within the JAR file in the wordlists folder on the top level of the archive. Enumerating files within an internal JAR folder is currently a pain and the available wordlist names are hardcoded into this class.
        Returns:
        HashSet of method candidates parsed from the wordlist file
        Throws:
        IOException - if some file access fails
      • getWordlistMethodsFromFolder

        public static HashSet<MethodCandidate> getWordlistMethodsFromFolder​(String folder,
                                                                            boolean updateWordlists)
                                                                     throws IOException
        Reads all files ending with .txt within the wordlist folder and returns the corresponding MethodCandidates.
        Parameters:
        folder - wordlist folder to read the wordlist files from
        updateWordlists - determines whether wordlists should be updated after creating MethodCandidates
        Returns:
        HashSet of MethodCandidates parsed from the wordlist files
        Throws:
        IOException - if an IO operation fails
      • getWordlistMethodsFromFile

        public static HashSet<MethodCandidate> getWordlistMethodsFromFile​(String filename,
                                                                          boolean updateWordlists)
                                                                   throws IOException
        Parses a wordlist file for available methods and creates the corresponding MethodCandidates. Comments prefixed with '#' within wordlist files are ignored. Each non comment line is split on the ';' character. If the split has a length of 1, the ordinary wordlist format (that just contains the method signature) is assumed. If the length is 4 instead, it should be the advanced format. Otherwise, we have an unknown format and print a warning. If updateWordlists was set within the constructor, each wordlist file is updated to the advanced format after the parsing.
        Parameters:
        filename - wordlist file to parse
        updateWordlists - determines whether wordlists should be updated after creating MethodCandidates
        Returns:
        HashSet of MethodCandidates parsed from the wordlist file
        Throws:
        IOException - if an IO operation fails
      • parseMethods

        public static HashSet<MethodCandidate> parseMethods​(String[] lines)
                                                     throws IOException
        Takes the contents of a wordlist file as a list of lines and parses the corresponding method specifications. Empty lines and lines starting with a '#' are ignored. All other lines should be valid method signatures and are parsed to MethodCandidates by this function.
        Parameters:
        lines - method signatures read from a wordlist file
        Returns:
        HashSet of MethodCandidates build from the wordlist file
        Throws:
        IOException - if an IO operation fails
      • updateWordlist

        public static void updateWordlist​(File file,
                                          HashSet<MethodCandidate> methods)
                                   throws IOException
        Write MethodCandidates with their advanced format to a wordlist.
        Parameters:
        file - destination to write the advanced wordlist file
        methods - MethodCandidates to write into the wordlist
        Throws:
        IOException - if an IO operation fails