From 3bdaba45e938cbc99ddb605dc4c4b5043db77de5 Mon Sep 17 00:00:00 2001 From: alanfoster Date: Sun, 22 Sep 2024 23:02:24 +0100 Subject: [PATCH] Fix NaN port number error --- js/script.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/js/script.js b/js/script.js index 4514b2b..561f4bd 100644 --- a/js/script.js +++ b/js/script.js @@ -109,9 +109,17 @@ const fixedEncodeURIComponent = function (str) { }); } +const parsePortOrDefault = function (value, defaultPort = 9001) { + if (value === null || value === undefined) return defaultPort; + + const number = Number(value); + const isValidPort = (Number.isSafeInteger(number) && number >= 0 && number <= 65535); + return isValidPort ? number : defaultPort; +}; + const rsg = { ip: (query.get('ip') || localStorage.getItem('ip') || '10.10.10.10').replace(/[^a-zA-Z0-9.\-]/g, ''), - port: query.get('port') || localStorage.getItem('port') || 9001, + port: parsePortOrDefault(query.get('port') || localStorage.getItem('port')), payload: query.get('payload') || localStorage.getItem('payload') || 'windows/x64/meterpreter/reverse_tcp', payload: query.get('type') || localStorage.getItem('type') || 'cmd-curl', shell: query.get('shell') || localStorage.getItem('shell') || rsgData.shells[0], @@ -166,7 +174,7 @@ const rsg = { getIP: () => rsg.ip, - getPort: () => Number(rsg.port), + getPort: () => parsePortOrDefault(rsg.port), getShell: () => rsg.shell, @@ -454,8 +462,9 @@ ipInput.addEventListener("input", (e) => { }); portInput.addEventListener("input", (e) => { + const value = e.target.value.length === 0 ? '0' : e.target.value; rsg.setState({ - port: Number(e.target.value) + port: parsePortOrDefault(value, rsg.getPort()) }) });