Skip to content
Snippets Groups Projects
Commit 466491ea authored by Jane Hoh's avatar Jane Hoh
Browse files

get and rem use urls that have previously been set

parent 6e019b07
No related branches found
No related tags found
2 merge requests!16Brownian motion fuzzer,!13Fuzzer
...@@ -11,6 +11,10 @@ public class Fuzzer { ...@@ -11,6 +11,10 @@ public class Fuzzer {
private static final String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz"; private static final String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz";
private static final String CHAR_UPPER = CHAR_LOWER.toUpperCase(); private static final String CHAR_UPPER = CHAR_LOWER.toUpperCase();
private static final String NUMBER = "0123456789"; private static final String NUMBER = "0123456789";
private static final int MAX_STRING_LENGTH = 1014;
private static final int MAX_URL_LENGTH = 300;
private static final int numInputLines = 1024; //Indicates the number of inputs we wish to generate in one file
private static ArrayList<String> savedURLs = new ArrayList<String>();
private static final String DATA_FOR_RANDOM_STRING = CHAR_LOWER + CHAR_UPPER + NUMBER; private static final String DATA_FOR_RANDOM_STRING = CHAR_LOWER + CHAR_UPPER + NUMBER;
...@@ -30,10 +34,8 @@ public class Fuzzer { ...@@ -30,10 +34,8 @@ public class Fuzzer {
/**Using generation-based fuzzing and Instruction.java, /**Using generation-based fuzzing and Instruction.java,
* create random, valid inputs*/ * create random, valid inputs*/
//Indicates the number of inputs we wish to generate
int numInputs = 10;
for(int i=0; i<numInputs; i++) { for(int i=0; i<numInputLines; i++) {
String input = generateValidInputs(); String input = generateValidInputs();
//only add the input if it hasn't already been generated //only add the input if it hasn't already been generated
if(inputAlreadyGenerated(input, inputs)) { if(inputAlreadyGenerated(input, inputs)) {
...@@ -60,17 +62,38 @@ public class Fuzzer { ...@@ -60,17 +62,38 @@ public class Fuzzer {
/**Generates random, valid inputs based on Instruction.java*/ /**Generates random, valid inputs based on Instruction.java*/
public static String generateValidInputs() { public static String generateValidInputs() {
int maxStringLength = 100;
//add the instruction string //add the instruction string
Instruction inst = getRandomInstruction(); Instruction inst = getRandomInstruction();
String input = inst.getOpcode(); String input = inst.getOpcode();
//add the operands //add the operands
int index =0;
for (OperandType op : inst.getOperands()){ for (OperandType op : inst.getOperands()){
if(op.equals(OperandType.STRING)) {
input += " "+generateRandomString(maxStringLength); if(index==0 && inst == Instruction.PUT) {
//generate a string with URL length for first arg
String url = generateRandomString(MAX_URL_LENGTH);
//store urls in a list of "saved urls"
savedURLs.add(url);
input += " "+url;
}else if(inst == Instruction.GET){
//use a saved url if one exists
input += " "+ getRandomSavedURL();
}else if(inst == Instruction.REM){
//use and remove a saved url if one exists
String url = getRandomSavedURL();
if(savedURLs.contains(url)) {
savedURLs.remove(url);
}
input += " "+ url;
}else if(op.equals(OperandType.STRING)) {
input += " "+generateRandomString(MAX_STRING_LENGTH);
} }
index++;
} }
//debug //debug
//System.out.println(input); //System.out.println(input);
...@@ -78,10 +101,12 @@ public class Fuzzer { ...@@ -78,10 +101,12 @@ public class Fuzzer {
return input; return input;
} }
/**Selects a random instruction*/ /**Selects a random instruction
* Returns any instruction except for masterpassword
* */
public static Instruction getRandomInstruction() { public static Instruction getRandomInstruction() {
Instruction[] INSTS = Instruction.values(); Instruction[] INSTS = Instruction.values();
int index = new Random().nextInt(INSTS.length); int index = new Random().nextInt(INSTS.length-1);
return INSTS[index]; return INSTS[index];
} }
...@@ -119,4 +144,14 @@ public class Fuzzer { ...@@ -119,4 +144,14 @@ public class Fuzzer {
return false; return false;
} }
/**Selects a random saved URL*/
public static String getRandomSavedURL(){
if(savedURLs.size()>0) {
int index = new Random().nextInt(savedURLs.size());
return savedURLs.get(index);
}else {
return generateRandomString(MAX_URL_LENGTH);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment