fix post data

This commit is contained in:
zefie
2021-08-10 19:06:15 -04:00
parent 7e8e9208e0
commit 12d50f6e1c
2 changed files with 41 additions and 29 deletions

View File

@@ -274,28 +274,33 @@ async function processURL(socket, request_headers) {
} }
if (request_headers.post_data) { if (request_headers.post_data) {
var post_data_string = request_headers.post_data.toString(CryptoJS.enc.Utf8).replace("\0", ""); var post_data_string = '';
if (isUnencryptedString(post_data_string)) { try {
if (post_data_string.indexOf('=')) { post_data_string = request_headers.post_data.toString(CryptoJS.enc.Utf8).replace("\0", ""); // if not text this will probably throw an exception
if (post_data_string.indexOf('&')) { if (isUnencryptedString(post_data_string)) {
var qraw = post_data_string.split('&'); if (post_data_string.indexOf('=')) {
if (qraw.length > 0) { if (post_data_string.indexOf('&')) {
for (let i = 0; i < qraw.length; i++) { var qraw = post_data_string.split('&');
var qraw_split = qraw[i].split("="); if (qraw.length > 0) {
if (qraw_split.length == 2) { for (let i = 0; i < qraw.length; i++) {
var k = qraw_split[0]; var qraw_split = qraw[i].split("=");
request_headers.query[k] = unescape(qraw[i].split("=")[1].replace(/\+/g, "%20")); if (qraw_split.length == 2) {
var k = qraw_split[0];
request_headers.query[k] = unescape(qraw[i].split("=")[1].replace(/\+/g, "%20"));
}
} }
} }
} } else {
} else { var qraw_split = post_data_string.split("=");
var qraw_split = post_data_string.split("="); if (qraw_split.length == 2) {
if (qraw_split.length == 2) { var k = qraw_split[0];
var k = qraw_split[0]; request_headers.query[k] = unescape(qraw_split[1].replace(/\+/g, "%20"));
request_headers.query[k] = unescape(qraw_split[1].replace(/\+/g, "%20")); }
} }
} }
} }
} catch (e) {
socket_sessions[socket.id].expecting_post_data = true;
} }
} }
@@ -748,7 +753,7 @@ async function sendToClient(socket, headers_obj, data) {
if (socket_sessions[socket.id].post_data) delete socket_sessions[socket.id].post_data; if (socket_sessions[socket.id].post_data) delete socket_sessions[socket.id].post_data;
if (socket_sessions[socket.id].post_data_length) delete socket_sessions[socket.id].post_data_length; if (socket_sessions[socket.id].post_data_length) delete socket_sessions[socket.id].post_data_length;
if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown; if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown;
socket.setTimeout(minisrv_config.config.socket_timeout * 1000);
if (socket_sessions[socket.id].close_me) socket.end(); if (socket_sessions[socket.id].close_me) socket.end();
if (headers_obj["Connection"]) { if (headers_obj["Connection"]) {
if (headers_obj["Connection"].toLowerCase() == "close" && wtv_connection_close == "true") { if (headers_obj["Connection"].toLowerCase() == "close" && wtv_connection_close == "true") {
@@ -1094,6 +1099,7 @@ async function processRequest(socket, data_hex, skipSecure = false, encryptedReq
// handle POST // handle POST
if (headers['request']) { if (headers['request']) {
if (headers['request'].substring(0, 4) == "POST") { if (headers['request'].substring(0, 4) == "POST") {
socket.setTimeout(minisrv_config.config.post_data_socket_timeout * 1000);
if (typeof socket_sessions[socket.id].post_data == "undefined") { if (typeof socket_sessions[socket.id].post_data == "undefined") {
if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown; if (socket_sessions[socket.id].post_data_percents_shown) delete socket_sessions[socket.id].post_data_percents_shown;
socket_sessions[socket.id].post_data_length = headers['Content-length'] || headers['Content-Length'] || 0; socket_sessions[socket.id].post_data_length = headers['Content-length'] || headers['Content-Length'] || 0;
@@ -1313,21 +1319,25 @@ async function handleSocket(socket) {
socket_sessions[socket.id] = []; socket_sessions[socket.id] = [];
socket.minisrv_pc_mode = false; socket.minisrv_pc_mode = false;
socket.setEncoding('hex'); //set data encoding (Text: 'ascii', 'utf8' ~ Binary: 'hex', 'base64' (do not trust 'binary' encoding)) socket.setEncoding('hex'); //set data encoding (Text: 'ascii', 'utf8' ~ Binary: 'hex', 'base64' (do not trust 'binary' encoding))
socket.setTimeout(10800000); // 3 hours socket.setTimeout(minisrv_config.config.socket_timeout * 1000);
socket.on('data', function (data_hex) { socket.on('data', function (data_hex) {
if (!socket_sessions[socket.id].secure && !socket_sessions[socket.id].expecting_post_data) { if (socket_sessions[socket.id]) {
// buffer unencrypted data until we see the classic double-newline, or get blank if (!socket_sessions[socket.id].secure && !socket_sessions[socket.id].expecting_post_data) {
if (!socket_sessions[socket.id].header_buffer) socket_sessions[socket.id].header_buffer = ""; // buffer unencrypted data until we see the classic double-newline, or get blank
socket_sessions[socket.id].header_buffer += data_hex; if (!socket_sessions[socket.id].header_buffer) socket_sessions[socket.id].header_buffer = "";
if (socket_sessions[socket.id].header_buffer.indexOf("0d0a0d0a") != -1 || socket_sessions[socket.id].header_buffer.indexOf("0a0a") != -1) { socket_sessions[socket.id].header_buffer += data_hex;
data_hex = socket_sessions[socket.id].header_buffer; if (socket_sessions[socket.id].header_buffer.indexOf("0d0a0d0a") != -1 || socket_sessions[socket.id].header_buffer.indexOf("0a0a") != -1) {
delete socket_sessions[socket.id].header_buffer; data_hex = socket_sessions[socket.id].header_buffer;
delete socket_sessions[socket.id].header_buffer;
processRequest(this, data_hex);
}
} else {
// stream encrypted requests through the processor
if (socket_sessions[socket.id].header_buffer) delete socket_sessions[socket.id].header_buffer;
processRequest(this, data_hex); processRequest(this, data_hex);
} }
} else { } else {
// stream encrypted requests through the processor cleanupSocket(socket);
if (socket_sessions[socket.id].header_buffer) delete socket_sessions[socket.id].header_buffer;
processRequest(this, data_hex);
} }
}); });

View File

@@ -13,6 +13,8 @@
"hide_ssid_in_logs": true, "hide_ssid_in_logs": true,
"post_percentages": [ 0, 25, 50, 100 ], "post_percentages": [ 0, 25, 50, 100 ],
"verbosity": 2, "verbosity": 2,
"socket_timeout": 10800,
"post_data_socket_timeout": 30,
"error_log_file": "errors.log", "error_log_file": "errors.log",
"catchall_file_name": "catchall.js", "catchall_file_name": "catchall.js",
"enable_lzpf_compression": false, "enable_lzpf_compression": false,