mirror of
https://github.com/0dayCTF/reverse-shell-generator.git
synced 2024-12-20 03:46:10 +00:00
removed unnecessary blank space
This commit is contained in:
parent
9a92be06a0
commit
9fe49aa96c
826
js/script.js
826
js/script.js
@ -1,464 +1,464 @@
|
|||||||
|
|
||||||
// Element selectors
|
// Element selectors
|
||||||
const ipInput = document.querySelector("#ip");
|
const ipInput = document.querySelector("#ip");
|
||||||
const portInput = document.querySelector("#port");
|
const portInput = document.querySelector("#port");
|
||||||
const listenerSelect = document.querySelector("#listener-selection");
|
const listenerSelect = document.querySelector("#listener-selection");
|
||||||
const shellSelect = document.querySelector("#shell");
|
const shellSelect = document.querySelector("#shell");
|
||||||
// const autoCopySwitch = document.querySelector("#auto-copy-switch");
|
// const autoCopySwitch = document.querySelector("#auto-copy-switch");
|
||||||
const encodingSelect = document.querySelector('#encoding');
|
const encodingSelect = document.querySelector('#encoding');
|
||||||
const listenerCommand = document.querySelector("#listener-command");
|
const listenerCommand = document.querySelector("#listener-command");
|
||||||
const reverseShellCommand = document.querySelector("#reverse-shell-command");
|
const reverseShellCommand = document.querySelector("#reverse-shell-command");
|
||||||
const bindShellCommand = document.querySelector("#bind-shell-command");
|
const bindShellCommand = document.querySelector("#bind-shell-command");
|
||||||
const msfVenomCommand = document.querySelector("#msfvenom-command");
|
const msfVenomCommand = document.querySelector("#msfvenom-command");
|
||||||
|
|
||||||
const FilterType = {
|
const FilterType = {
|
||||||
'All': 'all',
|
'All': 'all',
|
||||||
'Windows': 'windows',
|
'Windows': 'windows',
|
||||||
'Linux': 'linux',
|
'Linux': 'linux',
|
||||||
'Mac': 'mac'
|
'Mac': 'mac'
|
||||||
};
|
};
|
||||||
|
|
||||||
document.querySelector("#os-options").addEventListener("change", (event) => {
|
document.querySelector("#os-options").addEventListener("change", (event) => {
|
||||||
const selectedOS = event.target.value;
|
const selectedOS = event.target.value;
|
||||||
rsg.setState({
|
rsg.setState({
|
||||||
filter: selectedOS,
|
filter: selectedOS,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelector("#reverse-tab").addEventListener("click", () => {
|
document.querySelector("#reverse-tab").addEventListener("click", () => {
|
||||||
rsg.setState({
|
rsg.setState({
|
||||||
commandType: CommandType.ReverseShell,
|
commandType: CommandType.ReverseShell,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
document.querySelector("#bind-tab").addEventListener("click", () => {
|
document.querySelector("#bind-tab").addEventListener("click", () => {
|
||||||
rsg.setState({
|
rsg.setState({
|
||||||
commandType: CommandType.BindShell,
|
commandType: CommandType.BindShell,
|
||||||
encoding: "None"
|
encoding: "None"
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
document.querySelector("#bind-tab").addEventListener("click", () => {
|
document.querySelector("#bind-tab").addEventListener("click", () => {
|
||||||
document.querySelector("#bind-shell-selection").innerHTML = "";
|
document.querySelector("#bind-shell-selection").innerHTML = "";
|
||||||
rsg.setState({
|
rsg.setState({
|
||||||
commandType: CommandType.BindShell
|
commandType: CommandType.BindShell
|
||||||
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
document.querySelector("#msfvenom-tab").addEventListener("click", () => {
|
document.querySelector("#msfvenom-tab").addEventListener("click", () => {
|
||||||
document.querySelector("#msfvenom-selection").innerHTML = "";
|
document.querySelector("#msfvenom-selection").innerHTML = "";
|
||||||
rsg.setState({
|
rsg.setState({
|
||||||
commandType: CommandType.MSFVenom,
|
commandType: CommandType.MSFVenom,
|
||||||
encoding: "None"
|
encoding: "None"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var rawLinkButtons = document.querySelectorAll('.raw-listener');
|
var rawLinkButtons = document.querySelectorAll('.raw-listener');
|
||||||
for (const button of rawLinkButtons) {
|
for (const button of rawLinkButtons) {
|
||||||
button.addEventListener("click", () => {
|
button.addEventListener("click", () => {
|
||||||
const rawLink = RawLink.generate(rsg);
|
const rawLink = RawLink.generate(rsg);
|
||||||
window.location = rawLink;
|
window.location = rawLink;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelector(".download-listener").addEventListener("click", () => {
|
|
||||||
var element = document.createElement('a');
|
|
||||||
const rawLink = RawLink.generate(rsg);
|
|
||||||
element.setAttribute('href', rawLink);
|
|
||||||
element.setAttribute('download', rsg.getSelectedCommandName() + '.txt');
|
|
||||||
document.body.appendChild(element);
|
|
||||||
element.click();
|
|
||||||
document.body.removeChild(element);
|
|
||||||
})
|
|
||||||
|
|
||||||
const filterCommandData = function (data, { commandType, filter }) {
|
document.querySelector(".download-listener").addEventListener("click", () => {
|
||||||
return data.filter(item => {
|
var element = document.createElement('a');
|
||||||
if (!item.meta.includes(commandType)) {
|
const rawLink = RawLink.generate(rsg);
|
||||||
return false;
|
element.setAttribute('href', rawLink);
|
||||||
}
|
element.setAttribute('download', rsg.getSelectedCommandName() + '.txt');
|
||||||
|
document.body.appendChild(element);
|
||||||
|
element.click();
|
||||||
|
document.body.removeChild(element);
|
||||||
|
})
|
||||||
|
|
||||||
if (!filter) {
|
const filterCommandData = function (data, { commandType, filter }) {
|
||||||
return true;
|
return data.filter(item => {
|
||||||
}
|
if (!item.meta.includes(commandType)) {
|
||||||
|
return false;
|
||||||
if (filter === FilterType.All) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return item.meta.includes(filter);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = new URLSearchParams(location.hash.substring(1));
|
if (!filter) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const rsg = {
|
if (filter === FilterType.All) {
|
||||||
ip: query.get('ip') || localStorage.getItem('ip') || '10.10.10.10',
|
return true;
|
||||||
port: query.get('port') || localStorage.getItem('port') || 9001,
|
}
|
||||||
payload: query.get('payload') || localStorage.getItem('payload') || 'windows/x64/meterpreter/reverse_tcp',
|
|
||||||
shell: query.get('shell') || localStorage.getItem('shell') || rsgData.shells[0],
|
|
||||||
listener: query.get('listener') || localStorage.getItem('listener') || rsgData.listenerCommands[0][1],
|
|
||||||
encoding: query.get('encoding') || localStorage.getItem('encoding') || 'None',
|
|
||||||
selectedValues: {
|
|
||||||
[CommandType.ReverseShell]: filterCommandData(rsgData.reverseShellCommands, { commandType: CommandType.ReverseShell })[0].name,
|
|
||||||
[CommandType.BindShell]: filterCommandData(rsgData.reverseShellCommands, { commandType: CommandType.BindShell })[0].name,
|
|
||||||
[CommandType.MSFVenom]: filterCommandData(rsgData.reverseShellCommands, { commandType: CommandType.MSFVenom })[0].name,
|
|
||||||
},
|
|
||||||
commandType: CommandType.ReverseShell,
|
|
||||||
filter: FilterType.All,
|
|
||||||
|
|
||||||
uiElements: {
|
return item.meta.includes(filter);
|
||||||
[CommandType.ReverseShell]: {
|
});
|
||||||
listSelection: '#reverse-shell-selection',
|
}
|
||||||
command: '#reverse-shell-command'
|
|
||||||
},
|
|
||||||
[CommandType.BindShell]: {
|
|
||||||
listSelection: '#bind-shell-selection',
|
|
||||||
command: '#bind-shell-command',
|
|
||||||
},
|
|
||||||
[CommandType.MSFVenom]: {
|
|
||||||
listSelection: '#msfvenom-selection',
|
|
||||||
command: '#msfvenom-command'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
copyToClipboard: (text) => {
|
const query = new URLSearchParams(location.hash.substring(1));
|
||||||
if (navigator ?.clipboard ?.writeText) {
|
|
||||||
navigator.clipboard.writeText(text)
|
|
||||||
$('#clipboard-toast').toast('show')
|
|
||||||
} else if (window ?.clipboardData ?.setData) {
|
|
||||||
window.clipboardData.setData('Text', text);
|
|
||||||
$('#clipboard-toast').toast('show')
|
|
||||||
} else {
|
|
||||||
$('#clipboard-failure-toast').toast('show')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
escapeHTML: (text) => String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'),
|
const rsg = {
|
||||||
|
ip: query.get('ip') || localStorage.getItem('ip') || '10.10.10.10',
|
||||||
|
port: query.get('port') || localStorage.getItem('port') || 9001,
|
||||||
|
payload: query.get('payload') || localStorage.getItem('payload') || 'windows/x64/meterpreter/reverse_tcp',
|
||||||
|
shell: query.get('shell') || localStorage.getItem('shell') || rsgData.shells[0],
|
||||||
|
listener: query.get('listener') || localStorage.getItem('listener') || rsgData.listenerCommands[0][1],
|
||||||
|
encoding: query.get('encoding') || localStorage.getItem('encoding') || 'None',
|
||||||
|
selectedValues: {
|
||||||
|
[CommandType.ReverseShell]: filterCommandData(rsgData.reverseShellCommands, { commandType: CommandType.ReverseShell })[0].name,
|
||||||
|
[CommandType.BindShell]: filterCommandData(rsgData.reverseShellCommands, { commandType: CommandType.BindShell })[0].name,
|
||||||
|
[CommandType.MSFVenom]: filterCommandData(rsgData.reverseShellCommands, { commandType: CommandType.MSFVenom })[0].name,
|
||||||
|
},
|
||||||
|
commandType: CommandType.ReverseShell,
|
||||||
|
filter: FilterType.All,
|
||||||
|
|
||||||
getIP: () => rsg.ip,
|
uiElements: {
|
||||||
|
[CommandType.ReverseShell]: {
|
||||||
|
listSelection: '#reverse-shell-selection',
|
||||||
|
command: '#reverse-shell-command'
|
||||||
|
},
|
||||||
|
[CommandType.BindShell]: {
|
||||||
|
listSelection: '#bind-shell-selection',
|
||||||
|
command: '#bind-shell-command',
|
||||||
|
},
|
||||||
|
[CommandType.MSFVenom]: {
|
||||||
|
listSelection: '#msfvenom-selection',
|
||||||
|
command: '#msfvenom-command'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getPort: () => Number(rsg.port),
|
copyToClipboard: (text) => {
|
||||||
|
if (navigator ?.clipboard ?.writeText) {
|
||||||
|
navigator.clipboard.writeText(text)
|
||||||
|
$('#clipboard-toast').toast('show')
|
||||||
|
} else if (window ?.clipboardData ?.setData) {
|
||||||
|
window.clipboardData.setData('Text', text);
|
||||||
|
$('#clipboard-toast').toast('show')
|
||||||
|
} else {
|
||||||
|
$('#clipboard-failure-toast').toast('show')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getShell: () => rsg.shell,
|
escapeHTML: (text) => String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'),
|
||||||
|
|
||||||
getEncoding: () => rsg.encoding,
|
getIP: () => rsg.ip,
|
||||||
|
|
||||||
getSelectedCommandName: () => {
|
getPort: () => Number(rsg.port),
|
||||||
return rsg.selectedValues[rsg.commandType];
|
|
||||||
},
|
|
||||||
|
|
||||||
getReverseShellCommand: () => {
|
getShell: () => rsg.shell,
|
||||||
const reverseShellData = rsgData.reverseShellCommands.find((item) => item.name === rsg.getSelectedCommandName());
|
|
||||||
return reverseShellData.command;
|
|
||||||
},
|
|
||||||
|
|
||||||
getPayload: () => {
|
getEncoding: () => rsg.encoding,
|
||||||
if (rsg.commandType === 'MSFVenom') {
|
|
||||||
let cmd = rsg.getReverseShellCommand();
|
|
||||||
// msfvenom -p windows/x64/meterpreter_reverse_tcp ...
|
|
||||||
let regex = /\s+-p\s+(?<payload>[a-zA-Z0-9/_]+)/;
|
|
||||||
let match = regex.exec(cmd);
|
|
||||||
if (match) {
|
|
||||||
return match.groups.payload;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'windows/x64/meterpreter/reverse_tcp'
|
getSelectedCommandName: () => {
|
||||||
|
return rsg.selectedValues[rsg.commandType];
|
||||||
|
},
|
||||||
|
|
||||||
},
|
getReverseShellCommand: () => {
|
||||||
|
const reverseShellData = rsgData.reverseShellCommands.find((item) => item.name === rsg.getSelectedCommandName());
|
||||||
|
return reverseShellData.command;
|
||||||
|
},
|
||||||
|
|
||||||
generateReverseShellCommand: () => {
|
getPayload: () => {
|
||||||
let command
|
if (rsg.commandType === 'MSFVenom') {
|
||||||
|
let cmd = rsg.getReverseShellCommand();
|
||||||
if (rsg.getSelectedCommandName() === 'PowerShell #3 (Base64)') {
|
// msfvenom -p windows/x64/meterpreter_reverse_tcp ...
|
||||||
const encoder = (text) => text;
|
let regex = /\s+-p\s+(?<payload>[a-zA-Z0-9/_]+)/;
|
||||||
const payload = rsg.insertParameters(rsgData.specialCommands['PowerShell payload'], encoder)
|
let match = regex.exec(cmd);
|
||||||
command = "powershell -e " + btoa(toBinary(payload))
|
if (match) {
|
||||||
function toBinary(string) {
|
return match.groups.payload;
|
||||||
const codeUnits = new Uint16Array(string.length);
|
|
||||||
for (let i = 0; i < codeUnits.length; i++) {
|
|
||||||
codeUnits[i] = string.charCodeAt(i);
|
|
||||||
}
|
|
||||||
const charCodes = new Uint8Array(codeUnits.buffer);
|
|
||||||
let result = '';
|
|
||||||
for (let i = 0; i < charCodes.byteLength; i++) {
|
|
||||||
result += String.fromCharCode(charCodes[i]);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
command = rsg.getReverseShellCommand()
|
|
||||||
}
|
|
||||||
|
|
||||||
const encoding = rsg.getEncoding();
|
|
||||||
if (encoding === 'Base64') {
|
|
||||||
command = rsg.insertParameters(command, (text) => text)
|
|
||||||
command = btoa(command)
|
|
||||||
} else {
|
|
||||||
function encoder(string) {
|
|
||||||
return (encoding === 'encodeURI' || encoding === 'encodeURIComponent') ? window[
|
|
||||||
encoding](string) : string
|
|
||||||
}
|
|
||||||
|
|
||||||
command = rsg.escapeHTML(command);
|
|
||||||
command = rsg.insertParameters(
|
|
||||||
rsg.highlightParameters(
|
|
||||||
encoder(command), encoder),
|
|
||||||
encoder
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return command;
|
|
||||||
},
|
|
||||||
|
|
||||||
highlightParameters: (text, encoder) => {
|
|
||||||
const parameters = ['{ip}', '{port}', '{shell}', encodeURI('{ip}'), encodeURI('{port}'),
|
|
||||||
encodeURI('{shell}')
|
|
||||||
];
|
|
||||||
|
|
||||||
parameters.forEach((param) => {
|
|
||||||
if (encoder) param = encoder(param)
|
|
||||||
text = text.replace(param, `<span class="highlighted-parameter">${param}</span>`)
|
|
||||||
})
|
|
||||||
return text
|
|
||||||
},
|
|
||||||
|
|
||||||
init: () => {
|
|
||||||
rsg.initListenerSelection()
|
|
||||||
rsg.initShells()
|
|
||||||
},
|
|
||||||
|
|
||||||
initListenerSelection: () => {
|
|
||||||
rsgData.listenerCommands.forEach((listenerData, i) => {
|
|
||||||
const type = listenerData[0];
|
|
||||||
const command = listenerData[1];
|
|
||||||
|
|
||||||
const option = document.createElement("option");
|
|
||||||
|
|
||||||
option.value = command;
|
|
||||||
option.selected = rsg.listener === option.value;
|
|
||||||
option.classList.add("listener-option");
|
|
||||||
option.innerText = type;
|
|
||||||
|
|
||||||
listenerSelect.appendChild(option);
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
initShells: () => {
|
|
||||||
rsgData.shells.forEach((shell, i) => {
|
|
||||||
const option = document.createElement("option");
|
|
||||||
|
|
||||||
option.selected = rsg.shell === shell;
|
|
||||||
option.classList.add("shell-option");
|
|
||||||
option.innerText = shell;
|
|
||||||
|
|
||||||
shellSelect.appendChild(option);
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
// Updates the rsg state, and forces a re-render
|
|
||||||
setState: (newState = {}) => {
|
|
||||||
Object.keys(newState).forEach((key) => {
|
|
||||||
const value = newState[key];
|
|
||||||
rsg[key] = value;
|
|
||||||
localStorage.setItem(key, value)
|
|
||||||
});
|
|
||||||
Object.assign(rsg, newState);
|
|
||||||
|
|
||||||
rsg.update();
|
|
||||||
},
|
|
||||||
|
|
||||||
insertParameters: (command, encoder) => {
|
|
||||||
return command
|
|
||||||
.replaceAll(encoder('{ip}'), encoder(rsg.getIP()))
|
|
||||||
.replaceAll(encoder('{port}'), encoder(String(rsg.getPort())))
|
|
||||||
.replaceAll(encoder('{shell}'), encoder(rsg.getShell()))
|
|
||||||
},
|
|
||||||
|
|
||||||
update: () => {
|
|
||||||
rsg.updateListenerCommand()
|
|
||||||
rsg.updateTabList()
|
|
||||||
rsg.updateReverseShellCommand()
|
|
||||||
rsg.updateValues()
|
|
||||||
},
|
|
||||||
|
|
||||||
updateValues: () => {
|
|
||||||
const listenerOptions = listenerSelect.querySelectorAll(".listener-option");
|
|
||||||
listenerOptions.forEach((option) => {
|
|
||||||
option.selected = rsg.listener === option.value;
|
|
||||||
});
|
|
||||||
|
|
||||||
const shellOptions = shellSelect.querySelectorAll(".shell-option");
|
|
||||||
shellOptions.forEach((option) => {
|
|
||||||
option.selected = rsg.shell === option.value;
|
|
||||||
});
|
|
||||||
|
|
||||||
const encodingOptions = encodingSelect.querySelectorAll("option");
|
|
||||||
encodingOptions.forEach((option) => {
|
|
||||||
option.selected = rsg.encoding === option.value;
|
|
||||||
});
|
|
||||||
|
|
||||||
ipInput.value = rsg.ip;
|
|
||||||
portInput.value = rsg.port;
|
|
||||||
},
|
|
||||||
|
|
||||||
updateTabList: () => {
|
|
||||||
const data = rsgData.reverseShellCommands;
|
|
||||||
const filteredItems = filterCommandData(
|
|
||||||
data,
|
|
||||||
{
|
|
||||||
filter: rsg.filter,
|
|
||||||
commandType: rsg.commandType
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const documentFragment = document.createDocumentFragment()
|
|
||||||
filteredItems.forEach((item, index) => {
|
|
||||||
const {
|
|
||||||
name,
|
|
||||||
command
|
|
||||||
} = item;
|
|
||||||
|
|
||||||
const selectionButton = document.createElement("button");
|
|
||||||
|
|
||||||
if (rsg.getSelectedCommandName() === item.name) {
|
|
||||||
selectionButton.classList.add("active");
|
|
||||||
}
|
|
||||||
|
|
||||||
const clickEvent = () => {
|
|
||||||
rsg.selectedValues[rsg.commandType] = name;
|
|
||||||
rsg.update();
|
|
||||||
|
|
||||||
// if (document.querySelector('#auto-copy-switch').checked) {
|
|
||||||
// rsg.copyToClipboard(reverseShellCommand.innerText)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
selectionButton.innerText = name;
|
|
||||||
selectionButton.classList.add("list-group-item", "list-group-item-action");
|
|
||||||
selectionButton.addEventListener("click", clickEvent);
|
|
||||||
|
|
||||||
documentFragment.appendChild(selectionButton);
|
|
||||||
})
|
|
||||||
|
|
||||||
const listSelectionSelector = rsg.uiElements[rsg.commandType].listSelection;
|
|
||||||
document.querySelector(listSelectionSelector).replaceChildren(documentFragment)
|
|
||||||
},
|
|
||||||
|
|
||||||
updateListenerCommand: () => {
|
|
||||||
const privilegeWarning = document.querySelector("#port-privileges-warning");
|
|
||||||
let command = listenerSelect.value;
|
|
||||||
command = rsg.highlightParameters(command)
|
|
||||||
command = command.replace('{port}', rsg.getPort())
|
|
||||||
command = command.replace('{ip}', rsg.getIP())
|
|
||||||
command = command.replace('{payload}', rsg.getPayload())
|
|
||||||
|
|
||||||
if (rsg.getPort() < 1024) {
|
|
||||||
privilegeWarning.style.visibility = "visible";
|
|
||||||
command = `<span class="highlighted-warning">sudo</span> ${command}`
|
|
||||||
} else {
|
|
||||||
privilegeWarning.style.visibility = "hidden";
|
|
||||||
}
|
|
||||||
|
|
||||||
listenerCommand.innerHTML = command;
|
|
||||||
},
|
|
||||||
|
|
||||||
updateReverseShellSelection: () => {
|
|
||||||
document.querySelector(".list-group-item.active") ?.classList.remove("active");
|
|
||||||
const elements = Array.from(document.querySelectorAll(".list-group-item"));
|
|
||||||
const selectedElement = elements.find((item) => item.innerText === rsg.currentCommandName);
|
|
||||||
selectedElement?.classList.add("active");
|
|
||||||
},
|
|
||||||
|
|
||||||
updateReverseShellCommand: () => {
|
|
||||||
const command = rsg.generateReverseShellCommand();
|
|
||||||
const commandSelector = rsg.uiElements[rsg.commandType].command;
|
|
||||||
document.querySelector(commandSelector).innerHTML = command;
|
|
||||||
},
|
|
||||||
|
|
||||||
updateSwitchStates: () => {
|
|
||||||
$('#listener-advanced').collapse($('#listener-advanced-switch').prop('checked') ? 'show' :
|
|
||||||
'hide')
|
|
||||||
$('#revshell-advanced').collapse($('#revshell-advanced-switch').prop('checked') ? 'show' :
|
|
||||||
'hide')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
return 'windows/x64/meterpreter/reverse_tcp'
|
||||||
* Init
|
|
||||||
*/
|
},
|
||||||
rsg.init();
|
|
||||||
|
generateReverseShellCommand: () => {
|
||||||
|
let command
|
||||||
|
|
||||||
|
if (rsg.getSelectedCommandName() === 'PowerShell #3 (Base64)') {
|
||||||
|
const encoder = (text) => text;
|
||||||
|
const payload = rsg.insertParameters(rsgData.specialCommands['PowerShell payload'], encoder)
|
||||||
|
command = "powershell -e " + btoa(toBinary(payload))
|
||||||
|
function toBinary(string) {
|
||||||
|
const codeUnits = new Uint16Array(string.length);
|
||||||
|
for (let i = 0; i < codeUnits.length; i++) {
|
||||||
|
codeUnits[i] = string.charCodeAt(i);
|
||||||
|
}
|
||||||
|
const charCodes = new Uint8Array(codeUnits.buffer);
|
||||||
|
let result = '';
|
||||||
|
for (let i = 0; i < charCodes.byteLength; i++) {
|
||||||
|
result += String.fromCharCode(charCodes[i]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
command = rsg.getReverseShellCommand()
|
||||||
|
}
|
||||||
|
|
||||||
|
const encoding = rsg.getEncoding();
|
||||||
|
if (encoding === 'Base64') {
|
||||||
|
command = rsg.insertParameters(command, (text) => text)
|
||||||
|
command = btoa(command)
|
||||||
|
} else {
|
||||||
|
function encoder(string) {
|
||||||
|
return (encoding === 'encodeURI' || encoding === 'encodeURIComponent') ? window[
|
||||||
|
encoding](string) : string
|
||||||
|
}
|
||||||
|
|
||||||
|
command = rsg.escapeHTML(command);
|
||||||
|
command = rsg.insertParameters(
|
||||||
|
rsg.highlightParameters(
|
||||||
|
encoder(command), encoder),
|
||||||
|
encoder
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return command;
|
||||||
|
},
|
||||||
|
|
||||||
|
highlightParameters: (text, encoder) => {
|
||||||
|
const parameters = ['{ip}', '{port}', '{shell}', encodeURI('{ip}'), encodeURI('{port}'),
|
||||||
|
encodeURI('{shell}')
|
||||||
|
];
|
||||||
|
|
||||||
|
parameters.forEach((param) => {
|
||||||
|
if (encoder) param = encoder(param)
|
||||||
|
text = text.replace(param, `<span class="highlighted-parameter">${param}</span>`)
|
||||||
|
})
|
||||||
|
return text
|
||||||
|
},
|
||||||
|
|
||||||
|
init: () => {
|
||||||
|
rsg.initListenerSelection()
|
||||||
|
rsg.initShells()
|
||||||
|
},
|
||||||
|
|
||||||
|
initListenerSelection: () => {
|
||||||
|
rsgData.listenerCommands.forEach((listenerData, i) => {
|
||||||
|
const type = listenerData[0];
|
||||||
|
const command = listenerData[1];
|
||||||
|
|
||||||
|
const option = document.createElement("option");
|
||||||
|
|
||||||
|
option.value = command;
|
||||||
|
option.selected = rsg.listener === option.value;
|
||||||
|
option.classList.add("listener-option");
|
||||||
|
option.innerText = type;
|
||||||
|
|
||||||
|
listenerSelect.appendChild(option);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
initShells: () => {
|
||||||
|
rsgData.shells.forEach((shell, i) => {
|
||||||
|
const option = document.createElement("option");
|
||||||
|
|
||||||
|
option.selected = rsg.shell === shell;
|
||||||
|
option.classList.add("shell-option");
|
||||||
|
option.innerText = shell;
|
||||||
|
|
||||||
|
shellSelect.appendChild(option);
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
// Updates the rsg state, and forces a re-render
|
||||||
|
setState: (newState = {}) => {
|
||||||
|
Object.keys(newState).forEach((key) => {
|
||||||
|
const value = newState[key];
|
||||||
|
rsg[key] = value;
|
||||||
|
localStorage.setItem(key, value)
|
||||||
|
});
|
||||||
|
Object.assign(rsg, newState);
|
||||||
|
|
||||||
rsg.update();
|
rsg.update();
|
||||||
|
},
|
||||||
|
|
||||||
/*
|
insertParameters: (command, encoder) => {
|
||||||
* Event handlers/functions
|
return command
|
||||||
*/
|
.replaceAll(encoder('{ip}'), encoder(rsg.getIP()))
|
||||||
ipInput.addEventListener("input", (e) => {
|
.replaceAll(encoder('{port}'), encoder(String(rsg.getPort())))
|
||||||
rsg.setState({
|
.replaceAll(encoder('{shell}'), encoder(rsg.getShell()))
|
||||||
ip: e.target.value
|
},
|
||||||
})
|
|
||||||
|
update: () => {
|
||||||
|
rsg.updateListenerCommand()
|
||||||
|
rsg.updateTabList()
|
||||||
|
rsg.updateReverseShellCommand()
|
||||||
|
rsg.updateValues()
|
||||||
|
},
|
||||||
|
|
||||||
|
updateValues: () => {
|
||||||
|
const listenerOptions = listenerSelect.querySelectorAll(".listener-option");
|
||||||
|
listenerOptions.forEach((option) => {
|
||||||
|
option.selected = rsg.listener === option.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
portInput.addEventListener("input", (e) => {
|
const shellOptions = shellSelect.querySelectorAll(".shell-option");
|
||||||
rsg.setState({
|
shellOptions.forEach((option) => {
|
||||||
port: Number(e.target.value)
|
option.selected = rsg.shell === option.value;
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
listenerSelect.addEventListener("change", (e) => {
|
const encodingOptions = encodingSelect.querySelectorAll("option");
|
||||||
rsg.setState({
|
encodingOptions.forEach((option) => {
|
||||||
listener: e.target.value
|
option.selected = rsg.encoding === option.value;
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
shellSelect.addEventListener("change", (e) => {
|
ipInput.value = rsg.ip;
|
||||||
rsg.setState({
|
portInput.value = rsg.port;
|
||||||
shell: e.target.value
|
},
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
encodingSelect.addEventListener("change", (e) => {
|
updateTabList: () => {
|
||||||
rsg.setState({
|
const data = rsgData.reverseShellCommands;
|
||||||
encoding: e.target.value
|
const filteredItems = filterCommandData(
|
||||||
})
|
data,
|
||||||
});
|
{
|
||||||
|
filter: rsg.filter,
|
||||||
|
commandType: rsg.commandType
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
document.querySelector('#inc-port').addEventListener('click', () => {
|
const documentFragment = document.createDocumentFragment()
|
||||||
rsg.setState({
|
filteredItems.forEach((item, index) => {
|
||||||
port: rsg.getPort() + 1
|
const {
|
||||||
})
|
name,
|
||||||
|
command
|
||||||
|
} = item;
|
||||||
|
|
||||||
|
const selectionButton = document.createElement("button");
|
||||||
|
|
||||||
|
if (rsg.getSelectedCommandName() === item.name) {
|
||||||
|
selectionButton.classList.add("active");
|
||||||
|
}
|
||||||
|
|
||||||
|
const clickEvent = () => {
|
||||||
|
rsg.selectedValues[rsg.commandType] = name;
|
||||||
|
rsg.update();
|
||||||
|
|
||||||
|
// if (document.querySelector('#auto-copy-switch').checked) {
|
||||||
|
// rsg.copyToClipboard(reverseShellCommand.innerText)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
selectionButton.innerText = name;
|
||||||
|
selectionButton.classList.add("list-group-item", "list-group-item-action");
|
||||||
|
selectionButton.addEventListener("click", clickEvent);
|
||||||
|
|
||||||
|
documentFragment.appendChild(selectionButton);
|
||||||
})
|
})
|
||||||
|
|
||||||
document.querySelector('#listener-advanced-switch').addEventListener('change', rsg.updateSwitchStates);
|
const listSelectionSelector = rsg.uiElements[rsg.commandType].listSelection;
|
||||||
document.querySelector('#revshell-advanced-switch').addEventListener('change', rsg.updateSwitchStates);
|
document.querySelector(listSelectionSelector).replaceChildren(documentFragment)
|
||||||
|
},
|
||||||
|
|
||||||
setInterval(rsg.updateSwitchStates, 500) // fix switch changes in rapid succession
|
updateListenerCommand: () => {
|
||||||
|
const privilegeWarning = document.querySelector("#port-privileges-warning");
|
||||||
|
let command = listenerSelect.value;
|
||||||
|
command = rsg.highlightParameters(command)
|
||||||
|
command = command.replace('{port}', rsg.getPort())
|
||||||
|
command = command.replace('{ip}', rsg.getIP())
|
||||||
|
command = command.replace('{payload}', rsg.getPayload())
|
||||||
|
|
||||||
document.querySelector('#copy-listener').addEventListener('click', () => {
|
if (rsg.getPort() < 1024) {
|
||||||
rsg.copyToClipboard(listenerCommand.innerText)
|
privilegeWarning.style.visibility = "visible";
|
||||||
|
command = `<span class="highlighted-warning">sudo</span> ${command}`
|
||||||
|
} else {
|
||||||
|
privilegeWarning.style.visibility = "hidden";
|
||||||
|
}
|
||||||
|
|
||||||
|
listenerCommand.innerHTML = command;
|
||||||
|
},
|
||||||
|
|
||||||
|
updateReverseShellSelection: () => {
|
||||||
|
document.querySelector(".list-group-item.active") ?.classList.remove("active");
|
||||||
|
const elements = Array.from(document.querySelectorAll(".list-group-item"));
|
||||||
|
const selectedElement = elements.find((item) => item.innerText === rsg.currentCommandName);
|
||||||
|
selectedElement?.classList.add("active");
|
||||||
|
},
|
||||||
|
|
||||||
|
updateReverseShellCommand: () => {
|
||||||
|
const command = rsg.generateReverseShellCommand();
|
||||||
|
const commandSelector = rsg.uiElements[rsg.commandType].command;
|
||||||
|
document.querySelector(commandSelector).innerHTML = command;
|
||||||
|
},
|
||||||
|
|
||||||
|
updateSwitchStates: () => {
|
||||||
|
$('#listener-advanced').collapse($('#listener-advanced-switch').prop('checked') ? 'show' :
|
||||||
|
'hide')
|
||||||
|
$('#revshell-advanced').collapse($('#revshell-advanced-switch').prop('checked') ? 'show' :
|
||||||
|
'hide')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Init
|
||||||
|
*/
|
||||||
|
rsg.init();
|
||||||
|
rsg.update();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Event handlers/functions
|
||||||
|
*/
|
||||||
|
ipInput.addEventListener("input", (e) => {
|
||||||
|
rsg.setState({
|
||||||
|
ip: e.target.value
|
||||||
})
|
})
|
||||||
|
});
|
||||||
|
|
||||||
document.querySelector('#copy-reverse-shell-command').addEventListener('click', () => {
|
portInput.addEventListener("input", (e) => {
|
||||||
rsg.copyToClipboard(reverseShellCommand.innerText)
|
rsg.setState({
|
||||||
})
|
port: Number(e.target.value)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
document.querySelector('#copy-bind-shell-command').addEventListener('click', () => {
|
listenerSelect.addEventListener("change", (e) => {
|
||||||
rsg.copyToClipboard(bindShellCommand.innerText)
|
rsg.setState({
|
||||||
})
|
listener: e.target.value
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
document.querySelector('#copy-msfvenom-command').addEventListener('click', () => {
|
shellSelect.addEventListener("change", (e) => {
|
||||||
rsg.copyToClipboard(msfVenomCommand.innerText)
|
rsg.setState({
|
||||||
})
|
shell: e.target.value
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
// autoCopySwitch.addEventListener("change", () => {
|
encodingSelect.addEventListener("change", (e) => {
|
||||||
// setLocalStorage(autoCopySwitch, "auto-copy", "checked");
|
rsg.setState({
|
||||||
// });
|
encoding: e.target.value
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
// Popper tooltips
|
document.querySelector('#inc-port').addEventListener('click', () => {
|
||||||
$(function () {
|
rsg.setState({
|
||||||
$('[data-toggle="tooltip"]').tooltip()
|
port: rsg.getPort() + 1
|
||||||
});
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// TODO: add a random fifo for netcat mkfifo
|
document.querySelector('#listener-advanced-switch').addEventListener('change', rsg.updateSwitchStates);
|
||||||
//let randomId = Math.random().toString(36).substring(2, 4);
|
document.querySelector('#revshell-advanced-switch').addEventListener('change', rsg.updateSwitchStates);
|
||||||
|
|
||||||
|
setInterval(rsg.updateSwitchStates, 500) // fix switch changes in rapid succession
|
||||||
|
|
||||||
|
document.querySelector('#copy-listener').addEventListener('click', () => {
|
||||||
|
rsg.copyToClipboard(listenerCommand.innerText)
|
||||||
|
})
|
||||||
|
|
||||||
|
document.querySelector('#copy-reverse-shell-command').addEventListener('click', () => {
|
||||||
|
rsg.copyToClipboard(reverseShellCommand.innerText)
|
||||||
|
})
|
||||||
|
|
||||||
|
document.querySelector('#copy-bind-shell-command').addEventListener('click', () => {
|
||||||
|
rsg.copyToClipboard(bindShellCommand.innerText)
|
||||||
|
})
|
||||||
|
|
||||||
|
document.querySelector('#copy-msfvenom-command').addEventListener('click', () => {
|
||||||
|
rsg.copyToClipboard(msfVenomCommand.innerText)
|
||||||
|
})
|
||||||
|
|
||||||
|
// autoCopySwitch.addEventListener("change", () => {
|
||||||
|
// setLocalStorage(autoCopySwitch, "auto-copy", "checked");
|
||||||
|
// });
|
||||||
|
|
||||||
|
// Popper tooltips
|
||||||
|
$(function () {
|
||||||
|
$('[data-toggle="tooltip"]').tooltip()
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: add a random fifo for netcat mkfifo
|
||||||
|
//let randomId = Math.random().toString(36).substring(2, 4);
|
||||||
|
Loading…
Reference in New Issue
Block a user