Skip to content
Snippets Groups Projects
Commit 245e8914 authored by hadi's avatar hadi
Browse files

Fuzzer Structure

parent b175d0eb
No related branches found
No related tags found
1 merge request!4Fuzzer structure
/**
* Filler has the responsibility of filling the arguments to the Instructions
* For example decides to fill the PUT Instruction at index 800 with the following
* "put http://sample.com fuzzer 123"
*/
public class Filler implements SetTransformer {
@Override
public void transformSet(InstructionSet set) {
}
}
import java.io.IOException; import java.io.IOException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList;
/* a stub for your team's fuzzer */ /* a stub for your team's fuzzer */
public class Fuzzer { public class Fuzzer {
private static final String OUTPUT_FILE = "fuzz.txt"; private static final String OUTPUT_FILE = "fuzz.txt";
private static final int MAX_INSTRUCTIONS = 1024;
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
System.out.println(Instruction.getBNF()); InstructionSet set = new InstructionSet(MAX_INSTRUCTIONS);
FileOutputStream out = null; Segmenter segmenter = new Segmenter();
PrintWriter pw = null; Orderer orderer = new Orderer();
try { Filler filler = new Filler();
out = new FileOutputStream(OUTPUT_FILE);
pw = new PrintWriter(out); System.out.println("segmenting instruction set");
segmenter.transformSet(set);
/* We just print one instruction. System.out.println("ordering instructions");
Hint: you might want to make use of the instruction orderer.transformSet(set);
grammar which is effectively encoded in Instruction.java */ System.out.println("filling instructions operands");
pw.println("list"); filler.transformSet(set);
}catch (Exception e){
e.printStackTrace(System.err); System.out.println("writing to file: "+OUTPUT_FILE);
System.exit(1); writeLinesToFile(set.toString(),OUTPUT_FILE);
}finally{
if (pw != null){ System.out.println("all done.");
pw.flush();
}
if (out != null){
out.close();
}
} }
/**
* writes the provided lines to file at filePath
* @param lines
* @param filePath
*/
private static void writeLinesToFile(String lines, String filePath){
} }
} }
import java.util.Arrays;
import java.util.ArrayList; import java.util.ArrayList;
public enum Instruction { public class Instruction {
PUT("put",new OperandType[]{OperandType.STRING,OperandType.STRING,OperandType.STRING}), public InstructionType getType() {
GET("get",new OperandType[]{OperandType.STRING}), return type;
REM("rem",new OperandType[]{OperandType.STRING}),
SAVE("save",new OperandType[]{OperandType.STRING,OperandType.STRING}),
LIST("list",new OperandType[]{}),
MASTERPW("masterpw",new OperandType[]{OperandType.STRING});
public static String getBNF(){
String grammar = "<INSTRUCTION> ::= \n";
Instruction[] INSTS = Instruction.values();
boolean firstInst = true;
for (Instruction inst : INSTS){
if (firstInst){
grammar += " \"";
firstInst = false;
}else{
grammar += " | \"";
}
grammar += inst.getOpcode() + "\"";
for (OperandType op : inst.getOperands()){
grammar += " <" + op.toString() + ">";
}
grammar += "\n";
}
return grammar;
} }
private final String opcode; public ArrayList<String> getParams() {
private final OperandType[] operands; return params;
Instruction(String opcode, OperandType[] operands){
this.opcode = opcode;
this.operands = operands;
} }
public String getOpcode(){ public void setType(InstructionType type) {
return opcode; this.type = type;
} }
public OperandType[] getOperands(){ public void setParams(ArrayList<String> params) {
return operands; this.params = params;
} }
public String toString(){ private InstructionType type;
String operandsString = ""; private ArrayList<String> params;
for (OperandType op : operands) {
operandsString += " " + op.toString();
}
return "\"" + opcode + "\"" + operandsString;
}
} }
public enum InstructionType {
PUT,
GET,
REM,
SAVE,
RANDOM,
}
public enum Instruction_old {
PUT("put",new OperandType[]{OperandType.STRING,OperandType.STRING,OperandType.STRING}),
GET("get",new OperandType[]{OperandType.STRING}),
REM("rem",new OperandType[]{OperandType.STRING}),
SAVE("save",new OperandType[]{OperandType.STRING,OperandType.STRING}),
LIST("list",new OperandType[]{}),
MASTERPW("masterpw",new OperandType[]{OperandType.STRING});
public static String getBNF(){
String grammar = "<INSTRUCTION> ::= \n";
Instruction_old[] INSTS = Instruction_old.values();
boolean firstInst = true;
for (Instruction_old inst : INSTS){
if (firstInst){
grammar += " \"";
firstInst = false;
}else{
grammar += " | \"";
}
grammar += inst.getOpcode() + "\"";
for (OperandType op : inst.getOperands()){
grammar += " <" + op.toString() + ">";
}
grammar += "\n";
}
return grammar;
}
private final String opcode;
private final OperandType[] operands;
Instruction_old(String opcode, OperandType[] operands){
this.opcode = opcode;
this.operands = operands;
}
public String getOpcode(){
return opcode;
}
public OperandType[] getOperands(){
return operands;
}
public String toString(){
String operandsString = "";
for (OperandType op : operands) {
operandsString += " " + op.toString();
}
return "\"" + opcode + "\"" + operandsString;
}
}
public enum OperandType {
STRING
}
/**
* Orderer has the responsibility of ordering the instructions in the instruction set
* Using the methods provided by the InstructionSet like putAtPercentile
*
* example: list(put,put,put,rem,rem,list) , after transformation: list (put,rem,put,put,rem,list)
*
*/
public class Orderer implements SetTransformer {
@Override
public void transformSet(InstructionSet set) {
}
}
/*
Segmenter has the responsibility of creating and adding Instructions to the Instruction Set
It decides how many of each instruction type should be present in the overall set
example: 80% put, 18% rem, 1% list, ...
When creating instructions it only specifies the Instruction's type and leaves the arguments to be filled
later by the Filler
*/
public class Segmenter implements SetTransformer {
@Override
public void transformSet(InstructionSet set) {
}
}
interface SetTransformer{
public abstract void transformSet(InstructionSet set);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment