Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swen90006-a2-2019
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Toby Murray
swen90006-a2-2019
Commits
466491ea
Commit
466491ea
authored
Oct 17, 2019
by
Jane Hoh
Browse files
Options
Downloads
Patches
Plain Diff
get and rem use urls that have previously been set
parent
6e019b07
No related branches found
No related tags found
2 merge requests
!16
Brownian motion fuzzer
,
!13
Fuzzer
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
fuzzer/Fuzzer.java
+44
-9
44 additions, 9 deletions
fuzzer/Fuzzer.java
with
44 additions
and
9 deletions
fuzzer/Fuzzer.java
+
44
−
9
View file @
466491ea
...
@@ -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
<
numInput
Line
s
;
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
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment