-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex0.html
237 lines (208 loc) · 8.23 KB
/
index0.html
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
canvas {
max-width: 144px;
max-height: 82px;
}
</style>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
</head>
<body>
<main role="main" class="container">
<div>
<h1>Hardware Video Decoder Fingerprint Test Page</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
<div class="controls"></div>
<hr>
</div>
<div class="row submit" style="display:none;">
<div class="col-sm">
<h2>Submit Fingerprint</h2>
<form action="http://206.189.67.146/" method="post">
<div class="form-group">
<label for="cpu">CPU Model</label>
<input type="text" class="form-control" id="cpu" name="cpu" aria-describedby="cpuHelp" placeholder="ex. Intel Core i7-7700K">
<small id="cpuHelp" class="form-text text-muted">Leave blank if not applicable or unknown</small>
</div>
<div class="form-group">
<label for="gpu">Graphics Card Model</label>
<input type="text" class="form-control" id="gpu" name="gpu" aria-describedby="gpuHelp" placeholder="ex. Nvidia GeForce GTX 1080 Ti">
<small id="gpuHelp" class="form-text text-muted">Leave blank if not applicable or unknown</small>
</div>
<div class="form-group">
<label for="model">Device Model</label>
<input type="text" class="form-control" id="model" name="model" aria-describedby="modelHelp" placeholder="ex. iPhone 8 Plus">
<small id="modelHelp" class="form-text text-muted">Leave blank if not applicable or unknown</small>
</div>
<input type="hidden" id="videos" name="videos" />
<input type="hidden" id="renderer" name="renderer" />
<input type="hidden" id="useragent" name="useragent" />
<input type="hidden" id="time" name="time" />
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
<div class="row fingerprint" style="display:none; padding: 16px;">
<div class="col-sm data border border-secondary">
<h2>Visual Fingerprint</h2>
<div class="visual"></div>
<h2>Hashed Fingerprint</h2>
<div class="hashes"></div>
</div>
</div>
</main>
<script src="bitview.js"></script>
<script>
var assetURL = 'output_frag.mp4';
var emptyHash = "5a1c685ca6829cbbe95b235f4763b312a6e5013ecede57dfe82dad963d88d635";
var mimeCodec = 'video/mp4; codecs="avc1.640015"';
var indexes = [-1,
1954,
4625,
4795,
14298,
14319,
14326,
15058];
var asset;
var buffers = {};
var video;
var hashes = {};
var startTime;
function sha256(imageData) {
return crypto.subtle.digest("SHA-256", imageData.data).then(function (hash) {
return hex(hash);
});
}
function hex(buffer) {
var hexCodes = [];
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 4) {
var value = view.getUint32(i)
var stringValue = value.toString(16)
var padding = '00000000'
var paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
return hexCodes.join("");
}
function fuzz(index) {
if(index == -1) return asset.slice(0);
var buf = asset.slice(0);
var bv = new BitView(buf);
bv.setBit(index, !bv.getBit(index));
return buf;
}
function getHash(index) {
var canvas = document.createElement('canvas');
canvas.id = index;
canvas.height = video.videoHeight;
canvas.width = video.videoWidth;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
var data = ctx.getImageData(0, 0, canvas.width, canvas.height);
sha256(data).then(function(digest) {
hashes[index].push(digest);
document.querySelector(".visual").appendChild(canvas);
done();
}, function(e) {
hashes[index].push(e.toString());
error(e);
done();
});
}
function error(e) {
console.error(e);
}
function load() {
var xhr = new XMLHttpRequest;
xhr.open('get', assetURL);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
asset = xhr.response;
setup();
};
xhr.send();
}
function process(index) {
if(!(index in hashes)) hashes[index] = [];
buffers[index] = fuzz(index);
video = document.createElement('video');
video.addEventListener('loadeddata', function(_) {
console.log("loadeddata");
getHash(index);
});
video.addEventListener('error', function(_) {
console.log(video.error);
process(index);
});
if ('MediaSource' in window && MediaSource.isTypeSupported(mimeCodec)) {
var mediaSource = new MediaSource;
mediaSource.id = index;
video.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', sourceOpen);
} else {
error('Unsupported MIME type or codec: ', mimeCodec);
}
}
function setup() {
startTime = performance.now();
done();
}
function sourceOpen (_) {
var mediaSource = this;
mediaSource.removeEventListener('sourceopen', sourceOpen);
var sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
sourceBuffer.appendBuffer(buffers[mediaSource.id]);
}
function getNext() {
for(var i = 0; i < indexes.length; i++) {
if(indexes[i] in hashes) {
if(hashes[indexes[i]].length < 2) return indexes[i];
} else {
return indexes[i];
}
}
return null;
}
function done() {
var next = getNext();
if(next === null) {
var time = performance.now() - startTime;
var pre = document.createElement("pre");
pre.innerHTML = JSON.stringify(hashes, undefined, 2);
document.querySelector(".hashes").appendChild(pre);
var renderer = null;
try {
var canvas = document.createElement('canvas');
var gl = canvas.getContext('webgl');
var debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
} catch(e) {
}
document.querySelector("#useragent").value = navigator.userAgent;
document.querySelector("#renderer").value = renderer;
document.querySelector("#videos").value = JSON.stringify(hashes);
document.querySelector("#time").value = time;
document.querySelector(".submit").style.display = "block";
} else {
process(next);
}
}
var button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute("class", "btn btn-primary");
button.innerHTML = "Collect Fingerprint";
button.addEventListener("click", function() {
button.setAttribute("disabled", "true");
document.querySelector(".fingerprint").style.display = "block";
load();
});
document.querySelector(".controls").appendChild(button);
</script>
</body>
</html>