-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzzstart.js
165 lines (149 loc) · 5.72 KB
/
fuzzstart.js
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
var FuzzRunner = (function() {
var runner = {};
//startup:
var filterNo = 0;
var tmplNo = 0;
var tmplMax = 5;
var tested = {}; // used as hashtable to find vectors already used
var vector;
var bypassed = {}; // as a [filterNo][tmplNo] dict
for (var i=0; i<tmplMax; i++) {
bypassed['tmpl'+ i] = {}
for (var j=0; j<filters.length; j++) {
bypassed['tmpl'+ i]['filter'+j] = false
}
}
function executeTest() {
if (tmplNo == tmplMax) { // next filter, if done with all templates
tmplNo = tmplNo % tmplMax;
filterNo++;
}
if (filterNo >= filters.length) { // Next vector if done with all filters
console.log("Done through all filters. Next Vector.");
if (CONFIG.debug) { // debug, if we do not want to try vectors other than the first one.
return;
}
filterNo = 0; tmplNo = 0;
try {
vector = Producer.getNewVector("CAP_EXECUTE_SCRIPT");
}
catch(e) {
// Could not produce new erorrs.
runner.finished = + (+(new Date()));
console.log((runner.finished - runner.started) / 60000 +' minutes', Object.keys(Producer.tested).length + ' tests')
return
}
console.log("New: "+ vector)
}
if (bypassed['tmpl'+tmplNo]['filter'+filterNo] !== false) {
if (CONFIG.debug) {
console.log("Skipping test for template " + templates[tmplNo][1] +" and filter "+ filters[filterNo][1]);
}
tmplNo++;
//XXX nasty hack to trigger next execution:
frames[0].name = "";
frames[0].document.location = "about:blank";
return;
}
var filterFunc = filters[filterNo][0];
var tmplFunc = templates[tmplNo][0];
var filteredVector = filterFunc(vector);
if (CONFIG.debug) {
console.log("Trying Vector: " + vector);
console.log("Filtered: " + filteredVector);
}
//TODO test other thing than "just" script execution as a filter violation.
frames[0].name = btoa(["Filter", filterNo, "Template Part", tmplNo, "Vector", vector].join("|"));
frames[0].document.location = 'about:blank'; // potentially race, as this triggers the next execution of executeTest
frames[0].document.open();
frames[0].document.write( tmplFunc(filteredVector) );
frames[0].document.close();
if (CONFIG.debug && document.getElementById("contentFrame").style.display != "none") {
document.querySelector("#debug").value = frames[0].document.body.innerHTML;
}
//addToLog(filterNo, tmplNo, vector, "pending/safe");
tmplNo++;
}
function nextTest() {
if (vector === undefined) {
if (CONFIG.debug) {
// "one vector to rule them all"
vector = (new String("javascript:/*-->]]>%>?></script></title></textarea></noscript></style></xmp>\">[img=1,name=top.postMessage(window.name,/\\*/.source.slice(1))]<img -/style=a:expression(/*'/-/*',/**/eval(name)/*%2A///*///);width:100%;height:100%;position:absolute;-ms-behavior:url(#default#time2) name=top.postMessage(window.name,/\\*/.source.slice(1)) onerror=eval(name) src=1 autofocus onfocus=eval(name) onclick=eval(name) onmouseover=eval(name) onbegin=eval(name) background=javascript:eval(name)//>\""))
//stupid testing: vector = "<script>top.postMessage(window.name, /\\*/.source.slice(1));</script>"
} else {
vector = Producer.getNewVector("CAP_EXECUTE_SCRIPT");
}
}
executeTest(vector);
}
function updateLog(info, status) {
try {
var td = document.getElementById(info);
td.textContent = status;
td.className = (status == "bypass") ? "bypass" : "safe";
return true;
}
catch(e) { return false; }
}
function addToLog(filterNo, tmplNo, Vector, status) {
if (bypassed['tmpl'+tmplNo]['filter'+filterNo] !== false) {
return // do not log vector for this combination twice.
}
bypassed['tmpl'+tmplNo]['filter'+filterNo] = Vector;
if (tmplNo < templates.length) {
tmplDesc = templates[tmplNo][1];
}
var filterName = filters[filterNo][1];
var tr = document.createElement('TR');
// Filter Name
var td = document.createElement('TD');
tr.appendChild(td);
var text = document.createTextNode(filterName);
td.appendChild(text);
td.title = filters[filterNo][1];
// Template description
var td_0 = document.createElement('TD');
tr.appendChild(td_0);
var text_0 = document.createTextNode(tmplDesc);
td_0.appendChild(text_0);
// Vector as string
var td_1 = document.createElement('TD');
tr.appendChild(td_1);
var pre = document.createElement('PRE')
var text_1 = document.createTextNode(Vector);
pre.appendChild(text_1)
td_1.appendChild(pre);
td_1.className = "vector";
// filtered Vector as string
var td_2a = document.createElement('TD');
tr.appendChild(td_2a);
var pre_0 = document.createElement('PRE')
var text_2a = document.createTextNode( filters[filterNo][0](Vector) );
pre_0.appendChild(text_2a)
td_2a.appendChild(pre_0);
td_2a.className = "filteredvector";
// Result
var td_2 = document.createElement('TD');
tr.appendChild(td_2);
var text_2 = document.createTextNode(status);
td_2.id = btoa(["Filter", filterNo, "Template Part", tmplNo, "Vector", vector].join("|"));
td_2.className = "pending";
td_2.appendChild(text_2);
var table = document.querySelector("#resultTable");
table.appendChild(tr);
}
function updateLog(info, status) {
try {
var td = document.getElementById(info);
td.textContent = status;
td.className = (status == "bypass") ? "bypass" : "safe";
return true;
}
catch(e) { return false; }
}
runner.addToLog = addToLog;
runner.updateLog = updateLog;
runner.nextTest = nextTest;
runner.bypassed = bypassed;
return runner;
})();