-
Notifications
You must be signed in to change notification settings - Fork 1
/
Browser.js
178 lines (175 loc) · 3.73 KB
/
Browser.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
166
167
168
169
170
171
172
173
174
175
176
177
178
(function (sandbox) {
function Browser()
{
var nextId = 1;
this.getNextId = function ()
{
if (nextId >= 32)
throw Error("Too many input sources");
return nextId++; // return nextId, and increment it
};
var inputsArr = [];
this.getInputId = function (input)
{
for (var i = 0; i < inputsArr; i++)
{
if (inputsArr[i].input === input)
return inputsArr[i].id;
}
const nextId = this.getNextId();
inputsArr.push({input:input, id:nextId});
return nextId;
};
}//todo : putField, native functions
Browser.prototype.getField = function (base, offset, config)
{
const nt = sandbox.dtaTaintLogic.noTaint;
const fillArr = sandbox.dtaUtils.fillArray;
var ft = sandbox.dtaTaintLogic.taintSource;
function getRet(val, start, ft, id)
{
if (typeof val == 'undefined')
{
return {ret: val,
id: config.ifTaintUndefined ? id : undefined,
sv: config.ifTaintUndefined ? ft : nt};
}
else
{
const end = val.length;
return {
ret: val, id: id,
sv: fillArr(nt, start).concat(fillArr(ft, end - start))
};
}
}
if (base === window.location)
{
const id = 0;
ft = ft(id);
switch (offset)
{
case "hash":
case "search":
return getRet(base[offset], 0, ft, id);
case "pathname":
if (config.taintPathName)
return getRet(base[offset], 0, ft, id);
else
return {ret:base[offset]};
case "href":
const getStart = (idx) => idx === -1 ? base.href.length : idx;
const taintStart = Math.min(getStart(base.href.indexOf('?')),
getStart(base.href.indexOf('#')));
const start = config.taintPathName ?
base.href.indexOf(base.origin) + base.origin.length : taintStart;
return getRet(base[offset], start, ft, id);
default:
return;
}
}
else if (String(base) === '[object HTMLInputElement]'
&& offset === 'value' && base.type === 'text')
{
const id = this.getInputId(base);
ft = ft(id);
return getRet(base.value, 0, ft, id);
}
};
Browser.prototype.invokeFunSrc = function (f, abase, args)
{
var ret,sv;
const ft = sandbox.dtaTaintLogic.taintSource;
const fillArray = sandbox.dtaUtils.fillArray;
switch (f)
{
case prompt:
ret = f.apply(abase, args);
if (typeof ret == 'string')
{
const id = this.getNextId();
sv = fillArray(ft(id), ret.length);
return {ret: ret, sv: sv, id:id};
}
else
{
return {ret:ret};
}
default:
return;
}
};
Browser.prototype.putField = function (base, offset, val, sval, config)
{
function genMsg(c)
{
var ret;
try
{
JSON.stringify(val);
JSON.stringify(sval);
ret = {value: val, shadow: sval, name: c+'.'+offset};
}
catch (e)
{
ret = {value: "[cyclic object]", shadow: "[cyclic object]", name: c+'.'+offset};
}
return ret;
}
switch (base)
{
case window.location:
switch (offset)
{
case 'hash':
case 'host':
case 'hostname':
case 'href':
case 'origin':
case 'pathname':
case 'port':
case 'protocol':
case 'search':
return genMsg("window.location");
}
return;
case document:
if (offset === 'cookie')
return genMsg("cookie");
return;
}
const m = String(base).match(/\[object HTML[a-zA-Z0-9]+Element]/);
if (m !== null && m[0] === String(base))
{
return genMsg(String(base));
}
};
Browser.prototype.invokeFunSnk = function (f, abase, aargs, sbase ,sargs, isTainted)
{
function genMsg()
{
var ret;
try
{
JSON.stringify(aargs);
JSON.stringify(sargs);
ret = {value: aargs, shadow: sargs, name: f.name};
}
catch (e)
{
ret = {value: "[cyclic object]", shadow: "[cyclic object]", name: f.name};
}
return ret;
}
switch (f)
{
case document.write:
case document.writeln:
case XMLHttpRequest.prototype.send:
case XMLHttpRequest.prototype.open:
if (sargs.map(isTainted).reduce((a,b) => a || b))
return genMsg();
}
};
sandbox.dtaBrowser = new Browser();
})(J$);