Package eu.tneitzel.rmg.io
Class WordlistHandler
- java.lang.Object
-
- eu.tneitzel.rmg.io.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 Summary
Constructors Constructor Description WordlistHandler(String wordlistFile, String wordlistFolder, boolean updateWordlists, boolean zeroArg)Create a new WordlistHandler.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<MethodCandidate>getWordlistMethods()Read the specified wordlist and return the corresponding MethodCandidates.static HashSet<MethodCandidate>getWordlistMethodsFromFile(String filename, boolean updateWordlists)Parses a wordlist file for available methods and creates the corresponding MethodCandidates.static HashSet<MethodCandidate>getWordlistMethodsFromFolder(String folder, boolean updateWordlists)Reads all files ending with .txt within the wordlist folder and returns the corresponding MethodCandidates.static HashSet<MethodCandidate>getWordlistMethodsFromStream()This function is responsible for loading internal wordlist files.static HashSet<MethodCandidate>parseMethods(String[] lines)Takes the contents of a wordlist file as a list of lines and parses the corresponding method specifications.static voidupdateWordlist(File file, HashSet<MethodCandidate> methods)Write MethodCandidates with their advanced format to a wordlist.
-
-
-
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 filesupdateWordlists- whether wordlists should be updated to the advanced formatzeroArg- 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 fromupdateWordlists- 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 parseupdateWordlists- 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 filemethods- MethodCandidates to write into the wordlist- Throws:
IOException- if an IO operation fails
-
-