-
-
Notifications
You must be signed in to change notification settings - Fork 191
/
polyglot.html
149 lines (118 loc) · 10.8 KB
/
polyglot.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
-->
<div id='mypage'>
<span id='dropme'
ondrop="event.preventDefault();dropped(event.dataTransfer.files[0]);"
ondragover="event.preventDefault();event.stopPropagation();">
<style>
body {
/* top left&right bottom*/
margin: 10px 20px 0px;
}
p {
text-align: justify;
text-justify: inter-word;
}
</style>
<h1>This file is a hash pileup and HTML polyglot that collides itself.</h1>
<div style="text-align: right;">
by Ange Albertini and Rafał Hirsz
</div>
<h2>A polyglot</h2>
<div id='hideme'>
This file is a currently an HTML file and a ...<br/><br/>
<div style='text-align:center; font-style:italic;'>
<div style='font-size:200%;'>
[drop me here so that I can parse myself]
</div>
(otherwise I can't access my own contents without an 0-day)
</div>
<span id='ErrorMsg' style='color:red; font-weight:bold;'></span>
</div>
<div id='showme' style='display:none;'>
<p>This file is an HTML and (currently) a <span id=filetype></span> polyglot.</p>
<h2>An MD5 pileup</h2>
<p>It's also a file colliding with a quartet of PE/PDF/MP4/PNG*.</p>
<p>Maybe you don't have these files, but I can generate them for you:
<button id="exportPNG">Save as PNG</button>
<button id="exportPE">Save as PE</button>
<button id="exportPDF">Save as PDF</button>
<button id="exportMP4">Save as MP4</button>
</p>
<p style='font-size:80%;'>
*: note the PNG is not compatible with every reader (OS X preview, Safari)
because they enforce a structure that is incompatible with generic hash collisions.
</p>
</div>
</div>
<script language=javascript type="text/javascript">
prefixLen = 0x540
prefixPNG = "iVBORw0KGgoAAABYalVNUC89LT0tPS09LT0tPS09LVwrACBNRDUgcGlsZXVwAAArfAAAUE5HIHByZWZpeAAAfCsAAEFsYmVydGluaQAAACt8ICAgU3RldmVucyAgICB8XD0tPS09LT1VK6QEAAAE3GNPTEwAAAAAjAPRVp310yCeSguMrSd2TpmFijSruZo8MXe0qG/7lEHtdynGRhCBd8ZgYX4KottZebKJYetksRdLLmKw8j+aMdZaXi/S7cMSPgwQnLVp5Z43YdcMXY65lIoiq3FKZNwXxJfo6AZpI/Vpy/GwiAjKhgHJaR98ye1iwpKMk8UqoJaxWGIAN48FAtt1hry4T8ID8/mY/rdYxYfgLsvLfKM0vKKhEgQnoQQULAe0VJsuyf0rPwPZEpWpUZCNRCCOxcRE6rCiijPLlLnDEvDq7pDfOqR4zCuPCCBr2AFMIeo5AC9j4wi/huhDumpMxUC3r4+BdVKo09b9v8ludBtrw75YvmVX7o866/mOTkSpEKs+HJPQPWz1NIzbSM8hpKQEKytWtGFTLbcsMivUXljSTl77cdJEwQAV54Fcq64wsw6EdtegAvOIcnOaY1DKj7polcZ9wNK2s5j3gFKG27S1GTGY284oCDB0uTZKZEcz00w5h94H5kyis0dkArJZbN3qsUSdLr19e4Bcy3Jbh8jQNwtIqYmKo2qxk2luDDznBhp3wMcn/bOK0EoWhJlEFxaNs+j+wF19vNWgPYoq9b6bXE1utI6Hov4LrRGKLkU5CUjfogWQPMgX0e2BzW59emMhJrK/wmEU7GpjgW2RX07KCy937vTXPZ9BSPa9RqK8V4B5qLAknsUMOVw43VPf4MskL/qPKs+oq6jaL9bQBAlfYq3RMKgNMbW3/3pb/5nlwwjRDiMb+39pdaWVEWdCwATyFH5IFa869m7+VvovLT0tPS09LT0tPS09LT1cfCAgUEUgPD0+IFBORyAgfHwgICBsZXZlbCAyICAgIHxcPS09AAAAALmDEcL5LTW/UQ1ai5ztUVhl/k7ajJ7rBVGT9ddM0usgC4DJ9AbCF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+eBC/5UfV5IIoNx2j7IpJbiaKoHQEED85nx32+NURmzfuOULD5bkNvxXhGChyAu16yb0nkOfMSOJqQxTtRCvOVJFgPuICDKgFEezHV6Q46DwdfjGCzc4mEgyXHZ9xJX04ZFAVjhyyue+LoIAW/x0NjnVlVxEzuBTYl4+BChlARurRQ5bvdez+lCZ8RzLVaAnf3ZFreaLm+upCSsPeKcxb3H6IwFcVg5Zo/pAtLDtmNCe58ugjHsMfY93zLXQJpe12tvcMr959iqqsrmeyyjE6ICWN1g61x3uKwd/g2kEtuXqUmGRqsTO4jMFv5Yk498fLMZJNVz84wRyFXjIIU3Pkcw55ihArNGSfn3jFaYVY+3+pRozuO0ZDtHWZvZTTNPwyKwyoUD4TbGCjCEJxqyFUfoCDB818YkoqILUJc+qnDHGKU/eu+Ww6QYCR/OCQeUYrLKGBRJDOt0aIoQKbL6H4r4ZT9iIrfGmBF34S8MKx0ksGPaXil+Hxos0kt0M4ilNLo4RWesxVhNR0W+6nMlCWa2EKgeKOZmDbFYH6bZ37oJaqiOs6Zy3dvM0wpoJW6oCp9LGjHDrVMEp7lWBxY+9N5IwgVmluUbVwc5CZYICifiVqKf/jj7AXqo+ffaKudx4RxG0Z29QZKZPyJXsLaYWtJzhSkf2bj2G7ufcB+vdrWCrUNdesws3wpk1lAf2BgXqSz7tPV3"
var contents = "";
function dropped(f){
function setFileType(ft){
document.getElementById('filetype').textContent = ft;
document.getElementById('dropme').ondrop = function(){};
document.getElementById('dropme').ondragover = function(){};
document.getElementById('showme').style.display = "";
document.getElementById('hideme').style.display = "none";
}
r = new FileReader();
r.readAsArrayBuffer(f);
r.onload = function() {
fileContents = new Uint8Array(r.result);
prefix = String.fromCharCode.apply(null, fileContents.slice(0, prefixLen))
//console.log(btoa(prefix))
if (btoa(prefix) == prefixPNG){
setFileType("PNG");
}
else if (btoa(prefix) == prefixPE){
setFileType("PE");
} else if (btoa(prefix) == prefixPDF){
setFileType("PDF");
} else if (btoa(prefix) == prefixMP4){
setFileType("MP4");
}
else {
document.getElementById('ErrorMsg').textContent = "Unknown file!";
}
};
}
function Save(prefix, ext){
function download(blob, filename) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(() => {
document.body.removeChild(a);
URL.revokeObjectURL(url);
}, 200);
}
const blob = new Blob([
Uint8Array.from(atob(prefix), c => c.charCodeAt(0)),
fileContents.slice(prefixLen)
], {type:"application/octet-stream"});
download(blob, window.location.pathname.split("/").pop() + ext);
}
// necessary to clean up the elements of the outer file
document.documentElement.innerHTML = document.getElementById('mypage').innerHTML;
document.title = 'An MD5 pileup and HTML polyglot'
document.getElementById('exportPNG').addEventListener('click', () => {
Save(prefixPNG, ".png");
});
document.getElementById('exportPE').addEventListener('click', () => {
Save(prefixPE, ".ex");
});
document.getElementById('exportMP4').addEventListener('click', () => {
Save(prefixMP4, ".mp4");
});
document.getElementById('exportPDF').addEventListener('click', () => {
Save(prefixPDF, ".pdf");
});
</script>
<!--