forked from DidierStevens/DidierStevensSuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzzer.1sc
138 lines (122 loc) · 3.75 KB
/
fuzzer.1sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//---------------------------------------------------------------------------
/*
010 Editor Script to fuzz a file by overwriting random locations with AAAA...
or other (random) bytes.
2013/04/15 v0.0.1
Source code put in public domain by Didier Stevens, no Copyright
https://DidierStevens.com
Use at your own risk
History:
2013/03/31: start development with 010 Editor v4.0.2
2013/04/02: refactoring (RandomNumber)
2013/04/15: cleanup; added hexvalue for fuzz character
Todo:
Random returns an int (32 bits), while a file position is an int64
*/
//---------------------------------------------------------------------------
#define FUZZ_CHARACTER 'A'
#define TITLE "Fuzzer"
int RandomNumber(int iMinimum, int iMaximum)
{
return Random(iMaximum - iMinimum + 1) + iMinimum;
}
int HexDigitToInt(int digit)
{
if (digit >= '0' && digit <= '9')
return digit - '0';
if (digit >= 'a' && digit <= 'f')
return digit - 'a' + 10;
if (digit >= 'A' && digit <= 'F')
return digit - 'A' + 10;
return -1;
}
int HexToInt(string hexvalue)
{
int iResult;
int iHexDigit;
if (4 != Strlen(hexvalue))
return -1;
if (Strcmp(SubStr(hexvalue, 0, 2), "0x"))
return -1;
iHexDigit = HexDigitToInt(hexvalue[2]);
if (iHexDigit == -1)
return -1;
iResult = iHexDigit * 0x10;
iHexDigit = HexDigitToInt(hexvalue[3]);
if (iHexDigit == -1)
return -1;
return iResult + iHexDigit;
}
void Main(void)
{
int64 iStart;
int64 iSize;
int iCountOverwrites;
int iMinimumSize;
int iMaximumSize;
string sInputFuzzCharacter;
int iFlagRandom;
int iIter1;
int iIter2;
int iOverwriteSize;
int64 iOverwritePosition;
if (FileCount() == 0)
{
MessageBox(idOk, TITLE, "At least one file needs to be open.");
return;
}
iSize = GetSelSize();
if (0 == iSize)
{
iStart = 0;
iSize = FileSize();
}
else
iStart = GetSelStart();
iCountOverwrites = InputNumber(TITLE, "Number of times to overwrite random locations", "10");
if (BAD_VALUE == iCountOverwrites)
return;
if (iCountOverwrites < 1)
{
MessageBox(idOk, TITLE, "Input error");
return;
}
iMinimumSize = InputNumber(TITLE, "Minimum number of bytes to overwrite", "1");
if (BAD_VALUE == iMinimumSize)
return;
if (iMinimumSize < 1)
{
MessageBox(idOk, TITLE, "Input error");
return;
}
iMaximumSize = InputNumber(TITLE, "Maximum number of bytes to overwrite", "10");
if (BAD_VALUE == iMaximumSize)
return;
if (iMaximumSize < 1 || iMaximumSize > iSize || iMaximumSize < iMinimumSize)
{
MessageBox(idOk, TITLE, "Input error");
return;
}
iFlagRandom = false;
sInputFuzzCharacter = InputString(TITLE, "Fuzz character (use ** for random byte or 0x## for hex byte)", "A");
if ("" == sInputFuzzCharacter)
return;
else if ("**" == sInputFuzzCharacter)
iFlagRandom = true;
else if (-1 != HexToInt(sInputFuzzCharacter))
SPrintf(sInputFuzzCharacter, "%c", HexToInt(sInputFuzzCharacter));
else if (1 != Strlen(sInputFuzzCharacter))
{
MessageBox(idOk, TITLE, "Error input string.");
return;
}
for (iIter1 = 0; iIter1 < iCountOverwrites; iIter1++)
{
iOverwriteSize = RandomNumber(iMinimumSize, iMaximumSize);
iOverwritePosition = RandomNumber(iStart, iStart + iSize - iOverwriteSize);
Printf("0x%08x: overwriting with %d bytes\n", iOverwritePosition, iOverwriteSize);
for (iIter2 = 0; iIter2 < iOverwriteSize; iIter2++)
WriteByte(iOverwritePosition + iIter2, iFlagRandom ? Random(0x100) : sInputFuzzCharacter[0]);
}
}
Main();