Merge pull request #173 from AlanFoster/fix-NaN-port-number-error

Fix NaN port number error
This commit is contained in:
Ryan Montgomery 2024-10-31 18:38:04 -04:00 committed by GitHub
commit cf609e544b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 = { const rsg = {
ip: (query.get('ip') || localStorage.getItem('ip') || '10.10.10.10').replace(/[^a-zA-Z0-9.\-]/g, ''), 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('payload') || localStorage.getItem('payload') || 'windows/x64/meterpreter/reverse_tcp',
payload: query.get('type') || localStorage.getItem('type') || 'cmd-curl', payload: query.get('type') || localStorage.getItem('type') || 'cmd-curl',
shell: query.get('shell') || localStorage.getItem('shell') || rsgData.shells[0], shell: query.get('shell') || localStorage.getItem('shell') || rsgData.shells[0],
@ -166,7 +174,7 @@ const rsg = {
getIP: () => rsg.ip, getIP: () => rsg.ip,
getPort: () => Number(rsg.port), getPort: () => parsePortOrDefault(rsg.port),
getShell: () => rsg.shell, getShell: () => rsg.shell,
@ -454,8 +462,9 @@ ipInput.addEventListener("input", (e) => {
}); });
portInput.addEventListener("input", (e) => { portInput.addEventListener("input", (e) => {
const value = e.target.value.length === 0 ? '0' : e.target.value;
rsg.setState({ rsg.setState({
port: Number(e.target.value) port: parsePortOrDefault(value, rsg.getPort())
}) })
}); });