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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Toby Murray
swen90006-a2-2019
Merge requests
!13
Fuzzer
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Fuzzer
186477/swen90006-a2-2019:fuzzer
into
master
Overview
0
Commits
4
Pipelines
0
Changes
1
Closed
Jane Hoh
requested to merge
186477/swen90006-a2-2019:fuzzer
into
master
5 years ago
Overview
0
Commits
4
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Viewing commit
755c39f7
Prev
Next
Show latest version
1 file
+
21
−
6
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
755c39f7
1/4 chance of maximising or minimising the string length
· 755c39f7
Jane Hoh
authored
5 years ago
fuzzer/Fuzzer.java
+
21
−
6
Options
@@ -8,15 +8,17 @@ import java.util.Random;
public
class
Fuzzer
{
private
static
final
String
OUTPUT_FILE
=
"fuzz.txt"
;
private
static
final
String
CHAR_LOWER
=
"abcdefghijklmnopqrstuvwxyz"
;
private
static
final
String
CHAR_UPPER
=
CHAR_LOWER
.
toUpperCase
();
private
static
final
String
NUMBER
=
"0123456789"
;
private
static
final
int
MAX_STRING_LENGTH
=
1014
;
private
static
final
int
MAX_LINE_LENGTH
=
1022
;
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
ArrayList
<
String
>
savedURLs
=
new
ArrayList
<
String
>();
//save put urls here for get and rem
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
;
//specifies which characters can be in a string
public
static
void
main
(
String
[]
args
)
throws
IOException
{
System
.
out
.
println
(
Instruction
.
getBNF
());
@@ -91,7 +93,8 @@ public class Fuzzer {
input
+=
" "
+
url
;
}
else
if
(
op
.
equals
(
OperandType
.
STRING
))
{
input
+=
" "
+
generateRandomString
(
MAX_STRING_LENGTH
);
int
maxStringLength
=
MAX_LINE_LENGTH
-
input
.
length
()
-
((
inst
.
getOperands
().
length
-
index
)*
2
);
input
+=
" "
+
generateRandomString
(
maxStringLength
);
}
index
++;
}
@@ -115,14 +118,26 @@ public class Fuzzer {
* and modified*/
public
static
String
generateRandomString
(
int
maxlength
)
{
if
(
maxlength
<
1
)
throw
new
IllegalArgumentException
();
Random
random
=
new
Random
();
int
minLength
=
1
;
int
length
;
//make a 1/4 chance of picking the max length and a 1/4 chance of picking the min length
int
chance
=
random
.
nextInt
(
4
);
if
(
chance
==
1
)
{
length
=
maxlength
;
}
else
if
(
chance
==
2
)
{
length
=
minLength
;
}
else
{
length
=
random
.
nextInt
(
maxlength
)+
1
;
}
int
length
=
new
Random
().
nextInt
(
maxlength
)+
1
;
StringBuilder
sb
=
new
StringBuilder
(
length
);
for
(
int
i
=
0
;
i
<
length
;
i
++)
{
// 0-62 (exclusive), random returns 0-61
int
rndCharAt
=
new
R
andom
()
.
nextInt
(
DATA_FOR_RANDOM_STRING
.
length
());
int
rndCharAt
=
r
andom
.
nextInt
(
DATA_FOR_RANDOM_STRING
.
length
());
char
rndChar
=
DATA_FOR_RANDOM_STRING
.
charAt
(
rndCharAt
);
sb
.
append
(
rndChar
);
Loading