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
755c39f7
Commit
755c39f7
authored
Oct 17, 2019
by
Jane Hoh
Browse files
Options
Downloads
Patches
Plain Diff
1/4 chance of maximising or minimising the string length
parent
466491ea
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
+21
-6
21 additions, 6 deletions
fuzzer/Fuzzer.java
with
21 additions
and
6 deletions
fuzzer/Fuzzer.java
+
21
−
6
View file @
755c39f7
...
...
@@ -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
);
...
...
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