List of usage examples for org.apache.commons.lang StringUtils abbreviate
public static String abbreviate(String str, int maxWidth)
Abbreviates a String using ellipses.
From source file:org.owasp.jbrofuzz.core.Database.java
public DoubleFuzzer createDoubleFuzzer(String id1, int length1, String id2, int length2) throws NoSuchFuzzerException { if (containsPrototype(id1) && containsPrototype(id2)) { return new DoubleFuzzer(getPrototype(id1), length1, getPrototype(id2), length2); } else {/* www . ja va 2s.c om*/ throw new NoSuchFuzzerException(StringUtils.abbreviate(id1, 10) + " or " + StringUtils.abbreviate(id2, 10) + " Not Found in the Database "); } }
From source file:org.owasp.jbrofuzz.core.Database.java
public CrossProductFuzzer createCrossFuzzer(String id1, int length1, String id2, int length2) throws NoSuchFuzzerException { if (containsPrototype(id1) && containsPrototype(id2)) { return new CrossProductFuzzer(getPrototype(id1), length1, getPrototype(id2), length2); } else {//from w ww . j av a 2s . co m throw new NoSuchFuzzerException(StringUtils.abbreviate(id1, 10) + " or " + StringUtils.abbreviate(id2, 10) + " Not Found in the Database "); } }
From source file:org.owasp.jbrofuzz.core.Database.java
/** * <p>//w w w. ja v a2 s . c om * This factory method should be used instead of the #createFuzzer() if the * recursive payloads are more than 16^16 long. * </p> * <p> * As a Fuzzer is an iterator using a long datatype for counting, * FuzzerBigInteger is an iterator using the BigInteger datatype and thus not * limited to 16^16 number of iterator payloads. * </p> * <p> * Method responsible for creating a FuzzerBigInteger, based on an existing * prototypeId and length specified. * </p> * * @param prototypeId * prototypeId e.g 001-HTT-MTH or 032-SQL-INJ * @param len * The length of the fuzzer, used for recursive fuzzers * @return org.owasp.jbrofuzz.core#FuzzerBigInteger() * @throws NoSuchFuzzerException * * @see #containsPrototype(String) * * @author subere@uncon.org * @version 1.9 * @since 1.9 */ public FuzzerBigInteger createFuzzerBigInteger(final String prototypeId, final int len) throws NoSuchFuzzerException { if (!containsPrototype(prototypeId)) { throw new NoSuchFuzzerException( StringUtils.abbreviate(prototypeId, 10) + " : No Such Fuzzer Found in the Database "); } return new FuzzerBigInteger(getPrototype(prototypeId), len); }
From source file:org.owasp.jbrofuzz.fuzz.io.OpenSession.java
License:asdf
/** * load session from file - to be consistent with command line interface * style of *ix/*from w ww . ja va 2 s.c o m*/ * * @author daemonmidi@gmail.com * @since version 2.5 * @param file * @param fc */ private void setUpFromFile(File file, JFileChooser fc) { final String path = file.getAbsolutePath().toLowerCase(); // If the file does not end in .jbrofuzz, return JBroFuzzFileFilter jbfff = new JBroFuzzFileFilter(); if (!path.endsWith(".jbrofuzz") || !jbfff.accept(file)) { JOptionPane.showMessageDialog(fc, "The file selected is not a valid .jbrofuzz file", " JBroFuzz - Open ", JOptionPane.WARNING_MESSAGE); return; } // Clear up the display mWindow.getPanelFuzzing().clearAllFields(); // Start opening the file final StringBuffer fileContents = new StringBuffer(); BufferedReader in = null; int counter = 0; try { in = new BufferedReader(new FileReader(file)); int c; while (((c = in.read()) > 0) && (counter < MAX_CHARS)) { // Allow the character only if its printable ascii or \n if ((CharUtils.isAsciiPrintable((char) c)) || (((char) c) == '\n')) { fileContents.append((char) c); } counter++; } in.close(); } catch (final FileNotFoundException e) { Logger.log("FileNotFoundException", 3); } catch (final IOException e) { Logger.log("IOException", 3); } finally { IOUtils.closeQuietly(in); } // Validate particular lines to particular values final String[] fileContentsArray = fileContents.toString().split("\n"); final int fileNoOfLines = fileContentsArray.length; // Cannot have less than 12 lines if (fileNoOfLines < 12) { Logger.log("Invalid File: Contains less than 8 lines", 3); return; } if (!fileContentsArray[0].equals("[JBroFuzz]")) { Logger.log("Invalid File: Line 1 is not [JBroFuzz]", 3); return; } if (!fileContentsArray[2].equals("[Fuzzing]")) { Logger.log("Invalid File: Line 3 is not [Fuzzing]", 3); return; } if (!fileContentsArray[4].equals("[Comment]")) { Logger.log("Invalid File: Line 5 is not [Comment]", 3); return; } if (!fileContentsArray[6].equals("[URL]")) { Logger.log("Invalid File: Line 7 is not [URL]", 3); return; } if (!fileContentsArray[8].equals("[Request]")) { Logger.log("Invalid File: Line 9 is not [Request]", 3); return; } // Find the line where the [Fuzzers] line is int fuzzersLine = 0; for (int fuzzerLineCounter = fileNoOfLines - 1; fuzzerLineCounter > 0; fuzzerLineCounter--) { if (fileContentsArray[fuzzerLineCounter].equals("[Fuzzers]")) { // Check that there is only 1 instance if (fuzzersLine != 0) { Logger.log("Invalid File: Found 2 instances of [Fuzzers]", 3); return; } else { fuzzersLine = fuzzerLineCounter; } } } // If you can't find the [Fuzzers] line, return if (fuzzersLine == 0) { Logger.log("Invalid File: Cannot find a [Fuzzers] line", 3); return; } // Find the line where the [Transforms] line is int transformsLine = 0; for (int transformsLineCounter = fileNoOfLines - 1; transformsLineCounter > 0; transformsLineCounter--) { if (fileContentsArray[transformsLineCounter].equals("[Transforms]")) { // Check that there is only 1 instance if (transformsLine != 0) { Logger.log("Invalid File: Found 2 instances of [Transforms]", 3); return; } else { transformsLine = transformsLineCounter; } } } if (transformsLine == 0) { Logger.log("Invalid File: Cannot find a [Transforms] line", 3); return; } // File ends with [End] if (!fileContentsArray[fileNoOfLines - 1].equals("[End]")) { Logger.log("Invalid File: Last line is not [End]", 3); return; } // -> Target URL final String targetString = StringUtils.abbreviate(fileContentsArray[7], MAX_CHARS); mWindow.getPanelFuzzing().setTextURL(targetString); // -> Request final StringBuffer requestBuffer = new StringBuffer(); for (int reqLineCount = 9; reqLineCount < fuzzersLine; reqLineCount++) { requestBuffer.append(fileContentsArray[reqLineCount]); requestBuffer.append('\n'); } mWindow.getPanelFuzzing().setTextRequest(requestBuffer.toString()); // If more than 1024 lines of fuzzers, return if (fileNoOfLines - 1 - fuzzersLine - 1 > 1024) { Logger.log("Invalid File: More than 1024 Fuzzers Identified", 3); return; } // -> Load Fuzzers to Table for (int i = fuzzersLine + 1; i < transformsLine; i++) { final String[] payloadArray = fileContentsArray[i].split(","); // Each line must have 3 elements if (payloadArray.length != 3) { Logger.log("Invalid File: Line " + (i + 1) + " does not contain 3 elements", 2); continue; } // Assign local variables for line: 044-USR-AGN,39,177 // fuzz_id = 044-USR-AGN // start = 39 // end = 177 final String fuzzerID = payloadArray[0]; int start = 0; int end = 0; // The fuzzer id must be valid if (!Prototype.isValidFuzzerID(fuzzerID)) { Logger.log("Fuzzer Line Syntax Error: " + (i + 1) + " Invalid Fuzzer ID Format", 2); continue; } // The fuzzer id must also exist in the database if (!mWindow.getJBroFuzz().getDatabase().containsPrototype(fuzzerID)) { Logger.log("Could not find Fuzzer with ID: " + fuzzerID, 2); continue; } // The start and end integers should be happy try { start = Integer.parseInt(payloadArray[1]); end = Integer.parseInt(payloadArray[2]); } catch (final NumberFormatException e) { Logger.log("Fuzzer Line Syntax Error: Number Format Exception", 2); continue; } // Numbers must be positive if ((start < 0) || (end < 0)) { Logger.log("Fuzzer Line Syntax Error: Negative Value", 2); continue; } // Numbers must be less than the length of the request if ((start > requestBuffer.length()) || (end > requestBuffer.length())) { Logger.log("Fuzzer Line Syntax Error: Value Larger than Request", 2); continue; } Logger.log("Adding Fuzzer Line: " + "\t" + (i + 1) + "\t" + fileContentsArray[i], 1); mWindow.getPanelFuzzing().getFuzzersPanel().addFuzzer(fuzzerID, start, end); } // -> Load Transforms to Table // If more than 1024 lines of transforms, return if (fileNoOfLines - 1 - transformsLine - 1 > 1024) { Logger.log("Invalid File: More than 1024 Transforms Identified", 3); return; } for (int j = transformsLine + 1; j < fileNoOfLines - 1; j++) { final String[] transformLineArray = fileContentsArray[j].split(","); final int noOfElements = transformLineArray.length; // Each line must have 4 elements commas with empty ,, give a count // of 2 if ((noOfElements < 2) || (noOfElements > 4)) { Logger.log("Invalid File: Line " + (j + 1) + " does not contain 4 elements", 2); continue; } // Assign local variables for line: 1,Hexadecimal (UPP),asdf,fdsa // fuzzerNumber = 1 // encoder = Hexadecimal (UPP) // prefix = asdf // suffix = fdsa int fuzzerNumber = 0; // The transform number should be happy try { fuzzerNumber = Integer.parseInt(transformLineArray[0]); } catch (final NumberFormatException e) { Logger.log("Transform Line Syntax Error: Number Format Exception", 2); continue; } // Numbers must be greater than or equal to one if (fuzzerNumber < 1) { Logger.log("Transform Line Syntax Error: Value Less Than One", 2); continue; } // Numbers must be less than the total number of fuzzers if (fuzzerNumber > transformsLine - fuzzersLine) { Logger.log("Transform Line Syntax Error: Transform Outside Fuzzer Range", 2); continue; } final String encoder = StringUtils.abbreviate(transformLineArray[1], MAX_CHARS); // The encoder code must be valid if (!EncoderHashCore.isValidCode(encoder)) { Logger.log("Transform Line Syntax Error: Invalid Encode/Hash Code", 2); continue; } String prefix = ""; if (transformLineArray.length >= 3) { try { prefix = new String(Base64.decodeBase64(transformLineArray[2].getBytes()), "UTF-8"); } catch (UnsupportedEncodingException e) { Logger.log("Transform Line Syntax Error: Cannot Decode Prefix", 2); continue; } prefix = StringUtils.abbreviate(prefix, MAX_CHARS); } String suffix = ""; if (transformLineArray.length >= 4) { try { suffix = new String(Base64.decodeBase64(transformLineArray[3].getBytes()), "UTF-8"); } catch (UnsupportedEncodingException e) { Logger.log("Transform Line Syntax Error: Cannot Decode Suffix", 2); continue; } suffix = StringUtils.abbreviate(suffix, MAX_CHARS); } Logger.log("Adding Transform Line:\t" + (j + 1) + "\tOn Fuzzer Row:\t" + fuzzerNumber, 1); mWindow.getPanelFuzzing().getTransformsPanel().addTransform(fuzzerNumber, encoder, prefix, suffix); } // Finally, tell the frame this is the file opened // and save the directory location mWindow.setOpenFileTo(file); final String parentDir = file.getParent(); if (parentDir != null) { JBroFuzz.PREFS.put(JBroFuzzPrefs.DIRS[2].getId(), parentDir); } }
From source file:org.owasp.jbrofuzz.fuzz.ui.FuzzingPanel.java
/** * <p>/*from w w w . j a va2s . c o m*/ * Get the value of the Request String, limited to a maximum of 16384 * characters. * </p> * * @return String */ public String getTextRequest() { return StringUtils.abbreviate(requestPane.getText(), 16384); }
From source file:org.owasp.jbrofuzz.fuzz.ui.FuzzingPanel.java
/** * <p>//w w w. j a va2 s. co m * Get the value of the URL String, limited to a maximum of 1024 characters. * </p> * * @return String */ public String getTextURL() { return StringUtils.abbreviate(urlField.getText(), 1024); }
From source file:org.owasp.jbrofuzz.fuzz.ui.OutputTableModel.java
public void addNewRow(MessageContainer outputMessage) { this.addRow(new Object[] { outputMessage.getFileName(), outputMessage.getTextURL(), StringUtils.abbreviate(outputMessage.getPayload(), 50), StringUtils.abbreviate(outputMessage.getEncodedPayload(), 50), outputMessage.getStatus(), StringUtils.leftPad("" + outputMessage.getResponseTime(), 5, '0'), StringUtils.leftPad("" + outputMessage.getByteCount(), 8, '0') });/*from w w w .j a v a 2 s.com*/ }
From source file:org.owasp.jbrofuzz.ui.viewers.WindowViewerFrame.java
private void message(String msg) { status.setText(StringUtils.abbreviate(msg, 40)); }
From source file:org.owasp.jbrofuzz.version.JBroFuzzFormat.java
/** * <p>//from w w w .jav a 2s . c om * Method for abbreviating the given String to a particular length, by * removing characters from the middle of the String. * </p> * <p> * This method does not, yet guarantee a return String of length len. * </p> * * @param input * @param len * @return String */ public static final String centerAbbreviate(final String input, final int len) { if (input.length() <= len) { return input; } if (len < 5) { return input; } if (input.length() < len) { return input; } else { return StringUtils.abbreviate(input, len / 2) + StringUtils.right(input, len / 2); } }
From source file:org.pentaho.di.core.util.Assert.java
/** * @param input//from w w w. j a v a2s . co m * input to test. * @param predicate * predicate to apply. * @throws IllegalArgumentException * if predicate rejected input. */ public static void assertTrue(final Object input, final Predicate predicate) throws IllegalArgumentException { if (predicate.evaluate(input)) { return; } final StringBuilder builder = new StringBuilder(); builder.append("Predicate rejected input [predicate="); builder.append(predicate); builder.append(", input="); builder.append(StringUtils.abbreviate(String.valueOf(input), INPUT_MAX_WIDTH)); builder.append("]"); throw new IllegalArgumentException(builder.toString()); }