Skip to content

Commit 9789ee7

Browse files
committed
Move the Moodifications from SSH-Fuzzer to ModifiableVaraible.
SSH-Fuzzer hat defined some modificiations using the explicitValueModificationGenerator() method. It makes not much sense for me to define them not well structured in the SSH-Fuzzer (and abusing explicit modifications for this). The Mutations that got moved over are: - Append - Insert - Prepend for Integer, BigInteger, ByteArray and Long These Modifications do currently produce no usefull values for negative parameters, but if someone needs this, he should revise this. For our work, we mostly need only positiv values. I also added the missing modifications for long, since SFTP uses longs. And also added multiply modifiaction to integer.
1 parent 8599859 commit 9789ee7

37 files changed

+1660
-104
lines changed

src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,12 @@
77
*/
88
package de.rub.nds.modifiablevariable;
99

10-
import de.rub.nds.modifiablevariable.biginteger.BigIntegerAddModification;
11-
import de.rub.nds.modifiablevariable.biginteger.BigIntegerExplicitValueModification;
12-
import de.rub.nds.modifiablevariable.biginteger.BigIntegerInteractiveModification;
13-
import de.rub.nds.modifiablevariable.biginteger.BigIntegerMultiplyModification;
14-
import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftLeftModification;
15-
import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftRightModification;
16-
import de.rub.nds.modifiablevariable.biginteger.BigIntegerSubtractModification;
17-
import de.rub.nds.modifiablevariable.biginteger.BigIntegerXorModification;
10+
import de.rub.nds.modifiablevariable.biginteger.*;
1811
import de.rub.nds.modifiablevariable.bool.BooleanExplicitValueModification;
1912
import de.rub.nds.modifiablevariable.bool.BooleanToggleModification;
20-
import de.rub.nds.modifiablevariable.bytearray.ByteArrayDeleteModification;
21-
import de.rub.nds.modifiablevariable.bytearray.ByteArrayDuplicateModification;
22-
import de.rub.nds.modifiablevariable.bytearray.ByteArrayExplicitValueModification;
23-
import de.rub.nds.modifiablevariable.bytearray.ByteArrayInsertModification;
24-
import de.rub.nds.modifiablevariable.bytearray.ByteArrayShuffleModification;
25-
import de.rub.nds.modifiablevariable.bytearray.ByteArrayXorModification;
26-
import de.rub.nds.modifiablevariable.integer.IntegerAddModification;
27-
import de.rub.nds.modifiablevariable.integer.IntegerExplicitValueModification;
28-
import de.rub.nds.modifiablevariable.integer.IntegerShiftLeftModification;
29-
import de.rub.nds.modifiablevariable.integer.IntegerShiftRightModification;
30-
import de.rub.nds.modifiablevariable.integer.IntegerSubtractModification;
31-
import de.rub.nds.modifiablevariable.integer.IntegerXorModification;
32-
import de.rub.nds.modifiablevariable.longint.LongAddModification;
33-
import de.rub.nds.modifiablevariable.longint.LongExplicitValueModification;
34-
import de.rub.nds.modifiablevariable.longint.LongSubtractModification;
35-
import de.rub.nds.modifiablevariable.longint.LongXorModification;
13+
import de.rub.nds.modifiablevariable.bytearray.*;
14+
import de.rub.nds.modifiablevariable.integer.*;
15+
import de.rub.nds.modifiablevariable.longint.*;
3616
import de.rub.nds.modifiablevariable.singlebyte.ByteAddModification;
3717
import de.rub.nds.modifiablevariable.singlebyte.ByteExplicitValueModification;
3818
import de.rub.nds.modifiablevariable.singlebyte.ByteSubtractModification;
@@ -88,6 +68,15 @@ public abstract class ModifiableVariable<E> implements Serializable {
8868
@XmlElement(
8969
type = BigIntegerMultiplyModification.class,
9070
name = "BigIntegerMultiplyModification"),
71+
@XmlElement(
72+
type = BigIntegerAppendValueModification.class,
73+
name = "BigIntegerAppendValueModification"),
74+
@XmlElement(
75+
type = BigIntegerInsertValueModification.class,
76+
name = "BigIntegerInsertValueModification"),
77+
@XmlElement(
78+
type = BigIntegerPrependValueModification.class,
79+
name = "BigIntegerPrependValueModification"),
9180
@XmlElement(
9281
type = BooleanToggleModification.class,
9382
name = "BooleanToggleModification"),
@@ -101,8 +90,14 @@ public abstract class ModifiableVariable<E> implements Serializable {
10190
type = ByteArrayShuffleModification.class,
10291
name = "ByteArrayShuffleModification"),
10392
@XmlElement(
104-
type = ByteArrayInsertModification.class,
105-
name = "ByteArrayInsertModification"),
93+
type = ByteArrayAppendValueModification.class,
94+
name = "ByteArrayAppendValueModification"),
95+
@XmlElement(
96+
type = ByteArrayInsertValueModification.class,
97+
name = "ByteArrayInsertValueModification"),
98+
@XmlElement(
99+
type = ByteArrayPrependValueModification.class,
100+
name = "ByteArrayPrependValueModification"),
106101
@XmlElement(
107102
type = ByteArrayExplicitValueModification.class,
108103
name = "ByteArrayExplicitValueModification"),
@@ -116,6 +111,9 @@ public abstract class ModifiableVariable<E> implements Serializable {
116111
@XmlElement(
117112
type = IntegerSubtractModification.class,
118113
name = "IntegerSubtractModification"),
114+
@XmlElement(
115+
type = IntegerMultiplyModification.class,
116+
name = "IntegerMultiplyModification"),
119117
@XmlElement(
120118
type = IntegerShiftRightModification.class,
121119
name = "IntegerShiftRightModification"),
@@ -126,13 +124,40 @@ public abstract class ModifiableVariable<E> implements Serializable {
126124
type = IntegerExplicitValueModification.class,
127125
name = "IntegerExplicitValueModification"),
128126
@XmlElement(type = IntegerAddModification.class, name = "IntegerAddModification"),
127+
@XmlElement(
128+
type = IntegerAppendValueModification.class,
129+
name = "IntegerAppendValueModification"),
130+
@XmlElement(
131+
type = IntegerInsertValueModification.class,
132+
name = "IntegerInsertValueModification"),
133+
@XmlElement(
134+
type = IntegerPrependValueModification.class,
135+
name = "IntegerPrependValueModification"),
129136
@XmlElement(type = LongXorModification.class, name = "LongXorModification"),
130137
@XmlElement(
131138
type = LongSubtractModification.class,
132139
name = "LongSubtractModification"),
133140
@XmlElement(
134141
type = LongExplicitValueModification.class,
135142
name = "LongExplicitValueModification"),
143+
@XmlElement(
144+
type = LongAppendValueModification.class,
145+
name = "LongAppendValueModification"),
146+
@XmlElement(
147+
type = LongInsertValueModification.class,
148+
name = "LongInsertValueModification"),
149+
@XmlElement(
150+
type = LongPrependValueModification.class,
151+
name = "LongPrependValueModification"),
152+
@XmlElement(
153+
type = LongMultiplyModification.class,
154+
name = "LongMultiplyModification"),
155+
@XmlElement(
156+
type = LongShiftLeftModification.class,
157+
name = "LongShiftLeftModification"),
158+
@XmlElement(
159+
type = LongShiftRightModification.class,
160+
name = "LongShiftRightModification"),
136161
@XmlElement(type = LongAddModification.class, name = "LongAddModification"),
137162
@XmlElement(type = ByteXorModification.class, name = "ByteXorModification"),
138163
@XmlElement(
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* ModifiableVariable - A Variable Concept for Runtime Modifications
3+
*
4+
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0
7+
*/
8+
package de.rub.nds.modifiablevariable.biginteger;
9+
10+
import de.rub.nds.modifiablevariable.VariableModification;
11+
import jakarta.xml.bind.annotation.XmlAccessType;
12+
import jakarta.xml.bind.annotation.XmlAccessorType;
13+
import jakarta.xml.bind.annotation.XmlRootElement;
14+
import jakarta.xml.bind.annotation.XmlType;
15+
import java.math.BigInteger;
16+
import java.util.Objects;
17+
import java.util.Random;
18+
19+
@XmlRootElement
20+
@XmlType(propOrder = {"appendValue", "modificationFilter"})
21+
@XmlAccessorType(XmlAccessType.FIELD)
22+
public class BigIntegerAppendValueModification extends VariableModification<BigInteger> {
23+
24+
private static final int MAX_APPEND_LENGTH = 8;
25+
26+
private BigInteger appendValue;
27+
28+
public BigIntegerAppendValueModification() {}
29+
30+
public BigIntegerAppendValueModification(BigInteger bi) {
31+
this.appendValue = bi;
32+
}
33+
34+
@Override
35+
protected BigInteger modifyImplementationHook(BigInteger input) {
36+
if (input == null) {
37+
input = BigInteger.ZERO;
38+
}
39+
return input.shiftLeft(appendValue.bitLength()).add(appendValue);
40+
}
41+
42+
public BigInteger getAppendValue() {
43+
return appendValue;
44+
}
45+
46+
public void setAppendValue(BigInteger appendValue) {
47+
this.appendValue = appendValue;
48+
}
49+
50+
@Override
51+
public VariableModification<BigInteger> getModifiedCopy() {
52+
return new BigIntegerAppendValueModification(appendValue.add(new BigInteger(MAX_APPEND_LENGTH, new Random())));
53+
}
54+
55+
@Override
56+
public int hashCode() {
57+
int hash = 7;
58+
hash = 59 * hash + Objects.hashCode(this.appendValue);
59+
return hash;
60+
}
61+
62+
@Override
63+
public boolean equals(Object obj) {
64+
if (this == obj) {
65+
return true;
66+
}
67+
if (obj == null) {
68+
return false;
69+
}
70+
if (getClass() != obj.getClass()) {
71+
return false;
72+
}
73+
final BigIntegerAppendValueModification other = (BigIntegerAppendValueModification) obj;
74+
return Objects.equals(this.appendValue, other.appendValue);
75+
}
76+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* ModifiableVariable - A Variable Concept for Runtime Modifications
3+
*
4+
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0
7+
*/
8+
package de.rub.nds.modifiablevariable.biginteger;
9+
10+
import de.rub.nds.modifiablevariable.VariableModification;
11+
import jakarta.xml.bind.annotation.XmlAccessType;
12+
import jakarta.xml.bind.annotation.XmlAccessorType;
13+
import jakarta.xml.bind.annotation.XmlRootElement;
14+
import jakarta.xml.bind.annotation.XmlType;
15+
import java.math.BigInteger;
16+
import java.util.Objects;
17+
import java.util.Random;
18+
19+
@XmlRootElement
20+
@XmlType(propOrder = {"insertValue", "startPosition", "modificationFilter"})
21+
@XmlAccessorType(XmlAccessType.FIELD)
22+
public class BigIntegerInsertValueModification extends VariableModification<BigInteger> {
23+
24+
private static final int MAX_INSERT_LENGTH = 8;
25+
private static final int MAX_POSITION_MODIFIER = 32;
26+
27+
private BigInteger insertValue;
28+
private int startPosition;
29+
30+
public BigIntegerInsertValueModification() {}
31+
32+
public BigIntegerInsertValueModification(BigInteger bi, int startPosition) {
33+
this.insertValue = bi;
34+
this.startPosition = startPosition;
35+
}
36+
37+
@Override
38+
protected BigInteger modifyImplementationHook(BigInteger input) {
39+
if (input == null) {
40+
input = BigInteger.ZERO;
41+
}
42+
int originalValueLength = input.bitLength();
43+
int insertValueLength = insertValue.bitLength();
44+
int insertPosition = startPosition;
45+
if (startPosition > originalValueLength) {
46+
insertPosition = originalValueLength;
47+
} else if (startPosition < 0) {
48+
insertPosition = 0;
49+
}
50+
BigInteger mask = BigInteger.valueOf((1L << insertPosition) - 1);
51+
52+
return input.shiftRight(insertPosition)
53+
.shiftLeft(insertValueLength)
54+
.and(insertValue)
55+
.shiftLeft(insertPosition)
56+
.add(mask.and(input));
57+
}
58+
59+
public BigInteger getInsertValue() {
60+
return insertValue;
61+
}
62+
63+
public void setInsertValue(BigInteger insertValue) {
64+
this.insertValue = insertValue;
65+
}
66+
67+
public int getStartPosition() {
68+
return startPosition;
69+
}
70+
71+
public void setStartPosition(int startPosition) {
72+
this.startPosition = startPosition;
73+
}
74+
75+
@Override
76+
public VariableModification<BigInteger> getModifiedCopy() {
77+
Random r = new Random();
78+
79+
if (r.nextBoolean()) {
80+
return new BigIntegerInsertValueModification(
81+
insertValue.add(new BigInteger(MAX_INSERT_LENGTH, r)), startPosition);
82+
} else {
83+
int modifier = r.nextInt(MAX_POSITION_MODIFIER);
84+
if (r.nextBoolean()) {
85+
modifier *= -1;
86+
}
87+
modifier = startPosition + modifier;
88+
if (modifier <= 0) {
89+
modifier = 1;
90+
}
91+
return new BigIntegerInsertValueModification(insertValue, modifier);
92+
}
93+
}
94+
95+
@Override
96+
public int hashCode() {
97+
int hash = 7;
98+
hash = 58 * hash + Objects.hashCode(this.insertValue);
99+
hash = 58 * hash + Objects.hashCode(this.startPosition);
100+
return hash;
101+
}
102+
103+
@Override
104+
public boolean equals(Object obj) {
105+
if (this == obj) {
106+
return true;
107+
}
108+
if (obj == null) {
109+
return false;
110+
}
111+
if (getClass() != obj.getClass()) {
112+
return false;
113+
}
114+
final BigIntegerInsertValueModification other = (BigIntegerInsertValueModification) obj;
115+
if (this.startPosition != other.startPosition) {
116+
return false;
117+
}
118+
return Objects.equals(this.insertValue, other.insertValue);
119+
}
120+
}

0 commit comments

Comments
 (0)